# webhook.test

You sent a test event, from the dashboard or with the API.

Sent when someone sends a test from the dashboard or calls [Send a test event](https://chatwise.so/docs/api/test-webhook-endpoint.md), also to a paused endpoint. Endpoints don't subscribe to it.

It is signed like every event. It is sent once: it isn't retried, and it isn't in the delivery log. Its `X-Chatwise-Delivery` header is always `wd_test`.

## Headers

| Header | Description | Example |
| --- | --- | --- |
| `webhook-id` | The event's id, the same on every retry and redelivery. Dedupe on it. | `evt_01JE2Z3QK4T8M6N2R5S7V9W1X3` |
| `webhook-timestamp` | When this attempt was signed, in Unix seconds. | `1794475538` |
| `webhook-signature` | One or more signatures, separated by spaces: `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`. | `v1,<base64>` |
| `X-Chatwise-Event` | The event's name. | `webhook.test` |
| `X-Chatwise-Delivery` | The delivery's id. | `wd_test` |
| `User-Agent` | Always `Chatwise-Webhooks/1.0`. | `Chatwise-Webhooks/1.0` |

## Payload

```json
{
  "id": "evt_01JE2Z3QK4T8M6N2R5S7V9W1X3",
  "type": "webhook.test",
  "timestamp": "2026-11-12T09:25:36.000Z",
  "apiVersion": "2026-12-01",
  "workspaceId": "42",
  "data": {
    "endpointId": "we_01JE2Z3K8Q9V7W5X4Y3Z2A1B0C",
    "message": "This is a test event from Chatwise."
  }
}
```

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | The event's id, the same on every retry and redelivery. Also the `webhook-id` header. |
| `type` | string | The event's name. Also the `X-Chatwise-Event` header. Always `webhook.test`. |
| `timestamp` | string | When the event happened. The same on every retry. ISO 8601, in UTC. |
| `apiVersion` | string | The payload format, as a date. |
| `workspaceId` | string | The workspace the event happened in. |
| `data` | object | What happened. |
| `data.endpointId` | string | The endpoint the test was sent to. |
| `data.message` | string | A fixed sentence. |

## Verify it

Check the signature against the raw body before you trust the event. [Verify signatures](https://chatwise.so/docs/webhooks/verify-signatures.md) explains each step and has a complete server.

**Node.js** `verify.mjs`:

```js
import { createHmac, timingSafeEqual } from "node:crypto";

const FIVE_MINUTES = 5 * 60;

// rawBody is the request body exactly as received (a Buffer or a string).
// headers has lowercase names, as Node's request.headers does.
export function verifyChatwiseWebhook(rawBody, headers, secret, now = Date.now() / 1000) {
  const id = headers["webhook-id"];
  const timestamp = headers["webhook-timestamp"];
  const signatures = headers["webhook-signature"];
  if (!id || !timestamp || !signatures) return false;

  // Refuse old requests, so a captured one can't be sent again later.
  if (!(Math.abs(now - Number(timestamp)) <= FIVE_MINUTES)) return false;

  const key = Buffer.from(secret.slice("whsec_".length), "base64");
  const expected = createHmac("sha256", key).update(`${id}.${timestamp}.`).update(rawBody).digest();

  // While a secret is being rotated there are two signatures. One match is enough.
  return signatures.split(" ").some((signature) => {
    const [version, value = ""] = signature.split(",");
    const received = Buffer.from(value, "base64");
    return version === "v1" && received.length === expected.length && timingSafeEqual(received, expected);
  });
}
```

**Python** `verify.py`:

```python
import base64
import hashlib
import hmac
import time

FIVE_MINUTES = 5 * 60


def verify_chatwise_webhook(raw_body, headers, secret, now=None):
    """raw_body is the request body exactly as received, as bytes.

    headers is a mapping with case-insensitive or lowercase names.
    """
    message_id = headers.get("webhook-id")
    timestamp = headers.get("webhook-timestamp")
    signatures = headers.get("webhook-signature")
    if not message_id or not timestamp or not signatures:
        return False

    # Refuse old requests, so a captured one can't be sent again later.
    try:
        age = abs((time.time() if now is None else now) - int(timestamp))
    except ValueError:
        return False
    if age > FIVE_MINUTES:
        return False

    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed = f"{message_id}.{timestamp}.".encode() + raw_body
    expected = "v1," + base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()

    # While a secret is being rotated there are two signatures. One match is enough.
    return any(
        hmac.compare_digest(signature.encode(), expected.encode())
        for signature in signatures.split(" ")
    )
```

## Answer it

Answer with any 2xx status within 10 seconds. A test that fails isn't retried.
