按鈕範本參考資料

按鈕範本可讓您傳送包含文字和按鈕的結構化訊息。若要瞭解完整實作方式的詳細資料,請參閱按鈕型範本

內容

要求 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)。


您的 Bot 必須獲准使用顧客配對功能,才能透過此方式傳送訊息。

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

字串

最多 640 個 UTF-8 編碼字元。文字會顯示在按鈕上方。

buttons

陣列<button>

顯示為行動呼籲的一組 1 到 3 個按鈕