カスタムオブジェクト

Messages APIにはカスタムオブジェクトという概念があります。カスタムオブジェクトを使用すると、Facebook Messenger、WhatsApp、Viber など、サポートされているメッセージングプラットフォームの高度な機能を活用できます。

カスタム・オブジェクトは、基盤となるメッセージング・プラットフォームのAPIリクエスト・フォーマットの一部分を受け取り、そのプラットフォームに直接送信する。

WhatsAppを例に、Messages APIコールを説明する:

{
  "to": "447700900000",
  "from": "447700900001",
  "channel": "whatsapp",
  "message_type": "custom",
  "custom": {$CUSTOM_OBJECT}
}

VonageはWhatsAppに次のように送信する:

{
  "recipient_type": "individual",
  "to": "$TO_NUMBER",
  {$CUSTOM_OBJECT}
}

のJSONは CUSTOM_OBJECT は、メッセージングプラットフォームのリクエストタイプに応じたフォーマットに依存します。

もしWhatsAppのリクエストが

{
  "recipient_type": "individual",
  "to": "447700900000",
  "type": "template",
  "template": {
    "namespace": "whatsapp:hsm:technology:nexmo",
    "name": "parcel_location",
    "language": {
      "policy": "deterministic",
      "code": "en"
    },
    "components": [
      {
        "type": "location",
        "location": {
          "longitude": -122.425332,
          "latitude": 37.758056,
          "name": "Facebook HQ",
          "address": "1 Hacker Way, Menlo Park, CA 94025"
        }
      },
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "Value 1"
          },
          {
            "type": "text",
            "text": "Value 2"
          },
          {
            "type": "text",
            "text": "Value 3"
          }
        ]
      }
    ]
  }
}

Messages APIリクエストのフォーマットは以下のようになる:

{
  "to": "447700900000",
  "from": "447700900001",
  "channel": "whatsapp",
  "message_type": "custom",
  "custom": {
    "type": "template",
    "template": {
      "namespace": "whatsapp:hsm:technology:nexmo",
      "name": "parcel_location",
      "language": {
        "policy": "deterministic",
        "code": "en"
      },
      "components": [
        {
          "type": "header",
          "parameters": [
            {
              "type": "location",
              "location": {
                "longitude": -122.425332,
                "latitude": 37.758056,
                "name": "Facebook HQ",
                "address": "1 Hacker Way, Menlo Park, CA 94025"
              }
            }
          ]
        },
        {
          "type": "body",
          "parameters": [
            {
              "type": "text",
              "text": "Value 1"
            },
            {
              "type": "text",
              "text": "Value 2"
            },
            {
              "type": "text",
              "text": "Value 3"
            }
          ]
        }
      ]
    }
  }
}

カスタムオブジェクト、 CUSTOM_OBJECTオリジナルのリクエスト・フォーマットで定義されている

  "type": "template",
  "template": {
    "namespace": "whatsapp:hsm:technology:nexmo",
    "name": "parcel_location",
    "language": {
      "policy": "deterministic",
      "code": "en"
    },
    "components": [
      {
        "type": "location",
        "location": {
          "longitude": -122.425332,
          "latitude": 37.758056,
          "name": "Facebook HQ",
          "address": "1 Hacker Way, Menlo Park, CA 94025"
        }
      },
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "Value 1"
          },
          {
            "type": "text",
            "text": "Value 2"
          }
        ]
      }
    ]
  }

ということに注意してほしい。 カスタムオブジェクトを使用する場合例えば、WhatsAppのメッセージフォーマットでは、言語コードの形式はターゲットプラットフォームと一致していなければならない。例えば、WhatsAppのメッセージフォーマットでは言語コードは以下のような形式です en_GBではない。 en-GB.

Facebookメッセンジャーのメッセージテンプレート

カスタムオブジェクトはFacebook Messengerメッセージテンプレートの送信に使用できます。例えば

{
  "to": $FB_RECIPIENT_ID,
  "from": $FB_SENDER_ID,
  "channel": "messenger",
  "message_type": "custom",
  "custom": {$CUSTOM_OBJECT}
}

Messages APIメッセージは以下のように変換される:

{
  "recipient":{
    "id":"<PSID>"
  },
  "message":{
    $CUSTOM_OBJECT
  }
}

カスタムオブジェクトの場所、 $CUSTOM_OBJECTの中にあるものであれば何でもよい。 メッセンジャー・メッセージ・オブジェクト.

他の例を見る