Menu

Expand
Rate this page:

Twilio Channels: Facebook Messenger

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.

Channels are a collection of third-party integrations that let you send and receive messages on multiple channels with the Twilio APIs you already use. Currently, Facebook Messenger (Beta) and WhatsApp Business API are supported. You may use Facebook Messenger through Twilio Programmable Messaging and WhatsApp through Twilio Programmable Messaging and Conversations. Click here to install Facebook Messenger. For WhatsApp, learn more about the onboarding process or get started now with the WhatsApp sandbox.

Set Up Facebook Messenger

Prerequisites

In order to send and receive messages from Facebook Messenger, you must have:

  • A Facebook Page set up for your business: This is the identity that will be used to receive and respond to messages on Facebook Messenger. 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.
  • A personal Facebook account: Your Facebook account must have admin access to the Facebook Page.

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.

To get started, first go to the Channels area in the Twilio Console, click on Facebook Messenger and install it.

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
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.

Note: 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).

Note: You must receive a message from an end user before you can respond. Facebook Messenger is not a notification channel.

Tip: You can send yourself a message using m.me/<page id>. This is the easiest way to test your sender.

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:

  • A recipient.
  • A sender.
  • Your message body.

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

        
        
        

        Managing Your Facebook Senders

        Opt-Ins and Opt-Outs

        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.

        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 Community Forums or browsing the Twilio tag on Stack Overflow.

              
              
              

              Thank you for your feedback!

              We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

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

              Thanks for your feedback!

              Refer us and get $10 in 3 simple steps!

              Step 1

              Get link

              Get a free personal referral link here

              Step 2

              Give $10

              Your user signs up and upgrade using link

              Step 3

              Get $10

              1,250 free SMSes
              OR 1,000 free voice mins
              OR 12,000 chats
              OR more