Message templates offer a way for you to offer a richer in-conversation experience than standard text messages by integrating buttons, images, lists, and more alongside text a single message. Templates can be use for many purposes, such as displaying product information, asking the message recipient to choose from a pre-determined set of options, and showing search results.
The following templates are available for sending structured messages:
https://graph.facebook.com/v21.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
訊息收件人的說明。所有的要求都必須包含 id
、phone_number
或 user_ref
。
屬性 | 型別 | 說明 |
---|---|---|
| 字串 | 訊息收件人的 |
| 字串 | 選用。 收件人的電話號碼(格式為 +1(212)555-2368)。 您的 Bot 必須獲准使用顧客配對功能,才能透過此方式傳送訊息。 |
| 字串 | 選用。來自核取方塊外掛程式的 |
| 物件 | 選用。 只有設定 {"first_name":"John", "last_name":"Doe"} 提供姓名會提高成功配對的機會。 |
message
Property | Type | Description |
---|---|---|
| Object | An object describing attachments to the message. |
message.attachment
Property | Type | Description |
---|---|---|
| String | Value must be |
| Object | 範本的 |
message.attachment.payload
Property | Type | Description |
---|---|---|
| String | Value indicating the template type |
| Mixed | The rest of |