# Webhooks and Queues

Source: https://docs.autessa.com/docs/cli/webhooks-and-queues

> Inbound webhooks that let external systems trigger Autessa, durable work queues for background batches, and rules that archive closed agent conversations into AutessaDB.

# Webhooks and Queues

Three namespaces for work that happens without you watching. `custom-webhooks` lets an outside system trigger Autessa; `workqueues` drains a large batch through the worker fleet; `conversation-sync` archives closed agent conversations into a table. All three run server-side with no session attached, which makes them the durable half of [building headless](/docs/cli.md).

## Inbound webhooks

A webhook exposes a public URL. An external system POSTs to it; the payload is transformed into named variables — via JSONPath mappings or an AutessaScript transform — and those variables are substituted into a target resource that runs **asynchronously**. The target can be a tool, an agent, a manager, or a direct AutessaDB operation.

### How to create one

```bash
autessa custom-webhooks create --webhookConfig '{
  "name": "Inbound lead",
  "...": "..."
}'
```

> `create` mints the webhook's API key and returns it **exactly once**. Capture it from that response — it is never returned by any read. If you lose it, `refresh-api-key` rotates to a new one, which means updating every caller.

Run `autessa custom-webhooks create help` for the full `webhookConfig` shape; `name` is the only required field inside it.

### How to manage and debug one

```bash
autessa custom-webhooks get-all
autessa custom-webhooks get --json '{...}'
autessa custom-webhooks update --json '{...}'
autessa custom-webhooks refresh-api-key --json '{...}'
autessa custom-webhooks delete --json '{...}'
```

`update` changes the configuration and/or the enabled flag — disable rather than delete while you are debugging, since `delete` is a hard delete.

The command that earns its keep:

```bash
autessa custom-webhooks get-execution-history --json '{...}'
```

Pages through inbound calls newest-first with status, timing, attempt number, and **decrypted execution details** — so you can see the payload that actually arrived rather than what the caller believes it sent. That is almost always where a "the webhook isn't working" investigation ends.

### How to test and replay one

```bash
autessa secrets create --name twitch-eventsub-secret --mode SEALED --value '...' --allowedHosts '["api.twitch.tv"]'
autessa custom-webhooks create --webhookConfig @webhook.json
autessa custom-webhooks test --webhookId <id> --headers @headers.json --body @body.txt        # dry run: steps + reply
autessa custom-webhooks test --webhookId <id> --query '{"hub.mode":"subscribe","hub.verify_token":"t","hub.challenge":"42"}' --method GET
autessa custom-webhooks test --webhookId <id> --headers @headers.json --body @body.txt --run true   # really run it
autessa custom-webhooks get-execution-history --webhookId <id> --status REJECTED
autessa custom-webhooks replay --executionId <executionId>
```

`test` sends a sample call through the webhook's real checks — the handshake, the key or signature, the validation script, and the transform — and returns the outcome (`HANDSHAKE`, `REJECTED`, or `ACCEPTED`), each step in plain language, the variables, and the exact reply the sender would get. It is a dry run unless you pass `--run true`, which really runs it like a delivery from the sender. It needs edit access to the webhook. Handshake scripts do run during a dry run, including any callback they make to the sender.

Pass the body as `--body @file` so a signed sample stays byte-exact; an inline JSON value is re-serialized, which breaks its signature. To debug a refusal, paste a real delivery's headers and body.

`replay` runs a stored delivery again with the webhook's current settings. Store signing secrets with `autessa secrets create` and refer to them by name in `signatureConfig` or in scripts. For senders whose signature scheme isn't built in (`authMode: SCRIPT`), see [Any other service: scripts](/docs/guide/api-management/webhook-handlers.md#any-other-service-scripts).

Sharing a webhook is web-app-only.

## Work queues

Durable background processing. You create a queue, enqueue a batch, and the worker fleet drains it — `enqueue` returns immediately, so you poll progress rather than waiting.

### How to create a queue

```bash
autessa workqueues create \
  --name "Nightly enrichment" \
  --description "Enriches new leads." \
  --maxConcurrency 10 \
  --defaultMaxAttempts 3 \
  --defaultTimeoutSeconds 120
```

| Setting | Controls |
| --- | --- |
| `maxConcurrency` | How many items are leased and running at once |
| `defaultMaxAttempts` | Retries for items that don't override it |
| `defaultTimeoutSeconds` | Per-item lease timeout — an item that exceeds it is retried |
| `stagePrecedence` | Ordered stage names, so earlier stages lease first. Omit for plain FIFO-by-priority |
| `runtime` | Where items run; defaults to `WORKER` |

Time fields are plain integers in seconds, not durations.

### How to enqueue work

Each item names the **published tool** that processes it, plus a free-form payload:

```bash
autessa workqueues enqueue --queueId <id> --items '[
  { "groupKey": "run-2026-09-10", "actionToolId": "gPdJwp5jbr9eN", "payload": {"leadId": "1"} },
  { "groupKey": "run-2026-09-10", "actionToolId": "gPdJwp5jbr9eN", "payload": {"leadId": "2"} }
]'
```

`groupKey` is what makes a batch addressable afterwards — progress, cancellation and dead-item retries all operate on a group. Set it deliberately rather than leaving items ungrouped.

Build the action tool the usual way, preferring a purpose-built type over a script — see [Tools](/docs/cli/tools.md).

### How to watch it drain

```bash
autessa workqueues progress --queueId <id> --groupKey run-2026-09-10
```

Returns counts by state — `pending`, `running`, `succeeded`, `failed`, `dead`, `cancelled` — plus per-stage counts. This is your polling command.

```bash
autessa workqueues items-list --queueId <id> --json '{...}'
autessa workqueues items-get --json '{...}'
```

`items-list` filters by state, stage or `groupKey`; `items-get` returns one item's state, attempts, payload, result and last error.

### How to intervene

```bash
autessa workqueues pause --queueId <id>       # stop leasing
autessa workqueues resume --queueId <id>

autessa workqueues retry-dead --json '{...}'  # requeue a group's DEAD items
autessa workqueues cancel-group --json '{...}'
```

**Dead** means an item exhausted its attempts. `retry-dead` requeues every dead item in a group for another run — the right move after you fix the underlying tool. `cancel-group` stops every not-yet-terminal item in a group being leased.

> `pause` is the emergency brake: it stops leasing without losing queued work, so a runaway batch can be halted while you investigate and then resumed.

## Conversation sync

Company-scoped rules that copy a **closed** agent conversation's message log into an AutessaDB table row, as JSON, for reporting and analysis.

```bash
autessa conversation-sync create \
  --name "Support transcripts" \
  --agentIds '["K2UYSwk3Yy4i"]' \
  --tableUpdates '[{...}]' \
  --enabled true
```

```bash
autessa conversation-sync all
autessa conversation-sync get --json '{...}'
autessa conversation-sync update --json '{...}'
autessa conversation-sync delete --json '{...}'
```

Three things determine whether this does what you expect:

- **It never syncs retroactively.** A config applies only to conversations closed *after* it is written. Creating one does not backfill.
- **It runs off the conversation-logged queue**, asynchronously — not at config-write time. A conversation appears in the table some time after it closes.
- **The destination is always an AutessaDB table.** Never an external connector.

> This is **not** how an agent is deployed or made reachable to end users. It only archives conversations that already happened. If you are looking for how people reach an agent, see [Custom apps](/docs/cli/apps.md) or [Phone and SMS](/docs/cli/phone.md).

`requiresEvaluation` limits syncing to evaluated conversations, and `allowSandboxConversations` decides whether your own UI/sandbox runs are included — off by default, which is usually why a test conversation does not show up.

## Related

- [Autessa CLI](/docs/cli.md) — why durable work belongs on the platform
- [Scheduled jobs](/docs/cli/scheduled-jobs.md) — the time-driven counterpart
- [Tools](/docs/cli/tools.md) — what a webhook or queue item runs
- [AutessaDB](/docs/cli/autessadb.md) — triggers, the row-change counterpart
- [Webhook handlers](/docs/guide/api-management/webhook-handlers.md) in the builder

