Rate this page:

Facebook Messenger

For more about using Facebook Messenger with Twilio, see the documentation on Twilio Channels.

With Twilio Autopilot, you can build Facebook Messenger bots. On this page, we'll walk you through how to link your Facebook account to Autopilot so you can get started building your Facebook Messenger bot.

Before you begin:

  1. You must have a Facebook Page for your brand or business. If you don't have one follow these instructions to create one here.
  2. Download the Messenger App for your phone here: iOS - Android.
  3. Make sure you have created an Autopilot assistant to power the Facebook Messenger Bot.

Get Started

Once you have the Facebook page and the Messenger app installed you'll need to link your Facebook page with Twilio, and then configure the FB Messenger channel on Twilio to point to Autopilot. We'll walk you through step by step.

  1. First, you need to install the FB Messenger channel on your Twilio Account. Go here and click install.
  2. Once installed, you'll see a Configure section.
  3. In the Properties section, select Use in -> Programmable SMS Inbound
  4. In the Credentials section, click the Facebook Log in button to link and follow the instructions. This will link your Facebook page with your Twilio Account.
  5. Select the Facebook page that you want to build your Bot for. You'll see most of the Configuration fields auto-populate below.
  6. At this point, we need to configure the Callback URL with the Autopilot URL for Facebook Messenger. So, open a new tab, and to Autopilot in the Twilio Console.
  7. On the left-hand menu, click Your Bots. Then click on the assistant that is going to power the Facebook Messenger Bot.
  8. Then click Channels. You'll see a Facebook Messenger tile. Click on it and make sure you're on Configuration.
  9. You will see a URL, copy that URL, then go back to the FB Messenger Configuration page and paste that URL on the Callback URL field.
  10. Hit save and you're all set!


Now that you have Facebook Messenger configured it's time to test!

  • Open your Facebook Messenger app on your mobile
  • Search for the name of your Facebook page
  • Send your first message, you should get a response from Autopilot
  • Check the Autopilot Query logs, you should see the message you sent from Facebook Messenger in the query logs.

Autopilot URL Parameters

Parameter Description

A string representing the unique name of the destination Task. If no TargetTask is provided, the destination task is determined by the natural language understanding.

TargetTask is useful when you want to control what task a user is routed to.


Lets you send Inbound Context to Autopilot. Should be a JSON string containing key-value pairs to insert into the Autopilot memory before starting a dialogue with the bot.

Useful for passing data stored in third party systems like a CRM into Autopilot to deliver a more contextual experience.

Example 1: Using TargetTask parameter at the end of the URL<ACCOUNT_SID>/<ASSISTANT_SID>/twilio-messaging/facebook-messenger?TargetTask=handle_appointment_confirmation

Any message sent to number or messaging service configured with this URL will land in the handle_appointment_confirmation task.

Example 2: Passing Inbound Context with Memory<ACCOUNT_SID>/<ASSISTANT_SID>/twilio-messaging/facebook-messenger?Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}

Any message sent to a bot with this URL will insert CarModel, CarMake and CarYear into the Autopilot Memory.

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Loading Code Sample...

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!