Media Template Reference

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.

Request URI

https://graph.facebook.com/v21.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>

Example Request

Send with Attachment ID

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>"

Send with Facebook URL

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>"

Example Response

{
  "recipient_id": "1254477777772919",
  "message_id": "AG5Hz2Uq7tuwNEhXfYYKj8mJEM_QPpz5jdCK48PnKAjSdjfipqxqMvK8ma6AC8fplwlqLP_5cgXIbu7I3rBN0P"
}  

Properties

recipient

메시지 받는 사람의 설명. 모든 요청에는 id, phone_number 또는 user_ref 중 하나가 포함되어야 합니다.

속성유형설명

recipient.id

문자열

메시지를 받는 사람의 PSID, phone_number 또는 user_ref.

recipient.phone_number

문자열

선택 사항. 받는 사람의 전화번호(형식: +1(212)555-2368).


이 방법으로 메시지를 보내려면 봇의 고객 매칭 기능 사용이 승인되어야 합니다.

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

Property Name Type Description

template_type

String

Value must be media

elements

Array<element>

An array containing 1 element object that describe the media in the message. A maximum of 1 element is supported.

sharable

Boolean

Optional. Set to true to enable the native share button in Messenger for the template message. Defaults to false.

message.attachment.payload.elements

Property Name Type Description

media_type

String

The type of media being sent - image or video is supported.

attachment_id

String

The attachment ID of the image or video. Cannot be used if url is set.

url

String

The URL of the image. Cannot be used if attachment_id is set.

buttons

Array

An array of button objects to be appended to the template. A maximum of 3 button is supported.

Error Codes

Error CodeDescription

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