Skip to contentSkip to navigationSkip to topbar
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 aren't 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 APILink to code sample: Respond Using the Programmable Messaging API
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createMessage() {
11
const message = await client.messages.create({
12
body: "Would you like to play a game?",
13
from: "messenger:{facebook_page_id}",
14
to: "messenger:{messenger_user_id}",
15
});
16
17
console.log(message.body);
18
}
19
20
createMessage();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"api_version": "2010-04-01",
4
"body": "Would you like to play a game?",
5
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
6
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
7
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
8
"direction": "outbound-api",
9
"error_code": null,
10
"error_message": null,
11
"from": "messenger:{facebook_page_id}",
12
"num_media": "0",
13
"num_segments": "1",
14
"price": null,
15
"price_unit": null,
16
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"status": "queued",
19
"subresource_uris": {
20
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
21
},
22
"tags": {
23
"campaign_name": "Spring Sale 2022",
24
"message_type": "cart_abandoned"
25
},
26
"to": "messenger:{messenger_user_id}",
27
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
28
}

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.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.