Facebook media templates allows your business to send images, GIFs and videos as structured messages with an optional button.
Facebook Messenger supports only images and video for media templates. Audio isn't supported at the moment.
In order to send a media template with a URL button, you can use any of the endpoints for sending messages in Conversations API with the message type facebookMediaTemplate. The example below illustrates how to send it using the endpoint POST /v1/send.
curl -X "POST" "https://conversations.messagebird.com/v1/send" \-H 'Authorization: AccessKey {your-access-key}' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"content": {"facebookMediaTemplate": {"attachment": {"type": "template","payload": {"template_type": "media","elements": [{"media_url": "https://www.yourcompany.com/image.png","buttons": [{"type": "web_url","url": "https://www.yourcompany.com","title": "Visit website"}],"media_type": "image"}]}}}},"to": "4190117307726093","type": "facebookMediaTemplate","from": "99d0e570cd834661a1771ab08044be8b"}'
The message sent by the previous code snippet looks like the following.
The message looks like the following in Conversations API.
{"id": "8a7e47cf40cc472b8141ca4f033f361a","conversationId": "6279c2012f7d4df393cfa1f872518518","platform": "facebook","to": "4190117307726093","from": "101397625015964","channelId": "99d0e570cd834661a1771ab08044be8b","type": "facebookMediaTemplate","content": {"facebookMediaTemplate": {"attachment": {"type": "template","payload": {"template_type": "media","elements": [{"media_type": "image","attachment_id": "531649808135398","media_url": "https://www.yourcompany.com/image.png","buttons": [{"type": "web_url","url": "https://www.yourcompany.com","title": "Visit website"}]}]}}}},"direction": "sent","status": "sent","createdDatetime": "2022-02-15T16:15:35.576027239Z","updatedDatetime": "2022-02-15T16:15:35.576027239Z"}
In order to send a media template with a call button, you can use any of the endpoints for sending messages in Conversations API with the message type facebookMediaTemplate. The example below illustrates how to send it using the endpoint POST /v1/send.
curl -X "POST" "https://conversations.messagebird.com/v1/send" \-H 'Authorization: AccessKey {your-access-key}' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"content": {"facebookMediaTemplate": {"attachment": {"type": "template","payload": {"template_type": "media","elements": [{"media_url": "https://www.yourcompany.com/image.png","buttons": [{"type": "phone_number","payload": "+31000000000","title": "Call us!"}],"media_type": "image"}]}}}},"to": "4190117307726093","type": "facebookMediaTemplate","from": "99d0e570cd834661a1771ab08044be8b"}'
The message sent by the previous code snippet looks like the following.
The message looks like the following in Conversations API.
{"id": "7e57780ce09f4bada118257113bc610a","conversationId": "6279c2012f7d4df393cfa1f872518518","platform": "facebook","to": "4190117307726093","from": "101397625015964","channelId": "99d0e570cd834661a1771ab08044be8b","type": "facebookMediaTemplate","content": {"facebookMediaTemplate": {"attachment": {"type": "template","payload": {"template_type": "media","elements": [{"media_type": "image","attachment_id": "212930650994208","media_url": "https://www.yourcompany.com/image.png","buttons": [{"type": "phone_number","title": "Call us!","payload": "+31000000000"}]}]}}}},"direction": "sent","status": "sent","createdDatetime": "2022-02-15T16:42:35.478886849Z","updatedDatetime": "2022-02-15T16:42:35.478886849Z"}
In order to send a media template with a custom button, you can use any of the endpoints for sending messages in Conversations API with the message type facebookMediaTemplate. The example below illustrates how to send it using the endpoint POST /v1/send.
curl -X "POST" "https://conversations.messagebird.com/v1/send" \-H 'Authorization: AccessKey {your-access-key}' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"content": {"facebookMediaTemplate": {"attachment": {"type": "template","payload": {"template_type": "media","elements": [{"media_url": "https://www.yourcompany.com/image.png","buttons": [{"type": "postback","payload": "custom-value","title": "Click here"}],"media_type": "image"}]}}}},"to": "4190117307726093","type": "facebookMediaTemplate","from": "99d0e570cd834661a1771ab08044be8b"}'
The message sent by the previous code snippet looks like the following.
The message looks like the following in Conversations API.
{"id": "5e7ce3d1058e4460ac1e801b69203d27","conversationId": "6279c2012f7d4df393cfa1f872518518","platform": "facebook","to": "4190117307726093","from": "101397625015964","channelId": "99d0e570cd834661a1771ab08044be8b","type": "facebookMediaTemplate","content": {"facebookMediaTemplate": {"attachment": {"type": "template","payload": {"template_type": "media","elements": [{"media_type": "image","attachment_id": "628162978478942","media_url": "https://www.yourcompany.com/image.png","buttons": [{"type": "postback","title": "Click here","payload": "custom-value"}]}]}}}},"direction": "sent","status": "sent","createdDatetime": "2022-02-15T16:58:13.042419184Z","updatedDatetime": "2022-02-15T16:58:13.042419184Z"}
When the recipient clicks the button, this is how the FacebookPostback inbound message looks like in Conversations API.
{"id": "9fca85766f8d4940a33c28ce33e8960e","conversationId": "6279c2012f7d4df393cfa1f872518518","platform": "facebook","to": "101397625015964","from": "4190117307726093","channelId": "99d0e570cd834661a1771ab08044be8b","type": "facebookPostback","content": {"facebookPostback": {"title": "Click here","payload": "custom-value"}},"direction": "received","status": "received","createdDatetime": "2022-02-15T17:12:13.322Z","updatedDatetime": "2022-02-15T17:12:13.322Z"}
Note that the FacebookPostback inbound message contains the button label in content.facebookPostback.title and the custom value set in the content.facebookPostback.payload.