Facebook Messenger is currently available as a Public Beta product. This means that some features are not yet implemented and others may be changed before the product is declared as Generally Available.
Public Beta products are not covered by a Twilio SLA.
Facebook Messenger is a user-initiated channel, which means that end users have to reach out to your business before you can respond. This makes it a great fit for customer support, service and ads-driven sales use cases (e.g. click to message). We recommend using Facebook Messenger with Twilio Flex or Conversations API. You may also use Facebook Messenger with Programmable Messaging API if you have set up webhooks to triage inquiries.
Facebook Messenger Setup
1. Agree to the Terms and Install Facebook Messenger
All of the following steps are done through the Twilio Console. In the Facebook Messenger ecosystem, users communicate with brands and companies by messaging their Facebook Page. Twilio creates a Sender for each Facebook Page that you wish to use for messaging. A Sender is the identity used in the "From" field to send messages to your users.
2. Authorize Twilio to Send Messages on Your Behalf
Next, navigate to the Facebook Messenger channel that was just installed and click the "Connect with Facebook" button. Follow the prompts to select the Facebook Pages you want to authorize to configure as senders. In this step, you will be authorizing Twilio's Facebook Application to send and receive messages on behalf of your Facebook Page(s), thereby enabling access to Facebook Messenger through the Twilio Programmable Messaging API.
Note: You do not have to set up your own Facebook Application, as Twilio takes care of that for you.
3. Configure a Facebook Page to Use as a Sender
Next, let's configure the Facebook Page you wish to use as a sender. While on the Twilio Channels Catalog page:
Under the "Properties" heading in the Unique Name input field, enter a name of your choice for your page (Optional).
Under the "Credentials" heading click the Select a Page dropdown and select a single Facebook Page to use as a sender.
Under the "Configuration" heading in the Callback URL input field, enter a webhook URL where you can receive incoming messages sent to the Facebook Page from your end users.
Finally, click the "Save" button. This creates an instance of the Facebook Page that you can now use as a Sender.
Optional: Configure Additional Fields
Once a Channel is authenticated, you can now configure it to work with a Twilio API :
Configuration Parameter
Description
Page Friendly Name
This is the name of the Facebook Page. This cannot be changed.
Callback URL
A URL where Twilio will POST each time a message is received by Twilio. The format of this request is the same as Twilio's Inbound SMS TwiML Request. Non-relative URLs must contain a valid hostname (underscores are not allowed).
Callback Method
Http method to use with Callback URL. GET or POST.
Fallback URL
Fallback URL to which Twilio will call if the Callback URL above returns an error.
Fallback Method
Http method to use with Fallback URL. GET or POST.e ID
This is a unique identifier for the Facebook Page, which is used as the Sender: messenger:<page id>. This is also a unique identifier that can be used to navigate to the Facebook Page by following this URL: m.me/<page id>. This ID can not be changed.
Status Callback URL
A URL where Twilio will call each time your outbound message status changes to one of the following: failed, sent. Twilio will POST the standard TwiML request parameters as well as standard Status parameters : MessageStatus and ErrorCode. Non-relative URLs must contain a valid hostname (underscores are not allowed).
Status Callback Method
Http method to use with Status Callback. GET or POST.
Setting Up Multiple Senders
Twilio supports creating multiple instances so that your application can support different Facebook Pages. If you wish to configure more than one Facebook Page as a sender, you can click "Add Another Instance" and repeat the steps above for each new Facebook Page.
For Independent Software Vendors (ISV's) and Software Integrators (SI's) who are managing Facebook Messenger communications on behalf of your clients, you need to have admin access to each Facebook page.
Update (November 2022): Please note that at this time, a max of 25 Facebook pages can be used per Twilio account or subaccount. To use additional FB pages, you will need to use additional subaccounts.
(information)
Info
If you are an ISV or SI managing multiple pages on behalf of many brands, we recommend using subaccounts for each brand. For more information on using subaccounts please see the support article Getting Started with Twilio Projects and Subaccounts.
Using Facebook Messenger
Facebook Messenger Is a User-Initiated Channel
Now that your Facebook Messenger Sender is set up, you need to receive a message from an end user in order to respond. Facebook users 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).
(warning)
Warning
You must receive a message from an end user before you can respond. Facebook Messenger is not a notification channel.
(information)
Info
You can send yourself a message using m.me/<page id>. This is the easiest way to test your sender.
(information)
Info
Twilio tags messages with "ACCOUNT_UPDATE" if sent after the 24 hr session is up.
Retrieve the Messenger User ID from the Callback
When a user sends a message to your Facebook Page, your callback URL will receive the message with the same parameters as a standard Twilio WhatsApp or SMS message. Facebook Messenger sender and recipients have the format messenger:{messenger id}. You will need to retrieve the Facebook Messenger user ID from the callback response.
Respond Using the Programmable Messaging API
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:
You are also responsible for managing consumer opt-ins and opt-outs to Facebook Messenger platforms. Users grant you permission to message them by way of initiating the conversation with your Facebook Page. When users request that you stop messaging, you are required to stop messaging them. Users also have the option to block your page from reaching out to them again.
Maintaining High Quality
A business must strictly adhere to Facebook's commerce and business policies and is also expected to provide high quality experiences in Messenger. During or after the interaction in Messenger, users can provide negative feedback to Facebook when a page's conversations are considered spammy, abusive, or unpleasant. It is recommended that you maintain high quality, value-adding conversations that are aligned with the user's intention in engaging with you. If a business shows a pattern of violating Facebook's policies, Facebook will disable the page from using Facebook Messenger.