Messenger is an American messaging app and platform developed by Facebook, it enables users to send messages and exchange photos, videos, stickers, audio, and files.
In this project we will build a Messenger Chatbot using Twilio Autopilot.
Twilio is a cloud communications platform as a service (CPaaS) company which allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs.
Before starting this project, make sure you have a Facebook Page for your brand or business, and the Messenger App installed in your phone. If so, the following steps will walk you through the process of creating and configuring your Facebook Messenger channel on Twilio, and then to link it with your FB page :
Make sure you have created an Autopilot assistant to power the Facebook Messenger Bot.
1. Create a Twilio account
2. Create a new project
3. On project console, open Autopilot, then create a new bot from scratch if you don't have one.
4. In the dashboard of your bot, select Tasks on the left menu.
A bot usually has many tasks that power it. These could be simple tasks like confirm or cancel or more complex tasks like make-a-reservation
5. Click on Add a task and give it a (meaningful) name. Create as many tasks as your bot have to handle.
Every task has two main features Program and Train
- Program : Helps you program the actions your bot will perform in a given task. You need to replace the JSON text with your proper needs. for instance if you want to answer by a static text, change the text after "say" : by whatever you want your bot to say when this task is called :
{
"actions": [
{
"say": "Hello, how can I help you?"
}
]
}
If you want to execute a distant code or call an API :
{
"actions": [
{
"redirect": "PUT THE URL HERE"
}
]
}
- Train : Click on this button to add the expressions that will trigger this task. Add as many samples as possible so that your bot can map human input to the task.
1. Go to Twilio's Facebook channel and click install to install the Facebook Messenger channel on your Twilio account.
2. In the Configure section, select Properties > Use in > Programmable SMS Inbound
3. Go to Credentials and click the Facebook Log in button and follow the instructions to link your Facebook page with your Twilio Account.
4. If all goes well, after selecting your Facebook page you'll see most of the Configuration fields auto-populate below. We only have one main field left : Callback URL
-
Go back to your assistant ( Autopilot Console > your assistant )
-
Select Channels > Facebook Messenger. In the Configuration section, you will see the URL we are looking for, copy it
-
Go back to the FB Messenger Configuration page and paste that URL on the Callback URL field
5. Save your configuration, and go to Messenger app on your mobile, search for the name of your Facebook page, and start the conversation.