文档已更新。
中文(简体) 译文尚未完成。
英语更新时间:6月26日
中文(简体) 更新时间:1月3日

Button Template Reference

The button template allows you to send a structured message that includes text and buttons. For complete implementation details, see Button Template.

Request URI

https://graph.facebook.com/v21.0/me/messages?access_token={PAGE_ACCESS_TOKEN}

Example Request

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"{PSID}"
  },
  "message":{
    "attachment":{
      "type":"template",
      "payload":{
        "template_type":"button",
        "text":"What do you want to do next?",
        "buttons":[
          {
            "type":"web_url",
            "url":"https://www.messenger.com",
            "title":"Visit Messenger"
          }
        ]
      }
    }
  }
}' "https://graph.facebook.com/v21.0/me/messages?access_token={PAGE_ACCESS_TOKEN}"    

Example Response

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

Properties

recipient

Description of the message recipient. All requests must include one of the following properties to identify the recipient.

Property Type Description

recipient.id

String

Page Scoped User ID (PSID) of the message recipient. The user needs to have interacted with any of the Messenger entry points in order to opt-in into messaging with the Page. Note that Facebook Login integrations return user IDs are app-scoped and will not work with the Messenger platform.

recipient.user_ref

String

Used for the checkbox plugin and customer chat plugin.

recipient.post_id

String

Used for Private Replies to reference the visitor post to reply to.

recipient.comment_id

String

Used for Private Replies to reference the post comment to reply to.

message

Description of the message to be sent.
Property Type Description

message.attachment

Object

An object describing attachments to the message.

message.attachment

Property Type Description

type

String

Value must be template

payload

Object

模板的 payload

message.attachment.payload

Property Type Description

template_type

String

Value must be button

text

String

UTF-8-encoded text of up to 640 characters. Text will appear above the buttons.

buttons

Array<button>

Set of 1-3 buttons that appear as call-to-actions.