Message Templates

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.

Available Templates

The following templates are available for sending structured messages:

Request URI

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

Example Request

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

Example Response

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

Properties

recipient

Mô tả về người nhận tin nhắn. Tất cả yêu cầu phải bao gồm một trong các id, phone_number hoặc user_ref.

Thuộc tínhLoạiMô tả

recipient.id

Chuỗi

PSID, phone_number hoặc user_ref của người nhận tin nhắn.

recipient.phone_number

Chuỗi

Tùy chọn. Số điện thoại của người nhận có định dạng +1(212)555-2368.


Bot của bạn phải được phê duyệt cho tính năng Khớp khách hàng để gửi tin nhắn theo cách này.

recipient.user_ref

Chuỗi

Tùy chọn.user_ref từ plugin hộp kiểm.

recipient.name

Đối tượng

Tùy chọn. Chỉ sử dụng nếu đặt phone_number. Chỉ định tên của người dùng theo định dạng:


{"first_name":"John", "last_name":"Doe"}

Cung cấp tên sẽ giúp tăng tỷ lệ khớp thành công.

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 của mẫu.

message.attachment.payload

Property Type Description

template_type

String

Value indicating the template type generic, button, media, receipt, etc

...

Mixed

The rest of message.attachment.payload properties depend on the template type. See Available templates.