DEV Community

Cover image for RASA - Messaging channels - Twilio
Petr Janik
Petr Janik

Posted on

RASA - Messaging channels - Twilio

Messaging channels are interfaces such as Facebook Messenger, live chat window on a website, smart speaker etc.

Rasa uses pre-built connectors for a variety of messaging channels. You can also create your own custom connector.

In this article, we will connect our chatbot to the Twilio. We will be then able to communicate with the chatbot via SMS (text messages).

Our assistant is running locally on our PC. To make it available to external services, we will use ngrok. This tool simulates hosting our assistant on a server by creating a tunnel URL.
Download ngrok and make it available on PATH.

Create a Twilio account, if you don't have one already.
Then, create a new project.
After you have created the project, go to Console Dashboard.
Click Get a trial phone number and choose a phone number.

On the Console Dashboard – from the Project Info section – copy Account SID, Auth token and Phone number and add it to credentials.yml in the following format:

twilio:
  account_sid: "<your account sid>"
  auth_token: "<your auth token>"
  twilio_number: "<your twilio number>"
Enter fullscreen mode Exit fullscreen mode

Run the rasa server: rasa run.
In a new terminal window, run the actions server: rasa run actions.
In a new terminal window, run ngrok: ngrok http 5005.
Ngrok is listening on port 5005 since this is where the rasa server is running.

Copy the https version of the tunnel URL that was generated by ngrok and go to Twilio Phone Numbers page. Click on your assigned phone number in Active Numbers.
In Messaging section, put inside the A message comes in webhook input box the https URL from ngrok followed by /webhooks/twilio/webhook and save.

Twilio setup webhook

Send a text message to that Twilio phone number and the chatbot will reply!

You can connect as many messaging channels as you want.

To learn more about Twilio channel connector, visit the documentation.

You can learn more about messaging channels in the documentation.

Repository for this tutorial:

You can checkout the state of the repository at the end of this tutorial by running:

git clone --branch 19-messaging-channels git@github.com:petr7555/rasa-dev-tutorial.git
Enter fullscreen mode Exit fullscreen mode

Top comments (0)