Webhooks for WhatsApp Business Accounts

Bạn có thể nhận được thông báo trong thời gian thực khi Tài khoản WhatsApp Business (WABA) của mình có sự thay đổi bằng cách đăng ký ở cấp độ tài khoản WhatsApp Business. Cách thiết lập Webhooks cho tài khoản WhatsApp Business:

  1. Thiết lập điểm cuối của bạn và đặt cấu hình Webhooks. Quy trình này bao gồm các bước tương tự mà bạn dùng để thiết lập Webhooks cho Trang Facebook.
  2. Đăng ký ứng dụng của bạn trong tài khoản WhatsApp Business. Bạn phải đăng ký một ứng dụng thuộc sở hữu của doanh nghiệp mình. Các ứng dụng được chia sẻ với doanh nghiệp của bạn không thể nhận thông báo webhook.
  3. Đảm bảo ứng dụng của bạn đã hoàn tất quy trình Xét duyệt ứng dụng và đã yêu cầu quyền 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

Các trường đăng ký có sẵn

Tên trường Mô tả

account_review_update

Hệ thống gửi thông báo cho bạn khi một Tài khoản WhatsApp Business đã được xét duyệt.

account_update

Hệ thống gửi thông báo cho bạn khi có thay đổi đối với Tài khoản WhatsApp Business của bạn. Thay đổi này có thể bao gồm cập nhật về số điện thoại, lỗi vi phạm chính sách, Tài khoản WhatsApp Business bị cấm, v.v.

business_capability_update

Hệ thống gửi thông báo cho bạn khi một tính năng được cập nhật. Nội dung thông báo có thể bao gồm thay đổi về số lượng số điện thoại tối đa mà một WABA được phép có hoặc số cuộc trò chuyện trên mỗi số điện thoại.

message_template_status_update

Hệ thống gửi thông báo cho bạn khi mẫu tin nhắn đã được phê duyệt hoặc bị từ chối hay đã bị vô hiệu hóa.

messages

Hệ thống gửi thông báo cho bạn khi doanh nghiệp bạn nhận được tin nhắn của khách hàng, khi ban gửi tin nhắn cho khách hàng, khi tin nhắn được gửi thành công cho khách hàng và khi khách hàng đọc tin nhắn của bạn.

phone_number_name_update

Hệ thống gửi thông báo cho bạn khi tên liên kết với số điện thoại đã được phê duyệt hoặc bị từ chối.

phone_number_quality_update

Hệ thống gửi thông báo cho bạn khi có cập nhật về trạng thái liên quan đến chất lượng của một số điện thoại.

security

Hệ thống gửi thông báo cho bạn khi:

  • bạn yêu cầu vô hiệu hóa mã xác minh 2 bước
  • mã xác minh 2 bước bị vô hiệu hóa
  • mã xác minh 2 bước được cập nhật
  • Hãy truy cập Tài liệu tham khảo về Webhooks cho Tài khoản WhatsApp Business để biết thêm thông tin về từng trường phần tải dữ liệu và Tài liệu tham khảo về Webhooks cho API Đám mây của WhatsApp để biết thêm thông tin về các loại thông báo messages khác nhau mà bạn có thể nhận.

    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
                }
              }
            ]
          }
        ]
      }
    ]