logo

Guest Post: How to Integrate Twilio with Botpress on a Window environment

We welcome this guest blog from our community member, Danilo Limo! He recently posted in the Botpress Community Forum with a step-by-step tutorial on how to integrate Botpress with Twilio, using Whatsapp.

9 Nov, 2021

Updated 20 Nov, 2021

Share

How to Integrate Twilio with Botpress, Step-by-Step

Many thanks to a Botpress community contributor, Danilo Limo! We're happy to share here his recent how-to, posted in the Botpress community forum. He created a step-by-step tutorial on how to integrate Botpress with Twilio, using Whatsapp and working on his Windows machine. We really appreciate our community, and would love to share any tips, tutorials, or other content devs create with Botpress!

Integration Tutorial
Step-by-step

This tutorial aims to demonstrate how the botpress framework is integrated with Whatsapp through the Twilio platform.

Note: For ease I will describe the step-by-step for Windows since it is the environment I am currently using.

Prerequisites:

To use Twilio as integration of your botpress with Whatsapp it is necessary that your bot has external access via SSL /TLS [ https ]

If your bot is being built in a local environment(localhost) you will need to use a tunnel application such as NGROK so that you can access your localhost externally.

Follow the steps below:

  1. Download NGROK in ngrok - download
  2. Unzip the file and rotate the executable
  3. In the /ngrok/bin folder run the ngrok file.exe
  4. The command prompt [cmd] will open
  5. In it run the following command: ngrok http 3000, where ngrok is the executable command of the application, http indicates that it will be accessed via web and 3000 is the default port of Botpress

If you are developing your bot in cloud environment, such as Heroku for example, just use the external url of your bot which should look something like this: https://<yourbotname>.herokuapp.com/

Twilio

Now let’s go to Twilio!!

  1. Create an account on Twilio (I will not describe here how to create an account in Twilio because it is very simple and intuitive to create an account).
  2. When you create the account, in your account dashboard, copy and reserve the keys: accountSID and authToken.

Register your phone number in your account, as Twilio will need it.

Once that’s done, now it’s time to set up your Twilio access credentials in Botpress.

Botpress
In Botpress you perform the following steps:

  1. Open the \data\bots<your_bot>\bot.config.json file
  2. Include, before the last “}”, the json code block as below:
"messaging": {
	 "channels": {
	 "twilio": {
		 "enabled": false, "change here to true"
		 "accountSID": "Enter your key accountSID here",
		 "authToken": "Enter your key authToken here"
	 }
	 }
 }

It should look like this:

3. Go to \data\global\ folder and open the file botpress.config.json

4. With the file open, change the parameter externalUrl as follows:

 "externalUrl": "https://6a3d-a700.ngrok.io",
 "session": {
 "enabled": true, “If false change to true”
 "maxAge": "1h"
 },

It should look like this:

  • 5. Now, in the \data\global\config folder, open the channel-twilio.json file and configure it as follows:
 {
 "$schema": "bp://types/modules/channel-twilio/config.schema.json",
 "enabled": true,
 "accountSID": " Enter your key accountSID here",
 "authToken": " Enter your key authToken here"
 }

It should look like this:

6. Now copy the channel-twilio.json file from the \data\global\config folder and paste it into the \data\bots\ folder <your_bot>\config

7. Once that's done, it’s time to restart your Botpress. Once you restart, you should see the initiation log the URL of the Twilio webhook in Botpress. You must present as:

8. Now copy the Twilio webhook url, go to your Twilio account, and paste it into the webhook section, as shown in the image below:

  • 9. Now, while still in your Twilio account, go to menu Messaging → Try it out → Send a Whatsapp message
  • 10. You will need to activate Twilio Whatsapp, so open Whatsapp as follows:
  • 11. This “join lot-idea” code activates Twilio to interact with your Botpress.
  • 12. If you want to disable the Twilio service just send a message with the text “stop”.
  • 13. And that’s it! Your Botpress is prepared to send and receive messages by WhatsApp. See the interaction of messages, as well as the log:

And that's it!

Many thanks to Danilo! You can see his fine original post in the Botpress forum. If you're interested in more Botpress how-to's, check out the Botpress YouTube channel, where we've been adding lots of new developer content over the past few months.

In fact, there is a just-published how-to video on the Botpress Twilio Channel Integration, with up-to-date review of how to use Twilio with Botpress. Check it out!

Related Articles

7 Dec, 2021

The People of Botpress: Jean-Bernard Perron, Chief Financial Officer

The People of Botpress is a series where we highlight our people and the great work they do by talking about life at Botpress. In this first edition of The People of Botpress, we are interviewing our Chief Financial Officer, Jean-Bernard Perron

7 Dec, 2021

What’s Happening at Botpress: November 2021 Recap

Find out all about our November 2021 events, product updates, tips, tools, tricks and tutorials — All in one place.

23 Nov, 2021

The People of Botpress: François-Xavier Darveau, Head of Engineering

The People of Botpress is a series where we highlight our people and the great work they do by talking about life at Botpress. In this first edition of The People of Botpress, we are interviewing our Head of Engineering, François-Xavier Darveau!

Newsletter

Get The Latest Updates.
Subscribe Now