All quick replies, message templates, as well as the persistent menu, support buttons that invoke different types of actions. These buttons allow you to easily offer the message recipient actions they can take in response to the template, such as opening the Messenger webview, sending a postback message to your webhook, and more.
For message templates, buttons are included defined by objects in the buttons
array. For the persistent menu, buttons are defined by objects in the call_to_actions
array. For more information on the specific purpose and format of each button type, see below.
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"PAGE-SCOPED-ID"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text":"Try the URL button!",
"buttons":[
{
// Button type payload
}
]
}
}
}
}' "https://graph.facebook.com/v21.0
/PAGE-ID/messages?access_token=PAGE-ACCESS-TOKEN"
{ "recipient_id": "1254477777772919", "message_id": "AG5Hz2Uq7tuwNEhXfYYKj8mJEM_QPpz5jdCK48PnKAjSdjfipqxqMvK8ma6AC8fplwlqLP_5cgXIbu7I3rBN0P" }
The URL Button opens a webpage in the Messenger webview. This button can be used with the Button and Generic Templates.
If the site contains App Links the button will click into a native app. If you just made the change, you can use the Sharing Debugger to request a new scrape of the site.
如要在 Messenger WebView 中顯示啟用了 Messenger 擴充功能 SDK 的網頁,您必須在 Bot Messenger 個人檔案的 whitelisted_domains
屬性中將網域列入允許清單(包含子網域)。這樣可確保只有受信任的網域可以透過 SDK 函數存取可用的用戶資訊。
如要進一步了解如何將網域列入允許清單,請參閱 whitelisted_domains
參考資料。
{
"type":"web_url",
"url":"URL_TO_OPEN",
"title":"BUTTON_TEXT",
"webview_height_ratio": "compact|tall|full",
"messenger_extensions": "true|false",
"fallback_url": "URL_TO_FALLBACK_TO"
}
Parameters | Description |
---|---|
| Type of button. Must be |
| Button title. 20 character limit. |
| This URL is opened in a mobile browser when the button is tapped. Must use HTTPS protocol if |
| Optional. Height of the Webview. Valid values: |
| Optional. Must be |
| The URL to use on clients that don't support Messenger Extensions. If this is not defined, the |
| Optional. Set to |
When the postback button is tapped, the Messenger Platform sends an event to your postback webhook. This is useful when you want to invoke an action in your bot. This button can be used with the Button Template and Generic Template.
For more information on using the postback button, see Postback Button.
{ "type":"postback", "title":"Postback Button", "payload":"DEVELOPER_DEFINED_PAYLOAD" }
Parameters | Description |
---|---|
| Type of button. Must be |
| Button title. 20 character limit. |
| This data will be sent back to your webhook. 1000 character limit. |
The Call Button can be used to initiate a phone call. This button can be used with the Button and Generic Templates.
For more information on using the call button, see Call Button.
{
"type":"phone_number",
"title":"<BUTTON_TEXT>",
"payload":"<PHONE_NUMBER>"
}
Parameter | Description |
---|---|
| Type of button. Must be |
| Button title, 20 character limit. |
| Format must have "+" prefix followed by the country code, area code and local number. For example, |
The game play button launches an Instant Game that is associated with the bot page.
For more information on using the game play button, see Game Play Button.
{
"type":"game_play",
"title":"Play",
"payload":"{<SERIALIZED_JSON_PAYLOAD>}",
"game_metadata": { // Only one of the below
"player_id": "<PLAYER_ID>",
"context_id": "<CONTEXT_ID>"
}
}
Property | Description |
---|---|
| Type of button. Must be |
| Button title, e.g. "Play". |
| Optional. This data will be sent to the game. |
| Optional. Parameters specific to Instant Games. By providing the optional |
player_id string | Optional. Player ID (Instant Game name-space) to play against. |
context_id string djkkcfildgngitknngklglglufergvdn | Optional. Context ID (Instant Game name-space) of the THREAD to play in |
Refer to Game Play webhook event for the event that will be sent to the bot when a user finishes a game round.
The log in button triggers the account linking authentication flow.
For more information on using the log in button, see Log In Button.
...
"buttons":[
{
"type": "account_link",
"url": "https://www.example.com/authorize"
}
]
...
Parameter | Description |
---|---|
| Must be |
| Authentication callback URL. Must use HTTPS protocol. |
The log out button triggers the account unlinking flow.
For more information on using the log out button, see Log Out Button.
{
"type": "account_unlink"
}
Parameter | Description |
---|---|
| Must be |
The Extension Button opens a webpage in the Messenger webview. This button can be used with the Persistent Menu and Generic Templates.
For more information on using buttons, see Buttons.
To display a webpage with the Facebook Extensions SDK enabled in the Messenger webview you must whitelist the domain, including sub-domain, in the whitelisted_domains
property of your Messenger Profile. This ensures that only trusted domains have access to user information available via SDK functions.
For more information on whitelisting domains, see the whitelisted_domains
reference.
{
"type":"extension",
"url":"<URL_TO_OPEN>",
"title":"<BUTTON_TEXT>",
"view_style": "<compact|tall|full>" (default full),
"fallback_url": "<URL_TO_FALLBACK_TO>" (optional),
"enable_share_button": "<true|false>" (default false),
}
Parameter | Description |
---|---|
| Type of button. Must be |
| Button title. 20 character limit. |
| This URL is opened in a mobile browser when the button is tapped. Must use HTTPS protocol. |
| Optional. Height of the Webview. Valid values: |
| The URL to use on clients that don't support Messenger Extensions. If this is not defined, the |
| Optional. Set to |