一般型範本參考資料

一般型範本可讓您傳送含有圖像、文字和按鈕的結構化訊息。在 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 個描述訊息中影音素材的元素物件。最多支援 1 個元素。

sharable

布林值

選用。設定為 true 可在 Messenger 中啟用範本訊息的原生分享按鈕。預設為 false

message.attachment.payload.elements

一般型範本支援每則訊息最多 10 個元素。除了 title 之外,還必須設定至少一個屬性。

屬性名稱 類型 說明

title

字串

顯示在範本中的標題。以 80 個字元為限。

subtitle

字串

選用。顯示在範本中的副標題。以 80 個字元為限。

image_url

字串

選用。顯示在範本中的圖像網址。

default_action

物件

選用。點按範本時所執行的預設動作。接受與「網址」按鈕相同的屬性,title 除外。

buttons

陣列 <button>

選用。附加於範本的按鈕陣列。支援每個元素最多 3 個按鈕。