インタラクティブメッセージテンプレートの送信

インタラクティブメッセージテンプレートが拡張され、標準メッセージテンプレートやメディアメッセージテンプレートタイプでは送信できないコンテンツを受信者に送信できるようになりました。componentsオブジェクトを使用して、インタラクティブボタンを含めることができます。

次の2つのタイプの事前定義ボタンがあります。

  • コールトゥアクション — カスタマーが電話をかけたり、ウェブサイトにアクセスしたりするために使います
  • クイック返信 — カスタマーがシンプルなテキストメッセージを返信するために使います

これらのボタンは、テキストメッセージやメディアメッセージに含めることができます。作成と認証が完了したインタラクティブメッセージテンプレートは、通知メッセージやカスタマーサービス/ケアのメッセージで使えます。

開始する前に

以下が必要です。

メッセージテンプレートが承認されると、APIを使ってメッセージを送信できます。

制約

  • コールトゥアクションテンプレートの場合、タイプ(電話をかける、ウェブサイトにアクセスする)ごとに1つずつ、最大2つまでボタンを追加できます。
  • クイック返信テンプレートの場合、最大3つまでボタンを追加できます。

ステップ1: /messagesPOSTリクエストを送信する

POST /v1/messages
{
    "to": "recipient_wa_id",
    "type": "template",
    "template": {
        "namespace": "your-namespace",
        "language": {
            "policy": "deterministic",
            "code": "your-language-and-locale-code"
        },
        "name": "your-template-name",
        "components": [
            {
                "type" : "header",
                "parameters": [
                    {
                        "type": "text",
                        "text": "replacement_text"
                    }
                ]
            # end header
            },
            {
                "type" : "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": "replacement_text"
                    },
                    {
                        "type": "currency",
                        "currency" : {
                            "fallback_value": "$100.99",
                            "code": "USD",
                            "amount_1000": 100990
                        }
                    },
                    {
                        "type": "date_time",
                        "date_time" : {
                            "fallback_value": "February 25, 1977",
                            "day_of_week": 5,
                            "day_of_month": 25,
                            "year": 1977,
                            "month": 2,
                            "hour": 15,
                            "minute": 33, #OR
                            "timestamp": 1485470276
                        }
                    },
                    {
                        ...
                        # Any additional template parameters
                    }
                ] 
            # end body
            },

            # The following part of this code example includes several possible button types, 
            # not all are required for an interactive message template API call.
            {
                "type": "button",
                "sub_type" : "quick_reply",
                "index": "0", 
                "parameters": [
                    {
                        "type": "payload",
                        # Business Developer-defined payload
                        "payload":"aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT"
                    }
                ]
            },
            {
                "type": "button",
                "sub_type" : "url",
                "index": "1", 
                "parameters": [
                    {
                        "type": "text",
                        # Business Developer-defined dynamic URL suffix
                        "text": "9rwnB8RbYmPF5t2Mn09x4h"
                    }
                ]
            },
            {
                "type": "button",
                "sub_type" : "url",
                "index": "2",
                "parameters": [
                    {                    
                        "type": "text",
                        # Business Developer-defined dynamic URL suffix
                        "text": "ticket.pdf"
                    }
                ]
            }
        ]
    }
}

パラメーター

ステップ2: API応答を確認する

成功した場合の応答には、idを含むmessagesオブジェクトが含まれます。

{
  "messages": [{
    "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU"
  }]
}

失敗した場合の応答には、エラー文字列、エラーコード、その他の情報を含むエラーオブジェクトが含まれます。

テンプレートを受信できないアカウントにテンプレートが送信された場合、構成済みのWebhookサーバーに、エラーオブジェクトとして1026 (ReceiverIncapable)エラーが送信されます。

エラーについて詳しくは、エラーコードとステータスコードをご覧ください。

オプションステップ3: ユーザーアクションの処理

ユーザーがクイック返信ボタンをクリックすると、ビジネスに返信が送られます。詳しくは、クイック返信ボタンのクリックによるコールバックをご覧ください。ユーザーは、ボタンをクリックする代わりに自由形式のメッセージを送信することもできます。

クイック返信ボタンのクリックによるコールバック

顧客が[クイック返信]ボタンをクリックすると、応答が送信されます。コールバックフォーマットの例を次に示します。注: 顧客がボタンをクリックせずに、インタラクティブメッセージに返信するか、単にメッセージを送信する場合もあります。このタイプのシナリオも十分サポートできるようにしてください。詳しくは、Webhooksに関するドキュメントもご覧ください。
{
    "contacts": [
        {
            "profile": {
                "name": "Kerry Fisher"
            },
            "wa_id": "16505551234"
        }
    ],
    "messages": [
        {
            "button": {
                "payload": "No-Button-Payload",
                "text": "No"
            },
            "context": {
                "from": "16315558007",
                "id": "gBGGFmkiWVVPAgkgQkwi7IORac0"
            },
            "from": "16505551234",
            "id": "ABGGFmkiWVVPAgo-sKD87hgxPHdF",
            "timestamp": "1591210827",
            "type": "button"
        }
    ]
    # If there are any errors, an errors field (array) will be present        
    "errors": [ { ... } ]
}

以下は、インタラクティブメッセージテンプレートの設定プロセスを示す例です。まず、ビジネスマネージャでテンプレートを作成し、messagesエンドポイントへのAPI呼び出しによって作成したメッセージテンプレートを送信します。

旅行のリマインダー

この例では、クイック返信ボタン付きのインタラクティブメディアメッセージテンプレートの作成について示します。

1. ビジネスマネージャでインタラクティブメディアメッセージテンプレートを作成します。

2. パラメーター情報としてmessages API呼び出しを追加します。

POST /v1/messages
{
    "to": "your-test-recipient-wa-id",
    "recipient_type": "individual",
    "type": "template",
    "template": {
        "namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2",
        "name": "upcoming_trip_reminder",
        "language": {
            "code": "en",
            "policy": "deterministic"
        },
        "components": [
            {
                "type": "header",
                "parameters": [
                    {
                        "type": "text",
                        "text": "12/26"
                    }
                ]
            },
            {
                "type": "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": "*Ski Trip*"
                    },
                    {
                        "type": "date_time",
                        "date_time" : {
                            "fallback_value": "29th July 2019, 8:00am",
                            "day_of_month": "29",
                            "year": "2019",
                            "month": "7",
                            "hour": "8",
                            "minute": "00"
                        }
                    },
                    {
                            "type": "text",
                            "text": "*Squaw Valley Ski Resort, Tahoe*"
                    }
                ]
            },
            {
                "type": "button",
                "sub_type": "quick_reply",
                "index": 0,
                "parameters": [
                    {
                        "type": "payload",
                        "payload": "Yes-Button-Payload"
                    }
                ]
            },
            {
                "type": "button",
                "sub_type": "quick_reply",
                "index": 1,
                "parameters": [
                    {
                        "type": "payload",
                        "payload": "No-Button-Payload"
                    }
                ]
            }
        ]
    }
}

3. カスタマーが、クイック返信ボタン付きの旅行のリマインダーメッセージを受け取ります。

商品の発送

この例では、URLボタンと電話番号ボタン付きのインタラクティブメディアメッセージテンプレートの作成について示します。

1. ビジネスマネージャでインタラクティブメディアメッセージテンプレートを作成します。

2. パラメーター情報としてmessages API呼び出しを追加します。

POST /v1/messages
{
    "to": "your-test-recipient-wa-id",
    "recipient_type": "individual",
    "type": "template",
    "template": {
        "namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2",
        "name": "oculus_shipment_update",
        "language": {
            "code": "en",
            "policy": "deterministic"
        },
        "components": [
            {
                "type": "header",
                "parameters": [{
                    "type": "image",
                    "image": {
                        "link": "link-to-your-image"
                    }
                }]
            },
            {
                "type": "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": "Anand"
                    },
                    {
                        "type": "text",
                        "text": "Quest"
                    },
                    {
                        "type": "text",
                        "text": "113-0921387"
                    },
                    {
                        "type": "date_time",
                        "date_time" : {
                            "fallback_value": "23rd Nov 2019",
                            "day_of_month": "20",
                            "year": "2019",
                            "month": "9"
                        }
                    }
                ] 
            },
            {
                "type": "button",
                "index": "0",
                "sub_type": "url",
                "parameters": [
                    {
                        "type": "text",
                        "text": "1Z999AA10123456784"
                    }
                ]
            }
        ]
    }
}

3. カスタマーは、URLボタンと電話番号ボタン付きの商品発送メッセージを受け取ります。