Dialogflow has discontinued the one-click integration of Twilio for SMS and instead made the twilio integration available as open source.
Here, we take you through process of setting up Twilio integration on your own server to connect Twilio phone number with Dialogflow agent.
1. You can download the integration code from the official github repo of Dialogflow https://github.com/GoogleCloudPlatform/dialogflow-integrations . But in that there is code for multiple platforms.
To simplify it, we have created our own zip file which contains code for twilio only and also we have setup the code to run the server easily.
You can download the zip file by clicking here.
Extract the zip file in the folder and change the working directory to the extracted folder.
2. Now, browse to the directory where you extracted the folder and run
npm install
This will install all the required libraries for the project.
3. Now, download the json file for the service account.
To do that, go to https://dialogflow.cloud.google.com/#/agent/.
Select your agent.
4. Click on the settings button.
5. Now copy the Project id and paste it in the index.js file as value of projectId. Then open service account page in new tab by clicking on the service account.
6. Now on the service account page
Check the project
Check the service account is same as previous page
Click on the 3 dots
On clicking on the “create key” you will get the json file.
Save the json file in the working directory where you have extracted the zip file.
NOTE: the json file and index.js must be in the same directory at the same level.
Now export the path of the json file. By typing in the terminal export GOOGLE_APPLICATION_CREDENTIALS=”/full/path/to/your/json/file”
NOTE : Don’t close the terminal we will start our nodejs server here.
7. Now, next step is login to https://www.twilio.com/console.
Copy SID and paste in index.js as value of accountSID.
Copy Authtoken and paste in index.js as value of authToken.
8. Now click on the three dots
9. Click on “programmable sms”.
10. Click on “SMS”.
Click on “+” sign.
11. Give service name and then select mixed from the dropdown.
12. Check the radio button “send an incoming message webhook”.
Keep the window open we will back here to paste the ngrok url in Request URL.
Open index.js file and paste all the required fields.
Now run the node server with node index.js in the terminal where you have exported the path earlier.
Open ngrok in new terminal and type sudo ngrok http 8989
You will get the ngrok URL for your server. Paste it in the Twilio as SEND AN INCOMING MESSAGE WEBHOOK.
Now, the connection of Twilio of Dialogflow is done using the integration we setup. You can test it by sending the SMS.`
Send message from the your mobile to the number purchased from twilio. You will get the reply from Dialogflow agent.
STEPS TO DEPLOY THE APP ON HEROKU
git init
5. Now install Heroku CLI with
sudo snap install --classic heroku
6. Now run the below command and login with heroku via CLI.
heroku login
5. Now run following three commands one after one.
git add .
git commit -am "Initial commit"
git push heroku master
6. Set environment variable in heroku
heroku config:set GOOGLE_APPLICATION_CREDENTIALS='YOUR_JSON_FILE_PATH'
Feel free to comment your doubts/questions. We would be glad to help you.
If you are looking for Chatbot Development or Natural Language Processing services then do contact us or send your requirement at letstalk@pragnakalp.com. We would be happy to offer our expert services.