SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

Getting Started with the Facebook Messenger Channel (Beta)

Twilio now supports sending and receiving messages to and from Facebook Messenger users! The Facebook Messenger channel helps expand your reach and availability to your important contacts on any platform that is convenient for them. Best of all, Facebook messages are controlled by Twilio's existing Programmable SMS API. Here's what you need to know to get started.

Notice: The Facebook Messenger Channel is currently in beta, and has not yet been finalized. For more information on Support limitations for beta and pre-release products, please see Twilio Beta Product Support.

Facebook Messaging Capabilities

Facebook users will need to initiate contact with you by messaging your Facebook Page before you are able to contact them. Once a user’s message is received, you can respond back to the user for 24 hours. For more details, please see Platform Policy Overview (Facebook for Developers) 

After the 24-hour window has expired, Facebook only lets you alert the user of a non-recurring change to their application or account. Twilio tags any messages sent to the user with the "ACCOUNT_UPDATE" tag after the 24-hour window. For more details, please see Facebook’s Messenger Message Tags documentation.

Setup Process

Here are the steps required to setup the Facebook Messenger Channel:

  1. Create a Facebook Page.
  2. Install and Configure the Facebook Messenger Channel.
  3. Receive a message from a user so you can respond

You do not need to create a Facebook App. Twilio uses its own Facebook App to communicate on behalf of your users.

Step 1: Creating a Facebook Page

In the Facebook Messenger ecosystem, users communicate with brands and companies by messaging their Facebook Page. Similarly, the Facebook Messenger channel requires a Facebook Page for business messaging, rather than just a personal account.

If you do not have a Facebook page yet, you can create one by logging in to your Facebook account, clicking Pages, and then creating a new page.

Please note that if you are an Independent Software Vendors (ISV's) and Software Integrators (SI's) who is managing Facebook Messenger communications on behalf of your clients, you will need to have admin access to the Facebook page. 

Step 2: Install the Facebook Messenger Channel and Choose the Facebook Page as a Sender

To begin sending and receiving Twilio messages with Facebook Messenger, you’ll need to install the Facebook Messenger Channel, and select the Facebook Page you wish to use as a sender. A sender is the identity used in the "From" field to send messages to your users. Here are the instructions to get you set up:

  1. Login to www.twilio.com/console and click Channels from the left-side navigation bar.
    NOTE: If Channels is not visible, click All Products & Services.
  2. Click Facebook Messenger and click "Install".
  3. Review the Facebook terms of service. If you wish to continue, check the “I agree…” box, and then click "Agree & Install".
  4. From the “Configure” tab, click the "Connect with Facebook" button, and then follow the prompts to select the Facebook Pages you want to authorize to use as senders.
  5. Once connected, the page will reload. Make the following changes, and then click Save. 
    1. Properties > USE IN: Make sure "Programmable SMS Inbound" is selected.
    2. Credentials > SELECT A PAGE: Select your Facebook Page.
      NOTE: If your page is missing, you may need to sign out of Facebook, and then sign back in to provide Twilio access.
    3. Configuration > CALLBACK URL: Enter a webhook URL where you can receive incoming messages from your end users.

You are all set to use Facebook Messenger as a sender. Please make note of the "page ID" value. This is your Facebook Messenger sender ID using the Programmable Messaging API.

If you wish to configure more than one Facebook Page as a sender, you can click "Add Another Instance," and repeat steps 3-7 above for each new Facebook Page. For ISVs and SIs, we recommend setting up a new Twilio Subaccount for each brand that you manage.

Step 3: Receive a message from a user so you can respond

Now that your Facebook Messenger sender is set up, you need to receive a message from an end user in order to respond.

The simplest way to do this is to send yourself a message, by navigating to m.me/{Facebook_page_ID}. Incoming messages will hit your callback URL with the same parameters as a standard Twilio WhatsApp or SMS message. Facebook Messenger sender and recipients have the format Messenger:xxxxx. To send a Facebook message, make an HTTP POST request to Twilio’s Programmable Messaging Message REST API resource with three required pieces of information: a recipient, a sender, and your message.

  • Recipient: The To parameter consisting of messenger: followed by the Facebook Messenger User ID from the message you're replying to.
  • Sender: The From parameter consisting of messenger: followed by your Facebook Page ID.
  • Message: The Body parameter consisting of the desired response you wish to send.

Here’s an example cURL script:

curl -X POST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
--data-urlencode "To=messenger:{Messenger_User_ID}" \
--data-urlencode "From=messenger:{Facebook_Page_ID}" \
--data-urlencode "Body=Thank you for your message." \
-u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"

This example will send a response to the Facebook user at messenger:{Messenger_User_ID) from your Facebook Page ID with the following body:

Thank you for your message.

To make this script work for you, make the following updates, and then paste it into a terminal window:

  • Line 1 update with your Account SID
  • Line 2 update with the incoming Facebook Messenger User ID you're replying to
  • Line 3 update your Facebook Page ID
  • Line 4 update with your desired message
  • Line 5 update with your Account SID and Auth Token.

For more details, including code samples from our Helper Libraries, please see Sending Messages (Twilio Docs).

Optional: Configure Additional Facebook Messenger Channel Settings

You may configure the additional fields on the page as described below. Once you are done configuring, click "Save". 

Properties INSTALLED CHANNEL SID (Auto populates when once page selected)
  INBOUND CHANNEL URL (Auto populates when once page selected)
  UNIQUE NAME Edit as desired.
  USE IN Select the product(s) you intend to use.
Credentials FACEBOOK LOGIN Click Log In, and then follow the prompts.
  SELECT A PAGE Select your Facebook Page from Step 1.
Configuration PAGE ID (Auto populates when once page selected)
  PAGE FRIENDLY NAME (Auto populates when once page selected)
  CALLBACK URL Enter your Twilio App URL from Step 2.
  CALLBACK METHOD Select POST or GET.
  FALLBACK URL (OPTIONAL) Enter a backup Twilio App URL.
  FALLBACK METHOD Select POST or GET.
  STATUS CALLBACK URL (OPTIONAL) Enter your Callback URL.
  STATUS CALLBACK METHOD Select POST or GET.

Additional Resources

Have more questions? Submit a request
Powered by Zendesk