---
docId: doc_964d28147113488c874e76b67bb9375c
title: Delivery and signatures
description: "Verify webhook signatures and handle deliveries."
---

<script>
  import { Note } from '$lib/components';
</script>

# Delivery and signatures

Platica delivers webhooks through `POST` with `Content-Type: application/json`. If you configure a `secret`, it includes an HMAC-SHA256 signature to verify that the event comes from Platica.

## Envelope

Events for conversations, messages, comments, contacts, ads, and WhatsApp Flows arrive with this envelope:

```json
{
  "id": "9f8c...",
  "event": "conversation.created",
  "workspaceId": "ws_456",
  "timestamp": "2026-05-06T19:00:00.000Z",
  "source": "system.conversation.created",
  "resourceType": "conversation",
  "resourceId": "conv_123",
  "changes": null,
  "data": {}
}
```

| Field | Description |
|-------|-------------|
| `id` | Unique identifier of the event |
| `event` | Name of the event received |
| `workspaceId` | Workspace where it happened |
| `timestamp` | ISO-8601 date of the event |
| `source` | Origin of the event, in the format `<origin>.<resource>.<action>` — see [The `source` field](/api-reference/webhooks/payloads#the-source-field) |
| `resourceType` | `conversation`, `message`, `comment`, `client`, or `flow_response` |
| `resourceId` | ID of the affected resource |
| `changes` | Diff of the change, when it applies |
| `data` | Normalized snapshot of the resource |

See [List events](/api-reference/webhooks/events) for the 29 available events and [Payloads](/api-reference/webhooks/payloads) for the content of `data` and the possible values of `source`.

## Headers

| Header | Description |
|--------|-------------|
| `Content-Type` | `application/json` |
| `User-Agent` | Platica's User-Agent |
| `X-Webhook-Event` | Same as `payload.event` |
| `X-Webhook-Id` | Identifier of the configured webhook |
| `X-Webhook-Event-Id` | Same as `payload.id` |
| `X-Webhook-Resource-Type` | Type of the affected resource |
| `X-Webhook-Resource-Id` | ID of the affected resource |
| `X-Webhook-Timestamp` | Same as `payload.timestamp` |
| `X-Webhook-Signature` | `sha256=<hex>` if you configured `secret` |

## Validate the signature

The signature is computed with HMAC-SHA256 over the raw body (`rawBody`) that your endpoint received:

```text
sha256=<hmac_sha256(secret, rawBody)>
```

Use the [SDK](/sdk) helper `parseWebhookEvent` to validate the signature and get a typed event. A missing or mismatched signature throws `WebhookVerificationError`:

```ts
import { parseWebhookEvent, WebhookVerificationError } from 'platic-sdk';

async function receiveWebhook(request: Request): Promise<Response> {
  try {
    const event = await parseWebhookEvent({
      payload: await request.text(), // the raw body, not the already parsed JSON
      signature: request.headers.get('x-webhook-signature'),
      secret: process.env.PLATIC_WEBHOOK_SECRET!
    });
    console.log(event.event, event.id);
    return new Response(null, { status: 200 });
  } catch (error) {
    if (error instanceof WebhookVerificationError) return new Response(null, { status: 401 });
    throw error;
  }
}
```

Without the SDK, in Node.js:

```javascript
const crypto = require('crypto');

function verifyWebhook(secret, rawBody, signatureHeader) {
  const expected = Buffer.from(
    'sha256=' + crypto.createHmac('sha256', secret).update(rawBody).digest('hex')
  );
  const received = Buffer.from(signatureHeader || '');

  // timingSafeEqual throws an error if the sizes are different.
  return received.length === expected.length && crypto.timingSafeEqual(expected, received);
}
```

The signature does not include a date and cannot prevent replay of a captured delivery. An event may also arrive more than once. Store its `id` and discard duplicates.

<Note type="warning">

Use the raw request body, not the re-serialized JSON object. If your framework parses the body automatically, save the `rawBody` before converting it to JSON.

</Note>

## Responses and retries

Respond with `2xx` after processing the event. For conversation, message, comment, contact, and ad events, Platica uses the status to confirm receipt and ignores the response body.

Platica makes one delivery attempt per event and does not retry a failed one. Each failure counts toward the [automatic pause](#automatic-pause). If your server was down, use the API to fetch what changed in the meantime.

<Note type="note">

For [WhatsApp Flows](/api-reference/webhooks/whatsapp-flows), return the JSON that continues the flow. It uses the same `X-Webhook-*` headers and signature over `rawBody`.

</Note>

## Automatic pause

A delivery fails if your server returns `5xx`, takes more than 15 seconds, or cannot be reached. A `4xx` response counts as delivered. If failures continue, Platica automatically pauses the webhook.

`autoPause` decides when. You send it when you [create](/api-reference/webhooks/create) or [update](/api-reference/webhooks/update) the webhook, and every read returns it.

| `autoPause` | When it pauses |
|-------------|----------------|
| `{ "mode": "failures", "failures": 5 }` | After `failures` consecutive failed deliveries, from 5 to 1000. It is the default: a webhook that chose nothing reads like this |
| `{ "mode": "time", "hours": 24 }` | It keeps sending events and pauses when it has been failing for `hours` hours without a single successful delivery, from 1 to 168 (7 days). It also has to add up at least 5 consecutive failed deliveries |

```json
{
  "autoPause": { "mode": "time", "hours": 24 }
}
```

Use `failures` with mode `"failures"` and `hours` with `"time"`. Automatic pause is required: it allows at most 7 days of failures.

How failures are counted:

- `consecutiveFailures` adds one for every failed delivery and goes back to `0` with the first successful one.
- `failingSince` is the date of the first failed delivery of the streak. It is `null` while deliveries go out fine.
- Changing `autoPause` does not reset the count. If you choose a lower number of failures than the webhook already has, it pauses with the next failed delivery.
- Responses to [WhatsApp Flows](/api-reference/webhooks/whatsapp-flows) requests do not count.

When it pauses:

- It stops receiving events, with `active: false` and `status: "paused"`.
- The workspace owners and admins get a notice in Platica and by email, with the reason: after how many consecutive failed deliveries, or how many hours it had been failing.
- To reactivate it, fix your server and use [test a webhook](/api-reference/webhooks/test) or [update](/api-reference/webhooks/update) the webhook with `active: true`. Platica verifies the destination and the count goes back to `0`.
- Editing other fields of a webhook that paused itself does not reactivate it.
