# Webhooks

> Get incoming messages and delivery updates pushed to your server, signed with HMAC-SHA256.

Source: https://zyptos.com/docs/webhooks

## Add an endpoint

1. In the app, open `Settings` > `Add endpoint` (owners and admins).
2. Enter an https URL on your server and pick the events you want. A workspace can have up to 5 endpoints.
3. Copy the signing secret (`whsec_…`). It's shown once; Zyptos stores it encrypted.
4. Press `Test` to send a signed `ping` event and see the HTTP status your server returned.

## Events

| Event | When |
| --- | --- |
| `message.received` | A customer sent a message |
| `message.status` | An outgoing message was sent, delivered, read or failed |

`message.status` fires for each step Meta reports (`sent`, `delivered`, `read`, `failed`) for every outgoing message, whether it came from the inbox, a broadcast or the API, and when an API send fails before reaching Meta.

## Payload

Every delivery is a JSON POST with the same envelope:

message.received:

```json
{
  "id": "6f0c1a52-1b5e-4c55-9d1e-0c8f7f1f2a10",
  "type": "message.received",
  "created_at": "2026-11-25T06:31:12.000Z",
  "workspace_id": "3d6f…",
  "data": {
    "conversation_id": "a1b2…",
    "message": { "id": "…", "direction": "in", "type": "text", "text": "Is my order shipped?", "status": "received", "created_at": "…" },
    "contact": { "id": "…", "phone": "919876543210", "name": "Asha Verma", "opted_out": false, "tags": ["vip"] }
  }
}
```

message.status:

```json
{
  "id": "…",
  "type": "message.status",
  "created_at": "2026-11-25T06:31:40.000Z",
  "workspace_id": "3d6f…",
  "data": {
    "message_id": "…",
    "wa_message_id": "wamid.HBgM…",
    "status": "delivered",
    "error": null,
    "conversation_id": "…",
    "contact_id": "…",
    "timestamp": "2026-11-25T06:31:39.000Z"
  }
}
```

The `message` and `contact` objects have the same fields as the [Message](https://zyptos.com/docs/api#schema-Message) and [Contact](https://zyptos.com/docs/api#schema-Contact) API objects. Headers include `Zyptos-Event`, `Zyptos-Delivery` (unique per delivery, use it to de-duplicate) and `Zyptos-Signature`.

## Verify signatures

`Zyptos-Signature` looks like `t=1764052272,v1=5f2b…`. Compute HMAC-SHA256 of `<t>.<raw body>` with your secret, compare it to `v1` in constant time, and reject timestamps older than five minutes. Use the raw request body, before any JSON parsing.

Node.js:

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

export function verifyZyptos(rawBody: string, header: string, secret: string) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false;
  const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest();
  const given = Buffer.from(parts.v1 ?? "", "hex");
  return given.length === expected.length && timingSafeEqual(given, expected);
}
```

Python:

```python
import hmac, hashlib, time

def verify_zyptos(raw_body: bytes, header: str, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t = int(parts.get("t", "0"))
    if abs(time.time() - t) > 300:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))
```

## Retries and timeouts

- Respond with any 2xx within 10 seconds. Do slow work after responding.
- Timeouts, network errors and non-2xx responses are retried up to 6 attempts with exponential backoff. Redirects are not followed.
- Deliveries can arrive more than once or out of order. De-duplicate on `Zyptos-Delivery` and compare timestamps.
- The endpoint list shows the last delivery time and result. Pause an endpoint to stop deliveries without deleting it.
