Skip to content

Interview chatbot with the possibility to connect to different messengers like WhatsApp, Telegram(t.me/dgonor_bot), and Facebook or PWA.

License

Notifications You must be signed in to change notification settings

honoyr/ChatBotFunctions

Repository files navigation

1. Overview

This is the source code for the Interview ChatBot.

The ChatBot has the following features:

  • it can answer common interview screening questions about my experience as a software engineer, programming skills, and work authorization status
  • it can create a calendar event and set up a meeting with an interviewer
  • it can send my resume to the interviewer

ChatBotGif

Requirements

Architecture

image-min

  • Google Cloud Patform - cloud infrastructure for development.
  • Firebase - works on top of GCP. Used for hosting, data storing. Firebase provides developer tools such as cloud functions, analytics, monitoring, and testing.
  • Nebular Angular UI Library - Library for web application.
  • DialogFlow Account - for managing every aspect of natural language processing.
  • PostoHub - for sending emails. PostoHub is a Transactional Email API Service for developers.
  • OpenAI - GPT-3 API for managing answers to unknown questions. Temporarily disabled because of OpenAi Policy.
  • Google Calendar API - integration with Google Calendar.

Overview

Dialogflow Gateway Cloud Function is used to communicate with Dialogflow. The function is triggered when a watched event is being fired.

When Dialogflow Gateway gets all necessary information from the user, Dialogflow sends a webhook to the second Cloud Function. The Webhook Cloud Function holds a map of all the possible intents and calls the server to fulfill them.

Compute Egine is triggered on a specific intent to execute scripts such as sending emails or creating a calendar event.

2 Getting Started

Clone the GitHub repository from the command line:

git clone https://github.com/honoyr/ChatBotFunctions

Alternatively, if you do not have git installed, you can download the repository as a ZIP file.

3. Create and set up a Firebase project

Create a Firebase project

  1. Sign in to Firebase.
  2. In the Firebase console, click Add Project, and then name your Firebase project ChatBot. Remember the project ID for your Firebase project.
  3. Click Create Project.

Important: Your Firebase project will be named as ChatBot, but Firebase will automatically assign it a unique Project ID in the form ChatBot-1234. This unique identifier is how your project is actually identified (including in the CLI), whereas ChatBot is simply a display name.

The application that we're going to build uses Firebase products that are available for web apps:

  • Firebase Hosting to host and serve your assets.
  • Firebase Cloud Functions serverless framework that automatically runs backend code in response to events triggered by Firebase features and HTTPS requests.

Some of these products need special configuration or need to be enabled using the Firebase console.

Add a Firebase web app to the project

  1. Click the web icon 58d6543a156e56f9.png to create a new Firebase web app.
  2. Register the app with the nickname ChatBot, then check the box next to Also set up Firebase Hosting for this app. Click Register app.
  3. Click through the remaining steps. You don't need to follow the instructions now; these will be covered in later steps of this doc.

ea9ab0db531a104c

4 Set up Google Cloud Platform API credentials

DialogFlow API

Google Calendar API

5. Install the Firebase command-line interface

The Firebase command-line interface (CLI) allows you to use Firebase Hosting to serve your web app locally, as well as to deploy your web app to your Firebase project.

Note: To install the CLI, you need to install npm which typically comes with Node.js.

  1. Install the CLI by running the following npm command:
npm -g install firebase-tools

if it doesn't work, you may need to change npm permissions.

  1. Verify that the CLI has been installed correctly by running the following command:
firebase --version

Make sure that the version of the Firebase CLI is v9 or later.

  1. Authorize the Firebase CLI by running the following command:
firebase login

We've set up the web app template to pull your app's configuration for Firebase Hosting from your app's local directory (the repository that you cloned earlier). But to pull the configuration, we need to associate your app with your Firebase project.

  1. Make sure that your command line is accessing your app's local root project directory.
  2. Associate your app with your Firebase project by running the following command:
firebase use --add
  1. When prompted, select your Project ID, then give your Firebase project an alias. .firebaserc file

An alias is useful if you have multiple environments (production, staging, etc).

  1. Follow the remaining instructions on your command line.
  2. .firebaserc file will be set up with your Project ID
{  
  "projects": {  
    "default": "<Project ID>"  
  }  
}

6. Installing dependency

Functions

  • Go to functions directory cd functions
  • Install dependency npm install

7. Setting up credentials

Google Service Account

  • Add to your config folder credentials
  • Go to cd functions/src/config
  • Create serviceAccount.js
  • Open Firebase console
  • Open Service accounts tab and press Generate key button
  • Save your json to serviceAccount.js as
export default {
  "type": "service_account",  
  "project_id": "<Project_ID>",  
  "private_key_id": "4291b7e4eea9*****2c15a3cfe9645",  
  "private_key": "-----BEGIN PRIVATE KEY-----\nMr***********0=\n-----END PRIVATE KEY-----\n",  
  "client_email": "firebase-***********@<PROJECT_ID>.iam.gserviceaccount.com",  
  "client_id": "1***********51",  
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",  
  "token_uri": "https://oauth2.googleapis.com/token",  
  "auth_provider_x**9_cert_url": "https://www.googleapis.com/oauth2/v1/certs",  
  "client_x**9_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/*******.iam.gserviceaccount.com", 
};

Google calendar ID

  • Copy your Calendar ID from your calendar
  • Add new line to your serviceAccount.js file such as "calendarId": "*******@group.calendar.google.com",

Email API

  • Register on PostoHub (Email Service Provider)
  • Go to integration section and create your API key.
  • Add generated API key to your serviceAccount.js
"postohubEmailApiKey": "*******-9a5dd7***"

At the end serviceAccount.js looks like

export default {
  "type": "service_account",  
  "project_id": "<Project_ID>",  
  "private_key_id": "4291b7e4eea9*****2c1**45",  
  "private_key": "-----BEGIN PRIVATE KEY-----\nMr***********0=\n-----END PRIVATE KEY-----\n",  
  "client_email": "firebase-***********@<PROJECT_ID>.iam.gserviceaccount.com",  
  "client_id": "1***********51",  
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",  
  "token_uri": "https://oauth2.googleapis.com/token",  
  "auth_provider_x**9_cert_url": "https://www.googleapis.com/oauth2/v1/certs",  
  "client_x**9_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/*******.iam.gserviceaccount.com",  
  "calendarId": "*******@group.calendar.google.com",  
  "postohubEmailApiKey": "*******-9a5dd7***",  
};

Deployment

Functions

  • Open the directory with your functions cd functions

Local environment

  • Run your functions locally npm run-script serve. It allows to test the functions out first via any HTTP Requests simulator.

Production environment

  • Run deployment script to host functions in production npm run-script deploy

Web Application

  • Open cd chatBotUi directory
  • Run npm install to install dependencies

Local environment

  • Open cd chatBotUi directory
  • Change URL in .env file to local cloud function endpoint LOCAL_DIALOGFLOW_GATEWAY=http://localhost:5001/<Project_ID>/us-central1/dialogflowGateway before running locally
  • Build project with the command ng build. The compiled app is stored in the root directory cd ../public/
  • Run your functions locally cd ../functions && npm run-script serve
  • Open http://localhost:5000

Production environment

  • Open cd chatBotUi directory
  • Build project with the command ng build. The compiled app is stored in the root directory cd ../public/
  • Change URL in .env file to cloud function endpoint PROD_DIALOGFLOW_GATEWAY=https://us-central1-<Project_ID>.cloudfunctions.net/dialogflowGateway before running in production
  • Run your functions on the host cd ../functions && npm run-script deploy
  • Open your firebase hosting https://<Project_ID>.web.app/

About

Interview chatbot with the possibility to connect to different messengers like WhatsApp, Telegram(t.me/dgonor_bot), and Facebook or PWA.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published