通用範本參考資料

通用範本可讓您傳送結構化訊息,並在其中加入圖片、文字和按鈕。elements 陣列中所述的通用範本附有多個範本,其將會傳送可水平捲動的輪播項目,而每個項目都會含有圖片、文字和按鈕。如需完整的執行說明,請參閱通用範本

內容

要求獲取 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":"generic",
        "elements":[
           {
            "title":"Welcome!",
            "image_url":"https://petersfancybrownhats.com/company_image.png",
            "subtitle":"We have the right hat for everyone.",
            "default_action": {
              "type": "web_url",
              "url": "https://petersfancybrownhats.com/view?item=103",
              "messenger_extensions": false,
              "webview_height_ratio": "tall",
              "fallback_url": "https://petersfancybrownhats.com/"
            },
            "buttons":[
              {
                "type":"web_url",
                "url":"https://petersfancybrownhats.com",
                "title":"View Website"
              },{
                "type":"postback",
                "title":"Start Chatting",
                "payload":"DEVELOPER_DEFINED_PAYLOAD"
              }              
            ]      
          }
        ]
      }
    }
  }
}' "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

字串

值必須為 generic

elements

陣列 <element>

此陣列包含 1 個用以描述訊息中媒體的 element 物件。最多支援 1 個素材。

sharable

布林值

此為選填欄位。設為 true 即可在 Messenger 中為範本訊息啟用原生分享按鈕。預設為 false

message.attachment.payload.elements

通用範本的每個訊息最多支援 10 個素材。除了 title 之外,還必須設定最少一項屬性。

屬性名稱 類型 說明

title

字串

範本中顯示的標題。80 個字元限制。

subtitle

字串

此為選填欄位。範本中顯示的子標題。80 個字元限制。

image_url

字串

此為選填欄位。範本中顯示的圖片的網址。

default_action

物件

此為選填欄位。點按範本後執行的預設動作。接受與網址按鈕一樣的屬性;title 除外。

buttons

Array<button>

此為選填欄位。要附加至範本的按鈕陣列。每個素材最多支援 3 個按鈕。