Buttons

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.

Example Request

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"

Example Response

{
  "recipient_id": "1254477777772919",
  "message_id": "AG5Hz2Uq7tuwNEhXfYYKj8mJEM_QPpz5jdCK48PnKAjSdjfipqxqMvK8ma6AC8fplwlqLP_5cgXIbu7I3rBN0P"
}  

Buttons Types

URL Button

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 Extensions SDK - Required Domain Whitelisting

Для отображения веб-страницы с включенным SDK расширений Messenger в режиме веб-просмотра Messenger необходимо занести домен (включая субдомен) в белый список в свойстве whitelisted_domains профиля Messenger вашего бота. Благодаря этому доступ к данным пользователя через функции SDK будет только у доверенных доменов.

Дополнительные сведения о занесении доменов в белый список см. в справке по whitelisted_domains.

URL Button Payload

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

URL Parameters

ParametersDescription

type

string

Type of button. Must be web_url.

title

string

Button title. 20 character limit.

url

string

This URL is opened in a mobile browser when the button is tapped. Must use HTTPS protocol if messenger_extensions is true.

webview_height_ratio

string

Optional. Height of the Webview. Valid values: compact, tall, full. Defaults to full.

messenger_extensions

boolean

Optional. Must be true if using Messenger Extensions.

fallback_url

string

The URL to use on clients that don't support Messenger Extensions. If this is not defined, the url will be used as the fallback. It may only be specified if messenger_extensions is true.

webview_share_button

string

Optional. Set to hide to disable the share button in the Webview (for sensitive info). This does not affect any shares initiated by the developer using Extensions.

Postback Button

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.

Postback Button Payload

{
  "type":"postback",
  "title":"Postback Button",
  "payload":"DEVELOPER_DEFINED_PAYLOAD"
}

Postback Parameters

Parameters Description

type

string

Type of button. Must be postback.

title

string

Button title. 20 character limit.

payload

string

This data will be sent back to your webhook. 1000 character limit.

Call Button

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.

Call Button Payload

{
  "type":"phone_number",
  "title":"<BUTTON_TEXT>",
  "payload":"<PHONE_NUMBER>"
}

Call Parameter

Parameter Description

type

string

Type of button. Must be phone_number.

title

string

Button title, 20 character limit.

payload

string

Format must have "+" prefix followed by the country code, area code and local number. For example, +16505551234.

Game Play Button

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.

Game Play Button Payload

{
  "type":"game_play",
  "title":"Play",
  "payload":"{

Game Play Parameters

Property Description

type

string

Type of button. Must be game_play.

title

string

Button title, e.g. "Play".

payload

string

Optional. This data will be sent to the game.

game_metadata

object

Optional. Parameters specific to Instant Games. By providing the optional game_metadata, you can trigger the game to be started against a specific player_id or in a specific context_id.

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.

Log In Button

The log in button triggers the account linking authentication flow.

For more information on using the log in button, see Log In Button.

Log In Button Payload

...
    
"buttons":[
  {
    "type": "account_link",
    "url": "https://www.example.com/authorize"
  }
]

...

Log In Parameters

Parameter Description

type

string

Must be account_link.

url

string

Authentication callback URL. Must use HTTPS protocol.

Log Out Button Overview

The log out button triggers the account unlinking flow.

For more information on using the log out button, see Log Out Button.

Log Out Button Payload

{
  "type": "account_unlink"
}

Log Out Parameters

Parameter Description

type

string

Must be account_unlink

Extension Button

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.

Facebook Extensions SDK - Required Domain Whitelisting

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.

Extension Button Payload

{
  "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),
}

Extension Parameters

Parameter Description

type

string

Type of button. Must be extension.

title

string

Button title. 20 character limit.

url

string

This URL is opened in a mobile browser when the button is tapped. Must use HTTPS protocol.

webview_height_ratio

string

Optional. Height of the Webview. Valid values: compact, tall, full. Defaults to full.

fallback_url

string

The URL to use on clients that don't support Messenger Extensions. If this is not defined, the url will be used as the fallback. It may only be specified if messenger_extensions is true.

enable_share_button

string

Optional. Set to true to enable the share button in the Webview (for sensitive info). This does not affect any shares initiated by the developer using Extensions.