# Receive webhooks

> Register a URL that wakes your agent when work is waiting, verify each delivery's signature, and handle retries and pausing.

A webhook wakes your agent when the record needs it. Handline posts to your URL; what runs behind it, such as starting an agent session, is up to you. The agent then reads the work queue through MCP.

## Register a URL

An owner or admin does this on **Webhooks** in the product's settings. Agents can list webhooks (`webhooks_list`) but can't add or change them.

1. Add the URL. It must be HTTPS and must not point into a private network; Handline checks again before every delivery. A product can have up to 10 URLs.
2. Choose the kinds of work item it receives, or leave all of them.
3. Copy the signing secret. It is shown once. Keep it with your receiver, such as in `HANDLINE_WEBHOOK_SECRET`.
4. Send a test delivery and check the receiver's answer in the delivery log.

## What a delivery holds

Pointers only: which product has new work items, how many, of which kinds, and their ids. A delivery never holds an instruction or any text from outside.

```json
{
  "type": "work_items",
  "deliveryId": "dlv_01J…",
  "workspaceId": "ws_01J…",
  "productId": "prd_01J…",
  "sentAt": "2026-11-22T09:14:03.000Z",
  "items": [{ "id": "wi_3f…", "kind": "stop_rule", "urgency": "normal" }],
  "counts": { "stop_rule": 1 },
  "openItems": 4,
  "next": "Read the work queue with the workItems.list tool, or call briefing.get at the start of a session."
}
```

`type` is `work_items`, `heartbeat` (once a day, even when nothing is new) or `test` (a test delivery from **Webhooks**).

## Batching

Work items are gathered over a window, so a burst starts one session. Urgent kinds use a shorter window. The defaults are 120 seconds and 15 seconds; an owner or admin can set each from 10 seconds to an hour on **Webhooks**.

## Verify a delivery

Every delivery carries a `Handline-Signature` header: `t=<unix seconds>,v1=<hex HMAC-SHA256>`. The HMAC is computed with your URL's secret over `t`, a full stop, and the raw body. Reject a delivery whose signature doesn't match, or whose `t` is more than 5 minutes from your clock.

With the [helper package](/docs/developers/helper-package):

```ts title="app/webhooks/handline/route.ts"
import { verifyWebhook } from '@handline/handoff';

export async function POST(req: Request) {
  const body = await req.text();
  const ok = await verifyWebhook(body, req.headers.get('handline-signature'), process.env.HANDLINE_WEBHOOK_SECRET!);
  if (!ok) return new Response('bad signature', { status: 401 });
  const delivery = JSON.parse(body);
  // Start an agent session for delivery.productId.
  return new Response('ok');
}
```

Without it, in Node:

```ts title="verify.ts"
import { createHmac, timingSafeEqual } from 'node:crypto';

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

Answer within 10 seconds with any 2xx status. Start the agent's work after you answer.

## Retries and pausing

A delivery that gets no 2xx answer is retried with backoff, up to 6 attempts. The delivery log on **Webhooks**, and `webhooks_deliveries`, show each attempt with your receiver's response code. A URL that fails 10 times in a row is paused, and the workspace's admins are alerted. Work items stay in the queue; resume the URL on **Webhooks** once it works.

## Kinds of work item

| Kind | What it asks for | Urgency |
| --- | --- | --- |
| `recipient_converted` | Stop a recipient's sequence: they converted | urgent |
| `pause_in_tool` | Pause a placement in its tool | urgent |
| `retired_in_use` | Pull a live use of something retired | urgent |
| `fact_changed` | Update copy that quotes a changed fact | normal |
| `stop_rule` | A stop rule fired | normal |
| `fatigue` | A placement is tiring | normal |
| `pacing` | Budget pacing is off | normal |
| `email_health` | Bounce or complaint rate too high | urgent |
| `drift` | The record differs from what is live | normal |
| `conversions_rejected` | Conversions are being rejected | urgent |
| `conversion_deadline` | A conversion is about to pass its deadline | urgent |
| `credential_failing` | A platform connection stopped working | urgent |
| `read_failing` | An ad account can't be read | urgent |
| `reads_quota` | Reads are near the platform's daily limit | normal |
| `numbers_stale` | Reported numbers are stale | normal |
| `numbers_flagged` | Reported numbers look wrong | normal |
| `traced_share` | The traced share fell | urgent |
| `reconciliation` | Platform counts and Handline's disagree | normal |
| `experiment_look` | An experiment reached a planned look | normal |
| `experiment_check` | An experiment failed a check | urgent |
| `experiment_flag` | An experiment raised a flag | normal |
| `experiment_ended` | An experiment ended | normal |
| `learning_contradicted` | Re-test a contradicted learning | low |
| `change_set_decided` | A change set was approved or declined | normal |
| `webhook_paused` | A webhook was paused | urgent |
| `lead_lost` | A lead couldn't be delivered and was deleted | urgent |
| `domain_failing` | A page domain is failing | urgent |

How an agent works each one: [work the queue](/docs/agents/work-queue).
