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
- The IDE/text editor of your choice, such as WebStorm, Atom, Sublime, or VS Code
- The package manager npm, which typically comes with Node.js
- A terminal/console
- A browser of your choice, such as Chrome
- Google Cloud Patform
- DialogFlow Account
- Firebase console
- 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.
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.
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.
- Sign in to Firebase.
- In the Firebase console, click Add Project, and then name your Firebase project ChatBot. Remember the project ID for your Firebase project.
- 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.
- Click the web icon to create a new Firebase web app.
- Register the app with the nickname ChatBot, then check the box next to Also set up Firebase Hosting for this app. Click Register app.
- Click through the remaining steps. You don't need to follow the instructions now; these will be covered in later steps of this doc.
- Open your Google Cloud Patform
- Go to API Library
- Enabel DialogFlow API
- Set up your dialogflow service account permission to Owner role to get access to Dialogflow fulfillment from 3rd party services.
- Make sure your firebase service account has Owner role as well.
- Open your Google Cloud Patform
- Go to API Library
- Enabel # Google Calendar API
- Create
Service Account
and copy generated email address. Example:interview-scheduler-calendar@<Project ID>.iam.gserviceaccount.com
- Open your own google calendar or create a new one.
- Go to the settings
- Add provided email address to section Share with specific people
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.
- 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.
- 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.
- 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.
- Make sure that your command line is accessing your app's local
root
project directory. - Associate your app with your Firebase project by running the following command:
firebase use --add
- 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).
- Follow the remaining instructions on your command line.
.firebaserc
file will be set up with your Project ID
{
"projects": {
"default": "<Project ID>"
}
}
- Go to functions directory
cd functions
- Install dependency
npm install
- 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",
};
- Copy your Calendar ID from your calendar
- Add new line to your
serviceAccount.js
file such as"calendarId": "*******@group.calendar.google.com",
- 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***",
};
- Open the directory with your functions
cd functions
- Run your functions locally
npm run-script serve
. It allows to test the functions out first via any HTTP Requests simulator.
- Run deployment script to host functions in production
npm run-script deploy
- Open
cd chatBotUi
directory - Run
npm install
to install dependencies
- Open
cd chatBotUi
directory - Change URL in
.env
file to local cloud function endpointLOCAL_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 directorycd ../public/
- Run your functions locally
cd ../functions && npm run-script serve
- Open http://localhost:5000
- Open
cd chatBotUi
directory - Build project with the command
ng build
. The compiled app is stored in the root directorycd ../public/
- Change URL in
.env
file to cloud function endpointPROD_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/