Slack用WhatsApp通知サブスクリプションの作成

このコード・スニペットは WhatsApp ビジネスアカウント通知 スラックを通じて。

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

キー説明
VONAGE_API_KEY

Your Vonage API key (see it on your dashboard).

VONAGE_API_SECRET

Your Vonage API secret (also available on your dashboard).

CHANNEL_MANAGER_WHATSAPP_NOTIFICATION_WEBHOOK_URL_SLACK

An incoming webhook URL created for your Slack workspace. Please refer to the Slack webhook documentation for more information on how to configure this URL.

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 create-notification-webhook-slack-url.sh:

curl -X POST https://api.nexmo.com/v2/whatsapp-manager/subscriptions \
  -u "${VONAGE_API_KEY}:${VONAGE_API_SECRET}" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
    "type": "slack",
    "slack": {
      "url": "'${CHANNEL_MANAGER_WHATSAPP_NOTIFICATION_WEBHOOK_URL_SLACK}'"
    }
  }'

View full source

Run your code

Save this file to your machine and run it:

bash create-notification-webhook-slack-url.sh

試してみる

コードを実行すると、WhatsAppビジネスアカウントに変更があった場合、Slackチャンネルに通知が届きます。