Sinch Developer Documentation

Building blocks to enable rich customer communication

Send a FaceBook Messenger message

In this section you will learn how to create and configure a basic FaceBook Business Page with Messenger chat feature. Once you complete the steps below you will have a FaceBook App, FaceBook Business Page with Messenger Chat button, a Messenger Token, and a configured Messenger Webhook to use with the Sinch Conversation API.

Set up a Facebook Page Beta

A Facebook Page is required to use the Facebook Messenger API. It is used as the identity of your Messenger experience. When people chat with your app, they will see the Page name and the Page profile picture. To create a new Page, visit https://www.facebook.com/pages/create. If you already have one, you can skip to (#create-your-facebook-app).

Create New PageCreate New Page

Next, choose to create a "Business or Brand" and fill out the ensuing page name and contact form.

Create Business PageCreate Business Page

You can choose to "Skip" adding 'Profile' and 'Background' pictures as well as "Not Now" for the option to 'Add online booking'. You have now completed creating your Facebook Business Page. Remember while your FaceBook App is 'In development' the FaceBook Business Page is not visible to anyone except you and other developers you invite to your FaceBook developer account.

Make sure to bookmark your FaceBook Business Page. You will head back there to send messages later.

Business PageBusiness Page

Add a Messenger Chat Button to your FaceBook Business Page

Click on "+ Add Button".

Facebook Page Add ButtonFacebook Page Add Button

Choose Send Message and click "Next".

Fb Add Send Message ButtonFb Add Send Message Button

Click on "Messenger" and then click "Finish".

Fb Add Button MessengerFb Add Button Messenger

Create your Facebook App

If you have an existing FaceBook Developer Account and a FaceBook App, you can skip to Add Messenger Product to your FB App.
To register for a FaceBook Developer account, go to Facebook Developer Account and click "Get Started" on the upper right menu.

Once you have created your Facebook developer account, you can choose to "Create First App".

Create App FormCreate App Form

Your new APP ID will be displayed at the top left of your FaceBook App Dashboard.

Facebook App DashboardFacebook App Dashboard

Add Messenger to your app

From your FaceBook Developer Dashboard, under Add Product, click on the Messenger "Setup" button.

Generate your Messenger API Token

To generate your Messenger API Token, add the FaceBook Page you created earler. Scroll down to Access Tokens and click "Add or Remove Pages".

Add Remove PageAdd Remove Page

Next, follow the prompts and choose the new FaceBook Page you just created. Make sure that you leave the default setting Manage and access Page conversations in Messenger set to YES.

Manage and Access ConversationsManage and Access Conversations

You should see your FaceBook Page listed under Access Tokens. Click on the "Generate Token" button.

Copy and store your Messenger Token somewhere safe, we will need it to add the Messenger Channel to your Sinch Conversations App.

Generate Messenger TokenGenerate Messenger Token

Configure your FaceBook Messenger Channel on Sinch Conversation API

Create and send a POST to Patch your Sinch Conversations App with the newly created Messenger Token, this will allow the Sinch Conversations App to respond to inbound messages posted by visitors of your FaceBook Page.

curl --location --request POST 'https://eu.conversation.api.sinch.com/v1beta/projects/{project_id}/apps' \
--header 'Content-Type: application/json' \
-u '<client_id:client_secret>'
--data-raw '{
    "channel_credentials": [
        {
            "channel": "MESSENGER",
            "static_token": {
                "token": "{{YOUR_FB_PAGE_MESSENGER_TOKEN}}"
            }
        }
    ],
    "display_name": "Messages"
}'

Configure the Messenger Webhook

The Messenger Webhook Settings configuration forwards message events posted on your FaceBook Page to your Sinch Conversations App. To set the configuration, click on "Add Callback URL" in the FaceBook App Dashboard > Products > Messenger > Settings Webhooks.

Facebook Messenger WebhooksFacebook Messenger Webhooks

Then add the following Callback URL and Verify Token:

https://messenger-adapter.conversation-api.prod.sinch.com/adapter/v1/{{YOUR_SINCH_CONVERSATION_APP_ID}}/callback

Verify Token: 5651d9fd-5c33-4d7a-aa37-5e3e151c2a92

Facebook Messenger Edit WebhookFacebook Messenger Edit Webhook

To complete your Webhooks configuration, click on "Add Subscriptions". Select "messages" and "message_deliveries" fields and click on "Save".

Facebook Webhook SubscriptionFacebook Webhook Subscription

Great! You're almost there. Just a couple more steps.

Start a conversation in Messenger and Respond with Sinch Conversation API

OK, you are ready for some action! Visit your FB Page, click on "Send Message" and choose "Test Button".

Facebook test send message buttonFacebook test send message button

Enter a message into the Messenger chat window and Send.

Facebook Messenger Pop upFacebook Messenger Pop up

Use Sinch Conversation API to List Contacts, you should now see a new contact entry generated when the Messenger Message was posted from your FaceBook Page.

{
    "contacts": [
        {
            "id": "J69H07BDS8G11RDF01E96CW660",
            "channel_identities": [
                {
                    "channel": "MESSENGER",
                    "identity": "7746490198930851",
                    "app_id": "3FDS0PWWERGN1QX101E75WGS3Y"
                }
            ],
            "channel_priority": [
                "MESSENGER",
            ],
            "display_name": "",
            "email": "",
            "external_id": "",
            "metadata": ""
        }
    ],
    "next_page_token": ""

Use your newly created Sinch Contact to send a Text Message response using the message:send function.

curl --location --request POST 'https://eu.conversation.api.sinch.com/v1beta/projects/{project_id}/messages:send' \
-u '<client_id:client_secret>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "app_id": "{{YOUR_SINCH_APP_ID}}",
    "recipient": {
        "contact_id": "{{YOUR_SINCH_CONTACT_ID}}"
    },
    "message": {
        "text_message": {
            "text": "Greetings from Sinch Conversation API!"
        }
    },
    "channel_priority_order": [
        "MESSENGER"
    ]
}'
RequestBody body =
    RequestBody.create(
        mediaType,
        "{\n"
            + "\t\n"
            + "\t\"app_id\": \"your_app_id\",\n"
            + "    \"recipient\": {\n"
            + "    \t\"contact_id\": \"your_contact_id\"\n"
            + "    },\n"
            + "    \"message\": {\n"
            + "        \"text_message\": {\n"
            + "            \"text\": \"Text message from Sinch Conversation API.\"\n"
            + "        }\n"
            + "    },\n"
            + "    \"channel_priority_order\": [\n"
            + "        \"SMS\"\n"
            + "    ]\n"
            + "}");
Request request =
    new Request.Builder()
        .url(
            "https://eu.conversation.api.sinch.com/v1beta/projects/{project_id}/messages:send")
        .method("POST", body)
        .addHeader("Content-Type", "application/json")
        .addHeader(
            "Authorization",
            "Basic " + Base64.getEncoder().encodeToString("{client_id}:{client_secret}".getBytes()))
        .build();
Response response = client.newCall(request).execute();

Facebook Message TextFacebook Message Text

ALRIGHT!! CONGRATULATIONS, you have just sent your first Sinch Conversations Messenger Message!

  1. Learn how to receive messages
  2. Learn how to send rich messages with Facebook messenger.

Edit on GitHub

Updated 20 days ago


Send a FaceBook Messenger message


In this section you will learn how to create and configure a basic FaceBook Business Page with Messenger chat feature. Once you complete the steps below you will have a FaceBook App, FaceBook Business Page with Messenger Chat button, a Messenger Token, and a configured Messenger Webhook to use with the Sinch Conversation API.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.