ステッカーURLを使ってステッカーを送る

このコードスニペットでは URL を使って WhatsApp にステッカーを送信する方法を説明します。詳しくは WhatsApp ステッカーの使用 このコード・スニペットを使用する際の詳細については、こちらをご覧ください。

各コード・スニペットで使用されているすべての変数の説明を以下に示します:

キー説明
JWT

Used to authenticate your request. See Authentication for more information, including how to generate a JWT.

STICKER_URL

The publicly accessible URL of the sticker image. Supported types are .webp.

TO_NUMBER

The number you are sending the to in E.164 format. For example 447700900000.

WHATSAPP_NUMBER

The WhatsApp number that has been allocated to you by Vonage. For sandbox testing the number is 14157386102.

注: 先頭の + または 00 電話番号を入力する場合は、447700900000のように国番号から入力してください。

Prerequisites

If you do not have an application you can create one. Make sure you also configure your webhooks.

Write the code

Add the following to send-sticker-url.sh:

curl -X POST "${MESSAGES_API_URL}" \
  -H "Authorization: Bearer "$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
    "to": "'${MESSAGES_TO_NUMBER}'",
    "from": "'${WHATSAPP_SENDER_ID}'",
    "channel": "whatsapp",
    "message_type": "sticker",
    "sticker": {
      "url": "'${WHATSAPP_STICKER_URL}'"
    }
  }'

View full source

Run your code

Save this file to your machine and run it:

bash send-sticker-url.sh

試してみる

コードを実行すると、WhatsAppステッカーが相手先の番号に送信されます。

詳細情報