Facebook Messenger

Our business messaging API supports sending and receiving Facebook Messenger messages.

Being able to send Facebook Messenger messages requires requesting access via the Channels portal. Without onboarding with Facebook Messenger via the portal, you can not make use of this part of the API.

Fact sheet

FeatureSupportRemarks
delivery notificationyesOccurs when your message is delivered to the Facebook Messenger platform. Delivery notifications are sent to the status report webhooks.
text messagesyesThe maximum length of a Facebook Messenger message is 2.000 characters and it must be UTF-8 encoded.
mediayesMedia name attribute should end in the proper file extension. Only one media file is allowed per message; when sending multiple files, each file will be sent in its own Facebook Messenger message. When the linked media doesn't exist/can't be found, the message will not be sent at all. The provided text message is sent in a separate Facebook Messenger message.
media: imagesyesMaximum file size for an uploaded image is 25 MB. All common MIME types supported. For example: image/jpeg, image/png, image/webp.
media: gifsyesMaximum file size for an uploaded GIF is 25 MB. Supported MIME types are image/gif.
media: videoyesMaximum file size for an uploaded video is 25 MB. All common MIME types supported. For example: video/mp4, video/quicktime.
media: audioyesMaximum file size for an uploaded audio is 25 MB. All common MIME types supported. For example: audio/aac, audio/mpeg.
media: documentyesMaximum file size for an uploaded document is 25 MB. All common MIME types supported. For example: application/pdf.
reply suggestionsyesMaximum label length: 20 characters.
rich cardyesSupport for generic, media, button and product template.
rich carouselyesSupport for generic and product templates. Maximum of 10 templates supported.
message tagsyesAllows messaging outside the standard messaging window of 24 hours.

Onboarding

Onboarding is done via our Channels portal. On our portal, you will be presented with a facebook login pop up. In this pop up you will need to authorize our Facebook app, called CM.com Business Messaging to send and receive Facebook Messenger messages on behalf of your Facebook account.

This app requires the following permissions to work correctly:

  • "Manage and access Page conversations in Messenger"
  • "Show a list of the Pages you manage"

If you choose the de-select these permissions in the facebook pop up, we will not be able to complete the onboarding.

Business rules

Sending Facebook Messenger messages using the CM Business Messaging API also requires you to adhere to the Facebook Messenger Policy & Guidelines.

It is allowed to have multiple Facebook accounts under one CM.com account.

Considerations

Note that in case of Facebook, the Facebook account that is used for sending messages is also still available in the regular Facebook app, from the Facebook website and from other 3rd party Facebook apps. Our API only has permissions to send on behalf of the Facebook account, but it's not exclusively in control of that Facebook account.

This means that it will be possible to send messages using Facebook as well as using our API, and that might lead to situations where the API will relay replies to messages you sent via the Facebook app or website.

In those cases it will seem like messages are missing from a conversation when you use both ways of communicating with your end-users.

Our recommendation is to use the API exclusively for these Facebook accounts, and not switch between the Facebook app or website and the API, because the API won't "know" about the messages you sent using the app or website, but it will receive the replies to those messages.

The only way to have a Facebook Messenger conversation with end-users is when the end-user starts the conversation by sending you an initial message.

Facebook Messenger has rate limits in place; the per day rate limit is equal to 200 * the number of people the customer can message via Facebook Messenger.

If you choose to revoke any of the permissions given during the onboarding process on facebooks side, we might no longer be able to deliver messages.

Once onboarded, the authorization of our Facebook app expires after 90 days. This impacts the ability of our Facebook app to retrieve the name of the end user. In order to remedy this, you must re-authorize our Facebook app using the same onboarding process.

Sending messages

Unlike other channels, Facebook Messenger does not use telephone numbers as identifiers for sender (from) and recipient (to.number), instead it uses a so called "Page Scoped User ID (PSID)" for the recipient and a "Page ID" for the sender. A person is assigned a unique PSID for each Facebook Page they start a conversation with. Do note that the PSID is only valid for the Facebook page that received a message from a Facebook user.

Your Page ID is visible in the CM.com platform under channels...Facebook Messenger. The last section of the Page URL is your Page ID. E.g. https://www.facebook.com/1234567890 with 1234567890 as the Page ID.

Display order

If you send a message including both an image and some text, Facebook Messenger will display these as separate messages; typically the text will be the first message.

See the Facebook Messenger message with text and image example.

Suggestions

The following actions are supported by Facebook as buttons.

ActionRemarks
Reply*Maximum length of label is 20 characters.
OpenUrlMaximum length of label is 20 characters, url required.
DialMaximum length of label is 20 characters, phone number required.
LoginSuggestion without text, url required.
LogoutSuggestion without text.

🚧

Note

A reply action can be used as either a button or as a quick reply.

An explanation on suggestions can be found under Suggestions/Features

Quick reply

Quick Replies allows you to suggest quick answers for the recipient beneath your message.
Quick replies can be combined with any type of message; text, media or rich card.
A maximum of 13 quick replies are supported by Facebook Messenger.

The following restrictions apply for a quick reply:

FieldRequiredRemarks
labelYesMaximum length is 20 characters.
postbackdataYesMaximum length is 1000 characters.
mediaNoThumbnail image, should be at least 24 x 24 pixels.

Quick replies can also be included as a reply button to a template but each template has its own button limit.
If those limit has been passed, your reply suggestions will be included as quick replies beneath your message.

More info can be found in the rich content description.

Message Tags

Message tags enable sending important and personally relevant 1:1 updates to users outside the standard messaging window of 24 hours. This enables greater flexibility in how you interact with people, as well as the types of experiences you can build on the Facebook Messenger Platform. They may not be used to send promotional content (e.g. deals, offers, coupons, discounts, etc.). Use of tags outside of the approved use cases may result in restrictions on the Page's ability to send messages. See the Facebook Messenger Platform policy for details.

The following message tags are supported:

TagDescription
CONFIRMED_EVENT_UPDATESend the user reminders or updates for an event they have registered for (e.g., RSVP'ed, purchased tickets). This tag may be used for upcoming events and events in progress.
POST_PURCHASE_UPDATENotify the user of an update on a recent purchase.
ACCOUNT_UPDATENotify the user of a non-recurring change to their application or account.
HUMAN_AGENTAllows human agents to respond to user inquiries. Messages can be sent within 7 days after a user message.

Rich card

Rich cards, called templates in Facebook Messenger, offer a way for you to offer a richer in-conversation experience than standard text messages by integrating buttons, images and more alongside text in a single message. Rich cards can be used for many purposes, such as displaying product information or asking the message recipient to choose from a pre-determined set of options.

You can send rich cards as one of the following Facebook templates.

  • Button template
  • Media template
  • Product template
  • Generic template

More info about the templates specifically down below.

When sending rich cards we recommend adhering to the Best Practices defined by Facebook.

Button template

The button template sends a structured message with up to three attached buttons.
This template is useful for offering the recipient options to choose from, such as pre-determined responses to a question, or actions to take.

The button template is quit similar to other templates. But unlike other templates, there is a maximum of 640 characters.

The following restrictions apply for a button template:

FieldSupportRequiredRemarks
cardsNoNoSupported if a single card is given
headerYesYesDisplayed as the text. Maximum length is 640 characters.
textNoNo-
mediaUriNoNo-
suggestionsYesYesMaximum of 3 buttons per card. If more are given, all will be included as quick replies, instead of buttons.

The following Facebook buttons can be used. More info about each button can be found in the rich content description.

ButtonActionRemarks
URLOpenUrlMaximum length of button text is 20 characters, url required.
PostbackReplyMaximum length of button text is 20 characters.
Call numberDialMaximum length of button text is 20 characters, phone number required.
Log inLoginButton without text, url required.
Log outLogoutButton without text.

When sending rich cards containing buttons, we recommend adhering the Best Practises for using buttons defined by Facebook.

Media template

The media template allows you to send a image, GIF, or video as a structured message with an optional button.
Videos and animated GIFs sent with the media template are playable in the conversation.

The following restrictions apply for a media template:

FieldSupportRequiredRemarks
cardsNoNoSupported if a single card is given
headerNoNo-
textNoNo-
mediaUriYesYesImage or video
suggestionsYesNoMaximum of 1 button per card. If more are given, all will be included as quick replies, instead of buttons.

Product template

The product template sends a structured message to render products that have been uploaded to your Facebook catalog.
You need to provide the product ids that are linked to your Facebook page.

Up to 10 products can be provided via either suggestions directly or suggestions in a carousel.

The following restrictions apply for a product template:

FieldSupportRequiredRemarks
cardsYesNoWith a maximum of 10 per message.
headerNoNo-
textNoNo-
mediaUriNoNo-
suggestionsYesYesOnly action 'ViewProduct' supported. With a maximum of 10 per message.

Generic template

A simple structured message that includes a title. May include a subtitle, image and up to three buttons.

This template will be used if fields are given that are not covered by other Facebook templates.

The following restrictions apply for a generic template:

FieldSupportRequiredRemarks
cardsYesYes (If header not defined)Maximum 10 allowed per message. At least one property must be set in addition to header.
headerYesYes (If cards not defined)Displayed as the title. Maximum length is 80 characters.
textYesNoDisplayed as the subtitle. Maximum length is 80 characters.
mediaUriYesNoThe URL of the image to display.
suggestionsYesNoMaximum of 3 buttons per card. If more are given, all will be included as quick replies, instead of buttons.

Input matrix

You can use the following matrix to check what type of message will be send with the included inputs.

TextMediaSuggestionsHeaderOutput
xxxxNot supported
xxxGeneric template
xxxProduct template if 'ViewProduct' action, otherwise not supported
xxButton template with max 3 buttons or as template with quick replies
xxxMedia message
xxGeneric template
xxMedia template with max 1 button or as template with quick replies
xGeneric template with max 3 buttons or as template with quick replies
xxxText message
xxGeneric template
xxText message with quick replies
xGeneric template with max 3 buttons or as template with quick replies
xxText and Media messages
xGeneric template
xNot supported
Generic template with max 3 buttons or as template with quick replies

Receiving messages / Inbound flow

Since Facebook Messenger is used for 2-way communication (chat) it is important to also implement an Inbound flow. You can find more information about how to do this using our API documentation of the Inbound webhook. Note that for Facebook Messenger you need to set up your webhook API in the Channels app, not in the Gateway app.

Examples

The following examples are some showcases of the possible input matrix combinations

An explanation on how to send rich content messages in general can be found in the rich content description.

Direct message with plain text content

The example below will send a simple text-only Facebook Messenger message.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "from": "Your Page ID",
                "to": [
                    {
                        "number": "Recipients PSID"
                    }
                ],
                "allowedChannels": ["Facebook Messenger"],
                "body": {
                    "type": "auto",
                    "content": "CM.com - Be part of it."
                }
            }
        ]
    }
}

Direct message with text and image

In the example below we send a simple rich content message that contains both text and an image that Facebook Messenger will display as two separate messages.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "from": "Your Page ID",
                "to": [
                    {
                        "number": "Recipients PSID"
                    }
                ],
                "body": {
                    "type": "auto",
                    "content": "Fallback Text"
                },
                "allowedChannels": ["Facebook Messenger"],
                "richContent": {
                    "conversation": [
                        {
                            "text": "CM.com - Be part of it.",
                            "media": {
                                "mediaName": "cm-tablet.jpg",
                                "mediaUri": "https://www.cm.com/cdn/web/blog/featured/cm-tablet.jpg",
                                "mimeType": "image/jpeg"
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Direct message with rich card content with button suggestions

In the example below we send a simple rich content message that contains elements that Facebook Messenger will display as a generic template.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "from": "Your Page ID",
                "to": [
                    {
                        "number": "Recipients PSID"
                    }
                ],
                "body": {
                    "type": "auto",
                    "content": "Fallback Text"
                },
                "allowedChannels": ["Facebook Messenger"],
                "richContent": {
                    "conversation": [
                        {
                            "carousel": {
                                "cards": [
                                    {
                                        "header": "CM.com - Be part of it.",
                                        "text": "Want to know more about CM.com?",
                                        "media": {
                                            "mediaName": "cm-tablet.jpg",
                                            "mediaUri": "https://www.cm.com/cdn/web/blog/featured/cm-tablet.jpg",
                                            "mimeType": "image/jpeg"
                                        },
                                        "suggestions": [
                                            {
                                                "action": "REPLY",
                                                "label": "Give me more info",
                                                "postbackdata": "INFO"
                                            },
                                            {
                                                "action": "OPENURL",
                                                "label": "Visit CM.com",
                                                "url": "https://www.cm.com/"
                                            }
                                        ]
                                    }
                                ]
                            }
                            
                        }
                    ]
                }
            }
        ]
    }
}

Direct message with quick reply suggestions

In the example below we send a rich content message that contains a text and some reply suggestions.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "from": "Your Page ID",
                "to": [
                    {
                        "number": "Recipients PSID"
                    }
                ],
                "body": {
                    "content": ""
                },
                "allowedChannels": ["Facebook Messenger"],
                "richContent": {
                    "conversation": [
                        {
                            "text": "Hi, what can I do for you?",
                            "suggestions": [
                                {
                                    "action": "Reply",
                                    "label": "Call me",
                                    "postbackdata": "CALL"
                                },
                                {
                                    "action": "Reply",
                                    "label": "Email me",
                                    "postbackdata": "EMAIL"
                                },
                                {
                                    "action": "Reply",
                                    "label": "Send me an sms",
                                    "postbackdata": "SMS"
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    }
}

Direct message with product suggestions

In the example below we send a rich content message that contains elements that Facebook Messenger will render as a product from your product catalog.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "from": "Your Page ID",
                "to": [
                    {
                        "number": "Recipients PSID"
                    }
                ],
                "body": {
                    "content": ""
                },
                "allowedChannels": ["Facebook Messenger"],
                "richContent": {
                    "conversation": [
                        {
                            "suggestions": [
                                {
                                    "action": "VIEWPRODUCT",
                                    "product": {
                                        "id": "FB_tshirt_001"
                                    }
                                },
                                {
                                    "action": "VIEWPRODUCT",
                                    "product": {
                                        "id": "FB_tshirt_002"
                                    }
                                },
                                {
                                    "action": "VIEWPRODUCT",
                                    "product": {
                                        "id": "FB_tshirt_003"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    }
}

Direct message with message tag

In the example below we send a simple text message with a message tag "POST_PURCHASE_UPDATE" applied. This tag is used to notify the user of an update on a recent purchase.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "from": "Your Page ID",
                "to": [
                    {
                        "number": "Recipients PSID"
                    }
                ],
                "body": {
                    "type": "auto",
                    "content": "Fallback Text"
                },
                "allowedChannels": ["Facebook Messenger"],
                "richContent": {
                    "conversation": [
                        {
                            "text": "Dear customer, your order with id 1234xyz has been shipped.",
                            "tag": "POST_PURCHASE_UPDATE"
                        }
                    ]
                }
            }
        ]
    }
}

Did this page help you?