Deconstructing Chatbot: Integrate Dialogflow with Twilio Messaging Service

Introduction

In this article we will learn how Dialogflow integrates with Twilio messaging service for SMS which allows to easily create Twilio bots with natural language understanding. Programmable SMS service from Twilio makes sending and receiving SMS easily. If you are following the Deconstructing chatbots series, we will use the same Agent that we created in previous labs “Appointment Scheduler”. Although you can use any Dialoglfow agent and work through this article to create the integration. We will finally test to see if the integration by sending the requests over chat.

Dialogflow integration with Twilio Messaging Service

What you’ll learn

  • How to enable Twilio integration from Dialogflow
  • How to test the Dialogflow bot with Twilio integration

Prerequisites

Enable Twilio integration from Dialogflow

We will use the same appointment scheduler chatbot that we build in the previous codelab and work through the integration.

  • Navigate to the Dialogflow Console.
  • Select the AppointmentScheduler agent that we created previously.
  • Click on Integrations and then click on “Twilio (Text messaging)” integration settings.
Dialogflow Integrations
  • The pop up has instructions: Click on start, Copy the request URL and put it in Twilio Programmable SMS.
  • The first thing you will need is a Twilio account, if you don’t have one create it and log in.
  • From the dashboard, click on all products and navigate to Programmable SMS.
Programmable SMS in Twilio console
  • Once you are on the programmable SMS dashboard, click on SMS
  • If you already have an appointment scheduler messaging service set up, use that, if not, you can just create one. Provide a name, in the use case, select Chatbot/interactive 2 way.
  • Click on the created messaging service to assign a phone number.
  • Use the add button to buy a new number or use an existing number.
  • Click through the US selections and you should have a number assigned.
Phone number assignment in Twilio console
  • At this point, we click on configure to integrate Dialogflow.
  • Enable Inbound settings
  • In the Request URL copy and paste the URL generated by Dialogflow in the integration section and save.
  • Copy Service ID, Phone number and AuthToken from the Twilio dashboard and paste them in the Dialogflow integration console. Once you are done click on start.
Copy these items from the Twilio Console

You will notice that the bot has started successfully.

Test the Agent

In order to test the agent and Twilio integration use text messaging on a phone. Send text message to the number that was assigned to the Twilio messaging service and run through the example appropriate for your agent.

For the appointment scheduler agent, this is the test you can try:

Congratulations!

You enabled a Dialoglfow agent for text messages by using Twilio Messaging service!

Next steps

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store