The media template allows you to send images, GIFs, and video as a structured message with an optional button. Videos and animated GIFs sent with the media template are playable in the conversation.
For media templates you must either:
attachmentTo send a message with an attachment you must first upload your image/video using the attachment upload api. After successfully uploading an attachment that contains your image/video you should receive an attachment_id, record that and use in the payload below.
{
"message_id": "<MESSAGE_ID>",
"messenger_delivery_data": {
"subscription_token": "<SUBSCRIPTION_TOKEN>"
},
"message":{
"attachment": {
"type": "template",
"payload": {
"template_type": "media",
"elements": [
{
"media_type": "image",
"attachment_id": "<ATTACHMENT_ID>"
}
]
}
}
}
}
To get the Facebook URL for an image or video, do the following:
| Media Type | Media Source | URL Format |
|---|---|---|
Video | Facebook Page |
|
Video | Facebook Account |
|
Image | Facebook Page |
|
Image | Facebook Account |
|
After retrieving a valid facebook URL you can use it in the below payload.
{
"message_id": "<MESSAGE_ID>",
"messenger_delivery_data": {
"subscription_token": "<SUBSCRIPTION_TOKEN>"
},
"message":{
"attachment": {
"type": "template",
"payload": {
"template_type": "media",
"elements": [
{
"media_type": "image",
"url": "<FACEBOOK_URL>"
}
]
}
}
}
}
Optionally, buttons may also be attached to the media template. You can add up to 3 buttons to a media template message, similar to generic template.
"elements": [
{
"media_type": "image",
"url": "<MEDIA_URL>",
"buttons": [
{
"type": "web_url",
"url": "<WEB_URL>",
"title": "View Website",
}
]
}
]