-
Notifications
You must be signed in to change notification settings - Fork 5
Building Bots for WhatsAPP
Amitha R edited this page Oct 13, 2018
·
5 revisions
- Sign in Dialogflow
- Create an Agent - BotHRWorthyBot
- Whatsapp for Business is an application that offers an API service.
- It runs as a docker container for on-premise deployment. Or, it can be setup on AWS using a pre-built CloudFormation template.
- Use MySQL for storing data.
- Whatsapp requires to register a phone number and that will serve requests using twilio
- Create a new project and Continue.
- Programmable sms section -> Whatsapp - activate the sandbox.
- Store the listed number and send the requested message - join the sandbox.
-
WhatsApp Business API + twilio ------------------ Dialogflow
-
DialogFlow - Integrations - Twilio(Text Messaging) - Require Authentication Code.
-
Twilio - Programmable SMS Dashboard section -> right-top corner - show API Credentials.
-
Copy the credentials and paste it into the DialogflowTwilio integration form.
-
Start the form, this internally springs a nodejs app with the integration process built-in.
-
In the Dialog-floe Twilio-form copy the request url and paste it in twilio - programmable-sms -whatsapp - sandbox section section - "WHEN A MESSAGE COMES IN" - Save.
- In Dialogflow - BotHRWorthy - Intent
- Default Welcome Intent
- Default Fallback Intent
- Google Sheets - Database.
- Service Account Setup:
- Dialogflow -> Setting -> Service Account (Dialog flow uses this to interact with Google Cloud Platform);
- Click and open the link in a new tab - Google Cloud Platform.
- IAM & admin section -> Service Account ---> Create Service Account
- Enter the service Account -> select role - owner -> download the JSON file -> Done.
- Search for Google Drive API - Enable it.
- Google Drive - signin.
- New - Google sheets - blank spreadsheets - create two tabs - Jobs, Applications.
- Google Cloud Platform - left top corner - IAM & admin -> Service account - Email.
- Google Sheet -> Share button - paste the email id --> edit -> send.
- AWS Lambda - Function as a Service - deploy functions without worrying about scaling or the underlying server setup.
- Serveless movement - decouple large application into small manageable components.
- Download AWS CLI - windows download installer.
- Enable secure access to aws account.
- The CLI use special access key id and a secret key id to talk to the AWS account. The serverless framework also uses the function to deploy on AWS lambda.
- Services - IAM (Identity Access & Management)- Users Create a new users, attach the policies - AdministrativeAccess.
- Store the Access Key and Password.
- In windows explored - folder - cmd - aws configure - paste the Access Key, Password, etc.
- In cmd - npm i -g serverless
- sls --version
- AWS System Manager's Parameter Store - Secrets are stored encrypted at rest.
- SSM Dashboard - AWS -> Services -> System Manager --> Parameter Store.
- Creation of Parameters:
- In cmd -> aws ssm put-parameter --name "<>" --value "<>" --type SecureString
- Read -> aws ssm get-parameter --name "<>"
- In cmd -> aws ssm put-parameter --name "<>" --value "<>" --type SecureString
- In the folder - cmd - sls create --template aws-nodejs --path bothrworthywebhook.
- This creates a ready-made boiler plate that deploys has a AWS lambda.
- This command create a folder and certain files in it.
- handler.js
- serverless.yml - config file
- Lambda functions are built only for a certain period of time hence are advantageous.
- make changes in serverless.yml file.
- npm init, intall serverless-offline.
- Type sls offline - inorder to bring the "webhook" locally - port 3000.
- check the API in postman - POST - http://localhost:3000/bothrworthywebhook - body (someKey, someData) - send.
- AWS Lambda function must be able to interact with SSM Store.
- IAM policy - permit permissions, read parameters, etc.
- Get parameters from AWS, region is also required.
- Make changes to serverless.yml - ass roles, regioncodes.
- Require the Accounts Private Key and Client e-mail.
- Use service account to gain access to the sheets API.
- Gain Access to the BotHRWorthy Sheets document.
- Get to individual worksheets.
- Read/Write/Search.
- Create -Sheets/index.js -> store the parameters and write functions to extract it.
- In dialogflow - create an Intent - "Get-Openings".
- Code to handle the get-opening api from dialog-flow.
- Run ngrok - webhook
- The webhook from ngrok in integrated into dialogflow -> fullfillment --> http:...../bothrworthywebhook.
- Save changes and test setup.
- Intent (Apply) ---| What is the job code that you wish to apply for? Are you above 18? Do you have cs degree? /work ex? relocate to san francisco? | ---- AWS Lambda function.
- Create an intent "Apply" - Dialogflow and an entity termed "Yaynay".
- The serverless framework -- creates a JSON Document - "CloudFormation Template" (Code & Assets) - resources required to deploy it on the AWS platform.
- It then packages the code and deploys into an Amazon S3 bucket.
- S3 - Simple Storage Service - stores files of all kind.
- Thereafter it is deployed on AWS Lambda.
Serverless Framework ----> CloudFormation Template -(code&Assets)--------> Amazon S3 -------> AWS Lambda
- cmd -> sls deploy.
- Obtain - Endpoint URL to Lambda function.
- Copy the url -> into Dialogflows fulfillment webhook -> Save.
- Test the changes with Whatsapp.