The media template allows you to send a structured message that includes an image or video, and an optional button. For complete implementation details, see Media Template.
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": "media",
"elements": [
{
"media_type": "<image|video>",
"attachment_id": "<ATTACHMENT_ID>"
}
]
}
}
}
}' "https://graph.facebook.com/v2.6/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": "media",
"elements": [
{
"media_type": "<image|video>",
"url": "<FACEBOOK_URL>"
}
]
}
}
}
}' "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 Name | Type | Description |
---|---|---|
| String | Value must be |
| Array< | An array containing 1 element object that describe the media in the message. A maximum of 1 element is supported. |
| Boolean | Optional. Set to |
message.attachment.payload.elements
Property Name | Type | Description |
---|---|---|
| String | The type of media being sent - |
| String | The attachment ID of the image or video. Cannot be used if |
| String | The URL of the image. Cannot be used if |
| Array | An array of button objects to be appended to the template. A maximum of 3 button is supported. |
Error Code | Description |
---|---|
2018173 | Failed to generate preview url |
2018175 | Media Preview Failed |
2018182 | Media Type not valid |
2018183 | Attachment Id is missing |
2018184 | Media Template Facebook Media URL Is Not Supported |
2018185 | Non facebook url in url param |
2018186 | Unable to get photo or video from facebook url |
2018187 | Either URL or attachment id is required |
2018188 | External URL is not supported |