汎用テンプレートのリファレンス

汎用テンプレートを使用すると、画像、テキスト、ボタンを含む構造化メッセージを送信できます。elements配列に複数のテンプレートを記述した汎用テンプレートは、複数の項目(それぞれが画像、テキスト、ボタンで構成されている)の水平スクロールが可能なカルーセルを送信します。実装について詳しくは、汎用テンプレートをご覧ください。

目次

リクエストURI

https://graph.facebook.com/v19.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":"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>"

応答の例

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

プロパティ

recipient

メッセージ受信者の説明。すべてのリクエストには、idphone_numberuser_refのいずれを含める必要があります。

プロパティタイプ説明

recipient.id

文字列

メッセージ受信者のPSIDphone_numberuser_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

プロパティ名 説明

template_type

文字列

値はgenericにする必要があります

elements

element配列

メッセージ中のメディアについて説明する1つのelementオブジェクトを含む配列。最大1個のエレメントがサポートされます。

sharable

ブールアン

オプション。 テンプレートメッセージでMessengerのネイティブシェアボタンを有効にするには、trueに設定します。デフォルトはfalseです。

message.attachment.payload.elements

汎用テンプレートでは、メッセージごとに最大10個のエレメントがサポートされます。titleに加えて、少なくとも1つのプロパティを設定する必要があります。

プロパティ名 説明

title

文字列

テンプレートに表示するタイトル。最大80文字です。

subtitle

文字列

オプション。 テンプレートに表示するサブタイトル。最大80文字です。

image_url

文字列

オプション。 テンプレートに表示する画像のURL。

default_action

オブジェクト

オプション。 テンプレートがタップされたときに実行されるデフォルトアクション。URLボタンと同じプロパティ(titleを除く)を指定できます。

buttons

button配列

オプション。 テンプレートの末尾に追加するボタンの配列。エレメントごとに最大3個のボタンがサポートされます。