Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Facebook Messenger (Public Beta)


(warning)

Warning

Public Beta

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

facebook-messenger-setup page anchor

1. Agree to the Terms and Install Facebook Messenger

1-agree-to-the-terms-and-install-facebook-messenger page anchor

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.

To get started, first go to the Channels area in the Twilio Console(link takes you to an external page), click on Facebook Messenger and install it.

2. Authorize Twilio to Send Messages on Your Behalf

2-authorize-twilio-to-send-messages-on-your-behalf page anchor

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

3-configure-a-facebook-page-to-use-as-a-sender page anchor

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

optional-configure-additional-fields page anchor

Once a Channel is authenticated, you can now configure it to work with a Twilio API :

Configuration ParameterDescription
Page Friendly NameThis is the name of the Facebook Page. This cannot be changed.
Callback URLA 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 MethodHttp method to use with Callback URL. GET or POST.
Fallback URLFallback URL to which Twilio will call if the Callback URL above returns an error.
Fallback MethodHttp method to use with Fallback URL. GET or POST.e IDThis 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 URLA 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 MethodHttp method to use with Status Callback. GET or POST.

Setting Up Multiple Senders

setting-up-multiple-senders page anchor

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(link takes you to an external page).


Using Facebook Messenger

using-facebook-messenger page anchor

Facebook Messenger Is a User-Initiated Channel

facebook-messenger-is-a-user-initiated-channel page anchor

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)(link takes you to an external page).

(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

retrieve-the-messenger-user-id-from-the-callback page anchor

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

respond-using-the-programmable-messaging-api page anchor

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.
  • Your message body.

See the REST API: Sending a SMS or MMS or REST API: Messages page for details.

Respond Using the Programmable Messaging API

respond-using-the-programmable-messaging-api-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = require('twilio')(accountSid, authToken);
_14
_14
client.messages
_14
.create({
_14
from: 'messenger:{facebook_page_id}',
_14
body: 'Would you like to play a game?',
_14
to: 'messenger:{messenger_user_id}'
_14
})
_14
.then(message => console.log(message.sid));

Output

_24
{
_24
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"api_version": "2010-04-01",
_24
"body": "Would you like to play a game?",
_24
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_24
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_24
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_24
"direction": "outbound-api",
_24
"error_code": null,
_24
"error_message": null,
_24
"from": "messenger:{facebook_page_id}",
_24
"num_media": "0",
_24
"num_segments": "1",
_24
"price": null,
_24
"price_unit": null,
_24
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"sid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"status": "queued",
_24
"subresource_uris": {
_24
"media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json"
_24
},
_24
"to": "messenger:{messenger_user_id}",
_24
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
_24
}


Managing Your Facebook Senders

managing-your-facebook-senders page anchor

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

maintaining-high-quality page anchor

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.


Rate this page: