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. Supported formats: png, jpeg, gif.
media: gifsyes
media: videoyesMaximum file size for an uploaded video is 25 MB. Supported formats: mp4, ogg, avi, mov, webm.
media: audioyesMaximum file size for an uploaded audio is 25 MB. Supported formats: acc, m4a, wav, mp4.
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.
marketing messages: optin requestsyesSupport for sending marketing message optin requests.
marketing messages: notificationsyesSupport for sending all message types as marketing message.



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 hourly rate limit is equal to 200 * the number of people the customer can message via Facebook Messenger. This limit is high enough for most use cases. So if you have 1 conversation with 1 customer you can sent maximum 200 messages back to this customer. If there are 2 conversations with 2 customer you can sent maximum 400 messages back to these customers.

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.

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



Text

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."
                }
            }
        ]
    }
}



Media

Media typeSupported formatsMimetypeSupported size maximum
Audioacc, m4a, wav, mp4audio/acc, audio/m4a, audio/wav, audio/mp425MB
Imagepng, jpeg, gifimage/png, image/jpeg, image/gif8MB
Videomp4, ogg, avi, mov, webmvideo/mp4, video/ogg, video/avi, video/mov, video/webm25MB
Documentapplication/pdfAll common MIME types supported. For example: application/pdf25MB

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.

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.png",
                                "mediaUri": "https://www.cm.com/cdn/cm/cm.png",
                                "mimeType": "image/png"
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Direct message with text and video

In the example below, we send a simple rich content message that contains both text and a video 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": "your-video.mp4",
                                "mediaUri": "your-video-url.mp4",
                                "mimeType": "video/mp4"
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Direct message with text and document

In the example below, we send a simple rich content message that contains both text and a document 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-pdf.pdf",
                                "mediaUri": "your-document.pdf",
                                "mimeType": "application/pdf"
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Direct message with text and audio

In the example below we send a simple rich content message that contains both text and audio that Facebook 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": "your-audio.mp4",
                                "mediaUri": "your-audio-url.mp4",
                                "mimeType": "audio/mp4"
                            }
                        }
                    ]
                }
            }
        ]
    }
}



Suggestions (Quick Reply)

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.

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"
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    }
}



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.
NOTIFICATION_MESSAGEAllows to send all message types as a marketing message, needs to be combined with a notification_token as recipient.

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"
                        }
                    ]
                }
            }
        ]
    }
}



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.

Direct message with button rich card

In the example below we send a simple rich content message that contains elements that Facebook Messenger will display as a button 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.",
                                        "suggestions": [
                                            {
                                                "action": "REPLY",
                                                "label": "Give me more info",
                                                "postbackdata": "INFO"
                                            },
                                            {
                                                "action": "OPENURL",
                                                "label": "Visit CM.com",
                                                "url": "https://www.cm.com/"
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    }
}

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.

Direct message with media rich card

In the example below we send a simple rich content message that contains elements that Facebook Messenger will display as a media 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": [
                                    {
                                        "media": {
                                            "mediaName": "cm.png",
                                            "mediaUri": "https://www.cm.com/cdn/cm/cm.png",
                                            "mimeType": "image/png"
                                        },
                                        "suggestions": [
                                            {
                                                "action": "REPLY",
                                                "label": "Give me more info",
                                                "postbackdata": "INFO"
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Product template

🚧

Note

This feature is in beta and not publicly available yet

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.

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"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    }
}

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.

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.png",
                                            "mediaUri": "https://www.cm.com/cdn/cm/cm.png",
                                            "mimeType": "image/png"
                                        },
                                        "suggestions": [
                                            {
                                                "action": "REPLY",
                                                "label": "Give me more info",
                                                "postbackdata": "INFO"
                                            },
                                            {
                                                "action": "OPENURL",
                                                "label": "Visit CM.com",
                                                "url": "https://www.cm.com/"
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Rich Card Carousel

A carousel of Rich Cards with different compositions of a title, a subtitle, a media image and multiple suggestions

In the example below we send a rich content message that contains a carousel of rich cards. The rich cards have multiple different compositions in which they are shown to the end user. It's possible to mix different elements with each other.

{
    "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.png",
                                            "mediaUri": "https://www.cm.com/cdn/cm/cm.png",
                                            "mimeType": "image/png"
                                        },
                                        "suggestions": [
                                            {
                                                "action": "REPLY",
                                                "label": "Give me more info",
                                                "postbackdata": "INFO"
                                            },
                                            {
                                                "action": "OPENURL",
                                                "label": "Visit CM.com",
                                                "url": "https://www.cm.com/"
                                            }
                                        ]
                                    },
                                    {
                                        "header": "Our logo!",
                                        "media": {
                                            "mediaName": "cm.png",
                                            "mediaUri": "https://www.cm.com/cdn/cm/cm.png",
                                            "mimeType": "image/png"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    }
}



Marketing Messages

With Marketing Messages you can send (recurring) notifications on a topic, a user has opted-in to. During the 24-hour messaging window, you can send users this notification opt-in request. Users can opt-in to receive Marketing Messages any time after this opt-in request is sent. Once a user opts-in, you are allowed to send Marketing Messages related to the topic they opted-in to for a daily frequency.

Best practices

  • Your opt-in request, including the title and image, encompasses the types of Marketing Messages users can expect to receive, such as order updates, product recommendations, or certain offers.
  • When sending more than one opt-in request to a user, each opt-in request should clearly state the different, specific types of Marketing Messages the user can expect to receive.
  • You must not use Marketing Messages, including opt-in requests, to spam users. This includes sending duplicate opt-in requests at high frequencies to the same users.

Users can provide feedback on your messaging experience, including blocking your messaging, which may result in restrictions on your use of Marketing Messages. You should regularly review your opt-in requests and Marketing Messages to see if they meet the best practices above.

Limitations

  • You can only send one opt in request to a person per week for the same, specific topic.
  • You may only send a request for a user to opt-in to Marketing Messages within the standard 24 hour messaging window. A user’s action of opting-in to Marketing Messages does not open the 24 hour messaging window.
  • Do not send duplicate opt-in requests to users, which is defined as having the same title and image_url.
  • You can only see if a person has opted in to receiving Marketing Messages.
  • If a person has chosen to stop receiving Marketing Messages, your notifications will no longer be delivered to that person and you will receive an error.
  • A person can block, mute, or report your messaging.

Sending Marketing Messages Opt-In Requests

📘

Token Expiration and Re-Opt In

Beginning August 10, 2023, notification tokens will no longer expire. Re-opt in requests and opt out reminders will also no longer be sent.

Before sending Marketing Messages, users must opt-in via an opt-in request. You must not send more than one opt-in request to a user per week on the same, specific topic. If you attempt to send an opt-in request to a user for the same topic in less than a week, the request will be blocked and you will receive an error message. In addition, there must be an open 24 hour messaging window before you can send an opt-in request to the user. Users can opt-in to receive Marketing Messages for multiple topics in the same thread. When a user chooses to opt-in on your Marketing Message a opt-in event will be triggered, see incoming events for more information on Facebook Marketing Messages events.

You can send an opt-in request as a single suggestion. The following restrictions apply for an opt-in message:

FieldRequiredRemarks
actionYesThe action field is required and always needs to have the value "optin" to send the message as a opt-in message.
postbackdataYesYour opt-in reference.
labelYesDisplayed as the title. Maximum lenght is 65 characters.
mediaUriNoThe URL of the image to display in the opt-in request.
optinYesSee table below for opt-in details.

The following fields can be included as part of opt-in:

FieldRequiredRemarks
frequencyYesDAILY
reoptinNoTrue or False. When value is True, an automatic reoptin is sent to end-user when subscription expires.
timezoneNoDefault value is UTC. List of available time zones

Marketing Message opt-in request

In the example below we send a Marketing Message opt-in request that gives the recipient the option to opt-in on your notifications.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "allowedChannels": ["Facebook Messenger"],
                "from": "Your Facebook account ID",
                "to": [
                    {
                        "number": "Recipients PSID"
                    }
                ],
                "body": {
                    "content": ""
                },
                "richContent": {
                    "conversation": [
                        {
                            "suggestions": [
                                {
                                    "action": "optin",
                                    "postbackdata": "OPT_IN",
                                    "label": "Nice products!",
                                    "media": {
                                        "mediaName": "cm.png",
                                        "mediaUri": "https://www.cm.com/cdn/cm/cm.png",
                                        "mimeType": "image/png"
                                    },
                                    "optin": {
                                        "frequency": "DAILY",
                                        "reoptin": true,
                                        "timezone": "Europe/Amsterdam"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    }
}

Sending Marketing Messages

After a user opt-in, you can send your users Marketing Messages once every calendar day which starts from 12:00am until 11:59pm in the time zone set by you.

🚧

Important

A Marketing Messages message token is generated per opt-in (per user) which can then be used to send Marketing Messages. This means that instead of the users PSID you need to use the specific notification token received when the user opted-into your opt-in request to send Marketing Messages to this user.

If you sent two opt-in requests (with different topics) to your user, two separate notification message tokens are generated if the user opted-in to both requests.

📘

The NOTIFICATION_TAG

You can sent any type of Facebook message as a Marketing Message (except a opt-in request) as long as you use the notification token linked to the user as the recipient in combination with the "NOTIFICATION_MESSAGE" tag.

Sending Marketing Messages

In the example below we send a text message as a Marketing Message. Reminder: Every message type can be used as a Marketing Message as long as you combine the notification token with the "NOTIFICATION_MESSAGE" tag.

{
    "messages": {
        "authentication": {
            "producttoken": "Your product token"
        },
        "msg": [
            {
                "from": "Your Facebook account ID",
                "to": [
                    {
                        "number": "The notification token of the user"
                    }
                ],
                "body": {
                    "content": ""
                },
                "allowedChannels": ["Facebook Messenger"],
                 "richContent": {
                    "conversation": [
                        {
                            "text": "CM.com - Be part of it.",
                            "tag": "NOTIFICATION_MESSAGE"
                        }
                    ]
                }
            }
        ]
    }
}



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.