按钮模板参考文档

通过按钮模板,您可以发送包含文本和按钮的结构化消息。如需获取完整的实现详情,请参阅按钮模板

目录

请求 URI

https://graph.facebook.com/v19.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>

请求示例

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/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"

响应示例

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

属性

recipient

对消息接收人的说明。所有请求都必须包含下列任一属性:idphone_numberuser_ref

属性类型说明

recipient.id

字符串

消息接收人的 PSIDphone_numberuser_ref

recipient.phone_number

字符串

可选。 收件人的手机号码,格式为:+1(212)555-2368


您的智能助手必须获准使用客户匹配,才能通过这种方式发送消息。

recipient.user_ref

字符串

可选。复选框插件提供的 user_ref

recipient.name

对象

可选。 仅在设置了 phone_number 的情况下使用。以如下格式指定用户姓名:


{"first_name":"John", "last_name":"Doe"}

提供姓名可提高匹配成功的几率。

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

属性 类型 描述

template_type

字符串

值必须为 button

text

字符串

经 UTF-8 编码的文本,不超过 640 个字符。文本将显示在按钮上方。

buttons

Array<button>

一组按钮(数量为 1 至 3 个),这些按钮会显示为行动号召。