# Webhook events

> `event` is the string in the envelope and in `X-Vitral-WhatsApp-Event`.

Examples use placeholder ids. Meta may add fields. Do not require a field this page does not list, except where the example is the exact object this API builds.

Every delivery produced by the webhook processor adds these envelope fields. They are `null` when the phone or customer is not known. Nothing that was already on the payload is removed.

| Field | Meaning |
| --- | --- |
| `customerId` | Customer that owns the phone, when `PhoneNumber.customerId` is set. If that column is null, the newest setup link’s customer is used. |
| `phoneNumberId` | Whitelabel WhatsApp Cloud API phone id, not Meta’s `phone_number_id`. |
| `setupLinkId` | Newest setup link stored for that phone, or `null`. |
| `customers` | Present only when the event names more than one Whitelabel WhatsApp Cloud API phone. Each item has `customerId`, `phoneNumberId`, and `setupLinkId`. |

The same `customerId` is copied onto `data` when `data` does not already have that key. `phoneNumberId` and `setupLinkId` are copied onto `data` only when this API knows them and the key is absent. `referral.received` already has `phoneNumberId`; that value is left as-is. On `phone.disconnected` and resolved `account.update`, each object in `data.phones` gains `customerId` and, when known, `setupLinkId`.

`setup_link.completed`, `setup_link.failed`, and `setup_link.expired` are emitted by setup itself, not by the Meta processor. They use the same signing header, delivery row, and retry queue as other events. Each outcome is stored once per setup link, so a repeat of the same outcome does not send a second delivery. A link can send `failed` and later `completed`. No webhook URL skips enqueue and keeps that claim. An open circuit still enqueues, because these outcomes are not replayed by Meta; the delivery worker retries them. A failed enqueue releases the claim and is tried again up to three times.

## setup_link.completed

Embedded Signup finished and the phone was stored on the customer.

```json
{
  "event": "setup_link.completed",
  "tenantId": "ck_tenant",
  "timestamp": "2026-09-30T16:00:00.000Z",
  "customerId": "ck_customer",
  "phoneNumberId": "ck_phone",
  "setupLinkId": "ck_setup_link",
  "data": {
    "setupLinkId": "ck_setup_link",
    "customerId": "ck_customer",
    "externalCustomerId": "cust_123",
    "phoneNumberId": "ck_phone",
    "waPhoneNumberId": "META_PHONE_ID",
    "wabaId": "WABA_ID",
    "displayPhoneNumber": "525512345678",
    "connectionType": "coexistence"
  }
}
```

`phoneNumberId` is the Whitelabel WhatsApp Cloud API id. `waPhoneNumberId` is Meta’s id. `connectionType` is `coexistence` or `dedicated`, or `null` when a headless client omitted it and the link allowed both. `externalCustomerId` is `null` when the customer has none.

## setup_link.failed

A signup attempt failed. The link can stay `IN_PROGRESS` so the owner can retry. A later failure does not send this event again.

`data` has the same phone fields (null when the phone was not stored) plus `errorCode` and `errorMessage`.

`errorCode`: `token_exchange_failed`, `phone_verification_failed`, `phone_already_bound`, `waba_limit_reached`, `phone_number_limit`, or `internal_error`.

## setup_link.expired

The first hosted or headless config request that sees an unused link past `expiresAt`. `data.errorCode` is `link_expired`. Phone fields are null unless a phone was already stored. The public status poll does not emit this.

## message.received

A 1:1 inbound change was stored. One delivery per Meta change, not per message, when several messages arrived together.

`data` is the Meta change object, forwarded as received.

```json
{
  "event": "message.received",
  "tenantId": "ck_tenant",
  "timestamp": "2026-09-30T16:00:00.000Z",
  "customerId": "ck_customer",
  "phoneNumberId": "ck_phone",
  "setupLinkId": "ck_setup_link",
  "data": {
    "field": "messages",
    "value": {
      "messaging_product": "whatsapp",
      "metadata": {
        "display_phone_number": "15551234567",
        "phone_number_id": "META_PHONE_ID"
      },
      "messages": [
        {
          "from": "5215512345678",
          "id": "wamid.HBgM...",
          "timestamp": "1759248000",
          "type": "text",
          "text": { "body": "SI" }
        }
      ]
    },
    "customerId": "ck_customer",
    "phoneNumberId": "ck_phone",
    "setupLinkId": "ck_setup_link"
  }
}
```

`metadata.phone_number_id` is Meta’s id (`waPhoneNumberId`). `phoneNumberId` on the envelope and on `data` is the Whitelabel WhatsApp Cloud API id. `messages[].id` is the wamid. `customerId` and `setupLinkId` are null when the phone is not linked to a customer or setup link.

## message.status

A 1:1 status change was stored (`sent`, `delivered`, `read`, `failed`). One delivery per Meta change. `data` is the Meta change. Read `data.value.statuses[]`.

```json
{
  "event": "message.status",
  "tenantId": "ck_tenant",
  "timestamp": "2026-09-30T16:00:05.000Z",
  "customerId": "ck_customer",
  "phoneNumberId": "ck_phone",
  "setupLinkId": null,
  "data": {
    "field": "messages",
    "value": {
      "metadata": { "phone_number_id": "META_PHONE_ID" },
      "statuses": [
        {
          "id": "wamid.HBgM...",
          "status": "failed",
          "timestamp": "1759248005",
          "errors": [{ "code": 131026 }]
        }
      ]
    },
    "customerId": "ck_customer",
    "phoneNumberId": "ck_phone"
  }
}
```

`message.sent`, `message.delivered`, `message.read` The processor does not enqueue them. Use `message.status` and the Meta status string.

`conversation.started` and `conversation.expired` are also names in that file. They are not enqueued.

## message.media_ready

The stored copy of a file on a message is ready. One delivery per file. Sent for inbound media, outbound media sent by `id` or `link`, and coexistence echoes (`origin` `business_app`), when storage is configured. Not sent for imported history (`origin` `history_sync`): those files are still copied into storage.

`data` is built by this API: `mediaAssetId`, `messageId`, `wamId`, `conversationId`, `origin`, `direction`, `kind`, `status` (`STORED`), `waMediaId`, `mimeType`, `byteSize`, `sha256`, `filename`, `caption`, `transcript` (`{ text, language, provider }` or `null`), `url` (signed, time-limited), `urlExpiresAt`, `storedAt`, `expiresAt`. See [Media](/whatsapp/guides/media.md).

## message.media_failed

Every attempt to copy a file failed. Same `data` as `message.media_ready`, with `status` `FAILED`, `error`, and `url: null`. Not sent for imported history. `POST /api/v1/media/assets/:id/retry` queues it again.

## message.echo

Meta field `smb_message_echoes`: on a coexistence number, the business sent a message from the WhatsApp Business app. `data` is the Meta change; read `data.value.message_echoes[]` (`from` is the business, `to` the customer). The message is stored as `OUTBOUND` with `origin` `business_app` in the customer's conversation. An echo does not open the 24-hour window. `message.echo` is unchanged when a human-takeover pause is also recorded.

## conversation.human_takeover

A WhatsApp Business app echo started or extended the per-conversation pause. One event per such echo. A later echo resets the pause and sends this again; use `pausedUntil`. A retry still sends it when the message was stored and the pause was not. After this event was queued, another delivery of the same `echoWamId` does not send it again. Imported history does not send it. `conversation.human_takeover` and `conversation.bot_resumed` are delivered to every tenant that has a webhook URL. There is no per-event filter.

`data` is built by this API:

```json
{
  "conversationId": "ck_conversation",
  "contactId": "ck_contact",
  "waId": "5215512345678",
  "phoneNumberId": "ck_phone",
  "waPhoneNumberId": "META_PHONE_ID",
  "pausedUntil": "2026-10-28T16:30:00.000Z",
  "lastBusinessAppReplyAt": "2026-10-28T16:00:00.000Z",
  "echoMessageId": "ck_message",
  "echoWamId": "wamid.HBgM...",
  "pauseMinutes": 30
}
```

| Field | Meaning |
| --- | --- |
| `phoneNumberId` | Whitelabel WhatsApp Cloud API phone id. |
| `waPhoneNumberId` | Meta phone number id. |
| `pausedUntil` | `humanActiveUntil` after this echo. ISO-8601. |
| `lastBusinessAppReplyAt` | Meta timestamp of the last app reply that started or extended the pause. A late echo, a revoke, or a disabled pause does not move it. |
| `echoMessageId` | Whitelabel WhatsApp Cloud API id of the stored echo. |
| `echoWamId` | Meta id of that echo. |
| `pauseMinutes` | Minutes applied: the phone's `botPauseMinutesOnEcho`, or the deployment default (30) when that is null. |

The pause uses the echo's Meta timestamp, not the time Whitelabel WhatsApp Cloud API stored it. An echo that reached Whitelabel WhatsApp Cloud API more than 10 minutes after that timestamp is stored and does not pause. Time spent waiting on the processing queue does not count. A pause that would already have ended (`pausedUntil` not in the future at processing time) is not recorded. An older echo that arrives after a newer one does not shorten `pausedUntil`. An echo at or before `botResumedAt` does not pause. `type` `revoke` (the business deleted a message) does not pause. `type` `edit` does: an edit is the person changing a message in the Business app, and the pause runs from the edit's timestamp. Automated away or welcome messages are not classified separately; if the Business app echoes them, they pause the bot too.

Whitelabel WhatsApp Cloud API does not block `POST /messages` while the pause is active. The tenant bot must skip its own sends until `pausedUntil`, or until it receives `conversation.bot_resumed`.

`GET /api/v1/conversations` and `GET /api/v1/conversations/:id` include `humanActiveUntil`, `lastBusinessAppReplyAt`, and `botPaused` (`humanActiveUntil` is still in the future).

## conversation.bot_resumed

`POST /api/v1/conversations/:id/bot-resume` (scope `conversations:read` for now) cleared a pause that was still in the future. Sent once per clear. A second call, or a call when the pause has already expired, does not send it again and does not change the row. A later app echo starts a new pause and sends `conversation.human_takeover` again.

```json
{
  "conversationId": "ck_conversation",
  "contactId": "ck_contact",
  "waId": "5215512345678",
  "phoneNumberId": "ck_phone",
  "waPhoneNumberId": "META_PHONE_ID",
  "resumedAt": "2026-10-28T16:05:00.000Z"
}
```

`resumedAt` is `botResumedAt`. `humanActiveUntil` is null after this event. `contactId` and `waId` match `conversation.human_takeover`. A group conversation with no contact sends `contactId` and `waId` as `null`.

## history.sync

Meta field `history`: one chunk of the chat history shared after coexistence onboarding. `data` is a summary built by this API. It does not include threads or message text.

```json
{
  "phoneNumberId": "ck_phone",
  "waPhoneNumberId": "META_PHONE_ID",
  "phase": 1,
  "chunkOrder": 3,
  "progress": 40,
  "threads": 12,
  "messagesInChunk": 800,
  "messagesStored": 2400,
  "status": "IN_PROGRESS"
}
```

| Field | Meaning |
| --- | --- |
| `phoneNumberId` | Whitelabel WhatsApp Cloud API phone id. |
| `waPhoneNumberId` | Meta phone number id. |
| `phase` | Highest phase seen so far. 0 is day 0–1, 1 is day 1–90, 2 is day 90–180. An older chunk does not move it backwards. |
| `chunkOrder` | This webhook's `chunk_order`. Not a stored cursor. |
| `progress` | Highest progress seen so far, 0–100. 100 means Meta finished, including when that arrives before phase 2. |
| `threads` | Threads in this webhook. |
| `messagesInChunk` | Messages in this webhook. |
| `messagesStored` | Rows stored for this phone so far. A replay of the same messages adds 0. |
| `status` | `IN_PROGRESS`, `COMPLETED`, `DECLINED`, or `FAILED`. |

Messages are stored with `origin` `history_sync`, direction from the thread, and status from `history_context.status`. They are not sent as `message.received`, do not open the 24-hour window, and are not billed. Their files are copied into storage but do not send `message.media_ready` or `message.media_failed`. History audio is not transcribed unless the operator sets `HISTORY_SYNC_TRANSCRIBE=true`.

This replaced the previous `history.sync` body, which was the raw Meta change plus `stored` and `progress`. Set `HISTORY_SYNC_FULL_PAYLOAD=true` and restart to restore that body for one release. In that mode `stored` is the number of rows inserted by this webhook (a replay is 0). `history.sync.completed` and `history.sync.declined` stay summaries either way.

Whitelabel WhatsApp Cloud API asks Meta for that history (and for the business's phone contacts) once, within 24 hours of coexistence onboarding, via `smb_app_data`. The request ids and statuses are on `GET /api/v1/phone-numbers/:id/coexistence-sync`. See Coexistence sync.

## history.sync.completed

Sent once, when progress first reaches 100. A later chunk, including a replay, does not send it again. `data` is the `history.sync` summary with `status` `COMPLETED` and `completedAt` (ISO-8601).

## history.sync.declined

Sent once, when the business turns off history sharing. Meta sends error `2593109` and no threads are stored from that webhook. A decline does not replace a sync that already completed. `data`:

```json
{
  "phoneNumberId": "ck_phone",
  "waPhoneNumberId": "META_PHONE_ID",
  "phase": null,
  "progress": null,
  "messagesStored": 0,
  "status": "DECLINED",
  "errorCode": "2593109",
  "completedAt": "2026-10-27T18:00:00.000Z"
}
```

## contacts.sync

Meta field `smb_app_state_sync`: a change to the business's WhatsApp contacts. `data` is counts only. Phone numbers are not included.

```json
{
  "phoneNumberId": "ck_phone",
  "added": 2,
  "updated": 1,
  "removed": 1
}
```

`add` and `edit` upsert a contact. The name is `full_name`, then `first_name`, and is written only when the contact has no name or the current name came from an earlier state sync. A name set with `PATCH /api/v1/contacts/:id` is kept. `remove` does not delete the contact. It records the removal and leaves the name in place.

Meta does not send an end marker. A webhook that contains a contact sets `contactsStatus` to `IN_PROGRESS` and records when the chunk arrived. It does not set `COMPLETED`, and the quiet period that follows emits no event. The coexistence sweep sets `COMPLETED` after 15 minutes with no newer contact chunk. A later webhook sets `IN_PROGRESS` again and restarts that wait. `contactsStored` counts adds and updates (a name change or a contact restored after remove), not removes. Later webhooks still apply.

`history` and `smb_app_state_sync` are not forwarded as `account.update`.

## template.status_update

Meta field `message_template_status_update`. `data` is the Meta change plus `templateId` (the local template, or `null` when none matches `message_template_id`). When it matches, the local `status` is updated (`APPROVED`, `REJECTED`, `PAUSED`, `DISABLED`, `IN_APPEAL`, `PENDING`), so polling after create is no longer required.

## phone_number.quality_update

Meta field `phone_number_quality_update`. `data` is the Meta change (`display_phone_number`, `event`, `current_limit`).

Meta only sends `smb_message_echoes`, `history`, `message_template_status_update` and `phone_number_quality_update` when the Meta app is subscribed to those webhook fields (App Dashboard → WhatsApp → Configuration).

## phone.disconnected

`account_update` was `PARTNER_REMOVED`, `PARTNER_APP_UNINSTALLED`, `ACCOUNT_DELETED`, or `ACCOUNT_OFFBOARDED`, and the WABA matched a stored credential. Those four strings are Meta’s event names.

`data` is built by this API:

```json
{
  "event": "phone.disconnected",
  "tenantId": "ck_tenant",
  "timestamp": "2026-09-30T16:01:00.000Z",
  "customerId": "ck_customer",
  "phoneNumberId": "ck_phone",
  "setupLinkId": "ck_setup_link",
  "data": {
    "field": "account_update",
    "accountEvent": "PARTNER_REMOVED",
    "wabaId": "WABA_ID",
    "messagingAccountId": "WABA_ID",
    "entryId": "PARTNER_OR_WABA_ID",
    "disconnectionInfo": null,
    "phoneNumberIds": ["ck_phone"],
    "waPhoneNumberIds": ["META_PHONE_ID"],
    "phones": [
      { "phoneNumberId": "ck_phone", "waPhoneNumberId": "META_PHONE_ID", "status": "INACTIVE", "customerId": "ck_customer", "setupLinkId": "ck_setup_link" }
    ],
    "change": { "field": "account_update", "value": {} },
    "customerId": "ck_customer",
    "phoneNumberId": "ck_phone",
    "setupLinkId": "ck_setup_link"
  }
}
```

`phoneNumberIds` are Whitelabel WhatsApp Cloud API ids. The envelope `customerId` / `phoneNumberId` / `setupLinkId` describe the first resolved phone. When more than one phone is listed, envelope `customers` has one entry per phone. A `BANNED` phone stays `BANNED`. Further sends fail validation because the phone is not `ACTIVE`. Pending outbound rows on those phones are marked `FAILED` with `errorCode` `PHONE_DISCONNECTED`.

Those Meta events that omit `waba_info.waba_id` do not match a credential and do not send this event. This API does not subscribe the Meta app to the `account_update` field. That subscription is a Meta App Dashboard step. `change.value` is the raw Meta value.

## account.update

Two producers:

1. A resolved `account_update` that is not a disconnect (`ACCOUNT_RECONNECTED`, `ACCOUNT_RESTRICTION`, and any other non-disconnect event that matched a WABA). `data` has the same keys as `phone.disconnected`, and phones are not flipped to `INACTIVE`.
2. Any other change that was not a message, status, call, `business_username_update`, `history`, or `smb_app_state_sync`. `data` is the raw Meta change object only.

Unresolved `account_update` payloads are logged and not delivered.

## username.update

Meta field `business_username_update`. `data` is the raw change object.

## referral.received

An inbound message carried a new Click-to-WhatsApp referral. This is a second delivery beside `message.received`. `data` is built by this API:

```json
{
  "conversationId": "ck_conversation",
  "contactId": "ck_contact",
  "phoneNumberId": "ck_phone",
  "ctwaClid": "CLICK_ID",
  "sourceType": "ad",
  "sourceId": "AD_ID",
  "sourceUrl": "https://fb.me/example",
  "headline": null,
  "body": null,
  "customerId": "ck_customer",
  "setupLinkId": "ck_setup_link"
}
```

`phoneNumberId` here is the Whitelabel WhatsApp Cloud API id and is not overwritten. Nulls appear when Meta omitted the field. `customerId` is null when the phone has no customer. The envelope carries the same three routing fields.

## webhook.test

`POST /api/v1/webhook-config/test` only. Not queued. No `X-Vitral-WhatsApp-Delivery-Id`.

```json
{
  "event": "webhook.test",
  "tenantId": "ck_tenant",
  "timestamp": "2026-09-30T16:02:00.000Z",
  "data": { "message": "This is a test webhook event from Whitelabel WhatsApp Cloud API" }
}
```

## Groups and calls

Also emitted when those webhook shapes are processed. `data` for calls is the raw Meta change. Group payload shapes are still treated as unverified in the processor. Names you can see:

`group.message.received`, `group.message.status`, `group.created`, `group.updated`, `group.invite_link.updated`, `group.participant.joined`, `group.participant.left`, `group.participant.removed`, `group.join_request.created`, `group.join_request.revoked`, `group.join_request.approved`, `group.join_request.rejected`, `group.event`, `call.incoming`, `call.connect`, `call.status`, `call.terminated`, `call.permission.reply`, `call.permission.update`.

Appointment reminders do not need these.
