Webhooks for WhatsApp Business Accounts

WhatsApp Businessアカウントレベルでサブスクリプション登録することによりWhatsApp Businessアカウント(WABA)に変更が加えられた時点で、リアルタイムの通知を受け取ることができます。WhatsApp BusinessアカウントのWebhooksを設定するには、次のようにします。

  1. エンドポイントを設定し、Webhooksを構成します。これは、FacebookページにWebhooksを設定するための手順と同じです。
  2. WhatsApp Businessアカウントの下で該当アプリをサブスクリプション登録します。サブスクリプション登録するのは、自分のビジネスの所有するアプリでなければなりません。自分のビジネスと共有しているアプリは、Webhook通知を受け取ることができません。
  3. 該当アプリのアプリレビューが完了しており、whatsapp_business_managementアクセス許可をリクエスト済みであることを確認してください。

GET, POST, and DELETE calls to /{whats-app-business-account-id}/subscribed_apps are now subject to Business Use Case Rate Limits.

Set up Your Endpoint and Webhooks

Follow our Webhooks Getting Started guide to create your endpoint and configure your webhook endpoint. When you configure your endpoint, make sure to choose WhatsApp Business Account and subscribe to individual WhatsApp Business Account (WABA) fields.

Available Subscription Fields

サブスクリプションできるフィールド

フィールド名 説明

account_review_update

WhatsApp Businessアカウントの審査が完了すると通知が届きます。

account_update

WhatsApp Businessアカウントが変更されると通知が届きます。電話番号が更新された、ポリシー違反が発生した、WhatsApp Businessアカウントがブロックされた場合などが該当します。

business_capability_update

機能が更新された場合に通知が届きます。WABAが持ちうる電話番号の最大数や、電話番号あたりのスレッド数が変更された場合などが該当します。

message_template_status_update

メッセージテンプレートが承認されたか却下された場合、または無効化された場合に通知が届きます。

messages

ビジネスが顧客からメッセージを受け取った時、顧客にメッセージを送った時、顧客にメッセージが配信された時、顧客がメッセージを読んだ時に、通知が届きます。

phone_number_name_update

電話番号に関連付けられている名前が承認されたか却下された場合に通知が届きます。

phone_number_quality_update

電話番号のクオリティ関連のステータスが変わると通知が届きます。

security

以下の場合に通知が届きます。

  • 2段階認証コードの無効化をリクエストした
  • 2段階認証コードが無効化された
  • 2段階認証コードが更新された
  • 各ペイロードフィールドの詳細については WhatsApp BusinessアカウントのWebhooksリファレンスを、受信可能な各種messages通知の詳細については WhatsAppクラウドAPIのWebhooksリファレンスをご覧ください。

    Subscribe Your App

    You need to subscribe your app to webhooks on a given WABA. We only send notifications if your webhooks-configured app is subscribed to webhooks on a given WABA, and only if the app has permission to edit that WABA.

    Create a Subscription

    Request

    To subscribe your app to webhooks on a WABA, send a POST request to the WABA > Subscribed Apps endpoint.

    curl -X POST 'https://graph.facebook.com/<API_VERSION>/<WHATSAPP_BUSINESS_ACCOUNT_ID>/subscribed_apps' \
    -H 'Authorization: Bearer <ACCESS_TOKEN>'

    Response

    Upon success:

    {
      "success": "true"
    }
    

    Get Subscribed Apps

    To get a list of apps subscribed to webhooks on a WABA, send a GET request to the WABA > Subscribed Apps endpoint.

    Request

    curl 'https://graph.facebook.com/<API_VERSION>/<WHATSAPP_BUSINESS_ACCOUNT_ID>/subscribed_apps' \
    -H 'Authorization: Bearer <ACCESS_TOKEN>'

    Response

    A successful response will list the subscribed apps:

    {
      "data": [
        {
          "whatsapp_business_api_data": {
            "link": "<APP_1_URL>",
            "name": "<APP_1_NAME>",
            "id": "<APP_1_ID>"
          }
        },
        {
          "whatsapp_business_api_data": {
            "link": "<APP_2_URL>",
            "name": "<APP_2_NAME>",
            "id": "<APP_2_ID>"
          }
        },
        ...
      ]
    }

    Delete a subscription

    To unsubscribe your app from webhooks on a WABA, send a DELETE request to the subscribed_apps endpoint.

    Request

    curl -X DELETE 'https://graph.facebook.com/<AP_VERSION>/<WHATSAPP_BUSINESS_ACCOUNT_ID>/subscribed_apps' \
    -H 'Authorization: Bearer <ACCESS_TOKEN>'

    Response

    A successful response will read:

    {
      "success": "true"
    }
    

    Subscribe with Graph API Explorer

    If you don't want to subscribe your app with direct API calls, you can easily do it with Graph API Explorer.

    Replace the me?fields=id,name query with <WHATSAPP_BUSINESS_ACCT_ID>/subscribed_apps. It will subscribe the app you use to send the POST request in Graph Explorer.

    Your app must have permission to edit the WhatsApp business account in order to successfully subscribe.

    Example Webhook payload:

    [
      {
        "object": "whatsapp_business_account",
        "entry": [
          {
            "id": "0",
            "time": 1602782939,
            "changes": [
              {
                "field": "phone_number_name_update",
                "value": {
                  "display_phone_number": "16505551111",
                  "decision": "APPROVED",
                  "requested_verified_name": "WhatsApp",
                  "rejection_reason": null
                }
              }
            ]
          }
        ]
      }
    ]