# Webhook Handlers

Source: https://docs.autessa.com/docs/guide/api-management/webhook-handlers

> Receiving external webhooks and routing them to tools, agents, managers, or AutessaDB.

# Webhook Handlers

Webhook handlers give you public HTTPS endpoints that external systems — Meta, Stripe, GitHub, Slack, Shopify, Twilio, your own services — can call when something happens. Each handler checks the incoming request, extracts variables from the payload, and executes a resource you choose: a tool, an agent, a manager, or a direct AutessaDB operation. Providers point straight at the handler's URL; you don't need a server of your own in between. Services whose signature scheme isn't built in, such as Discord, Twitch, SendGrid, PayPal, and AWS SNS, work the same way with a short script: see [Any other service: scripts](#any-other-service-scripts).

## What it's for

Agents and tools normally run when you (or your API) invoke them. Webhook handlers flip the direction: the outside world initiates. A payment processor reports a charge, a CRM announces a new lead, a CI pipeline finishes a build — the handler turns that HTTP call into an execution inside Autessa, with fields from the payload mapped into the resource's inputs. No client API key is involved; each handler has its own dedicated key, or checks the sender's own signature instead, either with a built-in scheme or with a script you write.

## Navigating here

Click **Developer** on the rail, then **Webhooks**. The page lists your handlers in a table — name, an **Enabled**/**Disabled** status badge, a **View History** button, and **View Calling Instructions** — with a **Create Webhook** button at the top. Click a row to open its configuration.

## Key concepts

- **One trigger URL per handler** — every handler has a short URL, `https://api.autessa.com/w/{webhookId}` (the long form `https://api.autessa.com/clients/custom-webhooks?resourceId={webhookId}` also works), which accepts any HTTP method (GET, POST, PUT, PATCH, DELETE) so it fits whatever the sending system insists on. You don't configure allowed methods; the method used is simply recorded per delivery. See the [Custom Webhooks API](/docs/api/custom-webhooks.md) for the full request contract.
- **Dedicated webhook key** — each handler gets its own `wh:{keyId}:{keySecret}` credential, shown **once** in the "Webhook Created Successfully" modal. The sender can pass it in the `Authorization` header (with or without `Bearer`), in an `X-API-Key` header, or in the URL as an `authorization`, `auth`, `apiKey`, or `key` query parameter when it can't set headers. Lost it? **View Calling Instructions → Reset API Key** issues a new one and immediately invalidates the old. Autessa removes the key from stored history.
- **Sender signatures instead of a key** — providers such as Meta, GitHub, Stripe, Slack, Shopify, Twilio, and Svix-based senders (Resend, Clerk, and others) sign every request with a secret you share with them. Store that secret as an [Autessa Secret](/docs/guide/agentic/secrets.md) and pick it on the handler (saving adds the handler to the secret's [What can use it](/docs/guide/agentic/secrets.md#what-can-use-a-secret) list), and the handler verifies the signature on every call; the URL you give the provider carries no key at all. A missing or wrong signature is rejected with `401`. You can also require both the key and the signature, or accept either one. See [Signature verification](/docs/api/custom-webhooks.md#signature-verification).
- **Script authentication** — for any other sender, set the handler to script authentication (`authMode: SCRIPT`): there is no key and no built-in signature check, and the validation script alone decides whether a call is accepted, so the script is required. Script helpers verify Ed25519, ECDSA, and RSA signatures and HMACs keyed by an Autessa Secret. See [Any other service: scripts](#any-other-service-scripts).
- **Verification handshakes** — many providers check a new URL by sending a challenge before they send real events. The handler can answer Meta, Slack, Microsoft Graph, Dropbox, Zoom, and X challenges (or one you describe with a custom rule, or answer with a handshake script) immediately, without running your resource. These show in history as **HANDSHAKE**.
- **Four target types** — the **Resource Execution** section selects what runs: a **Tool** (with argument mappings, environment variables, and private variables that are never logged), an **Agent** or **Manager** (with a user message and prompt template variables), or **AutessaDB** (a direct Insert or Update on a table, no agent involved).
- **Payload transformation** — incoming requests are reduced to a flat set of variables, either with **JSONPath** mappings (`orderId` ← `$.order.id`) or an **AutessaScript** transform that receives the raw `payload`, `headers`, and `queryParams` and returns an object. Form-encoded bodies, such as Twilio's and Slack slash commands', are read as a JSON object, so the same mappings work. Everywhere else in the form, `@@{variableName}` references substitute those variables into tool arguments, user messages, and column values.
- **Request validation** — an AutessaScript that runs on every delivery after the key or signature check, whenever the handler has one; to stop validating, remove the script. With script authentication it is the only check, and it is required. It receives `method`, `url`, `body`, `headers`, `headersLower`, and `queryParams` (keys redacted) and must return `true` or `false`; a `false` return rejects the delivery with `401`. Use it for checks the built-in signature schemes don't cover — it can verify an HMAC against an Autessa Secret with `secrets.verifyHmac` or `secrets.verifyHmacSha256`, or a public-key signature with `cryptoUtils.verifySignature`. See [Webhook scripts](/docs/api/custom-webhooks.md#webhook-scripts).
- **The reply** — by default a valid delivery gets an immediate reply with an `executionId`, and the resource runs afterwards. The status is `200` when the handler checks a sender signature or answers a handshake, and `202 Accepted` otherwise. You can change the status, content type, and body, or, for a Tool, reply with the tool's own output, such as TwiML for Twilio. See [Customizing the reply](/docs/api/custom-webhooks.md#customizing-the-reply).
- **Duplicates** — providers resend events they think you missed. Handlers checking a GitHub, Stripe, Slack, Shopify, or Svix signature drop repeats by the provider's delivery ID automatically; for others you can name the field that identifies an event. Repeats get the normal reply without running again (**DUPLICATE** in history).
- **Failures and retries** — if your transform fails, the delivery is recorded as **TRANSFORM_FAILED**; if your resource fails, as **FAILED**. Either way the sender still gets the success status, so it doesn't keep retrying or disable your endpoint. A failed resource is retried under **Execution Settings** (timeout, default 300 seconds; max retries, default 3; retry delay, default 5 seconds, doubling each attempt up to 15 minutes), showing as **RETRYING** between attempts.

## How to create a webhook handler

1. On the Webhook Handlers page, click **Create Webhook**.
2. Under **Basic Information**, name the handler (e.g. "Stripe Payment Webhook"), add a description, and leave **Enabled** checked.
3. If the sender signs its requests, choose it as the sender and pick the Autessa Secret that holds its signing secret. You need **Use** on the secret: saving adds this handler to what can use it. This switches the handler to signature authentication and fills in the matching handshake and reply settings. If the sender signs with a scheme that isn't listed, use script authentication instead (see [Any other service: scripts](#any-other-service-scripts)).
4. Optionally enable **Request Validation** and write a validation script. It is required with script authentication.
5. Under **Payload Transformation**, map the payload fields you need — JSONPath pairs for straightforward bodies, an AutessaScript transform for anything more involved. JSONPath mode requires at least one mapping.
6. Under **Resource Execution**, pick the resource type and target, then wire the extracted variables into its inputs with `@@{variableName}` references.
7. Adjust **Execution Settings** if the defaults don't fit, then click **Create Webhook**.
8. The success modal shows the full trigger URL and the API key — **copy the key now**; this is the only time it's displayed. Confirm with **I've Saved My API Key - Continue**.
9. Paste the trigger URL (and the key, unless the handler checks signatures only) into the external system's webhook settings.

## How to review deliveries

1. Click **View History** on the handler's row.
2. The table lists each execution with its ID, status, resource type, queued time, and duration. Besides **QUEUED**, **SUCCESS**, and **FAILED**, you'll see **TRANSFORM_FAILED**, **RETRYING** (failed, will run again, with the attempt number), **HANDSHAKE**, **DUPLICATE**, and **REJECTED** (failed the key, signature, or validation check, with the reason).
3. Click **View** on a row to open **Execution Details**: the HTTP method and source IP, the request headers and payload, the **Transformed Variables** your transform produced, and the **Resource Response** from the tool, agent, manager, or database operation.
4. To run a delivery again — after fixing a mapping, say — click **Replay** on it. The replay is a new execution that uses the handler's current transform, resource, and reply settings. It needs edit access to the handler, and **HANDSHAKE**, **REJECTED**, and **DUPLICATE** entries can't be replayed.

> There is no in-app "send test request" button. To test a handler, run a sample call through its real checks with [`autessa custom-webhooks test`](#test-and-replay-from-the-cli), or call its trigger URL with `curl` (or the sender's test-delivery feature) and read the outcome in execution history.

Handlers can also be shared from the edit page (**Share**) with people, teams, company roles, or everyone at your company — see [Sharing and Access](/docs/guide/platform/sharing.md). Only the owner can delete a handler, and disabled handlers reject all deliveries.

## Connect Meta / Instagram without a server

Meta (Facebook, Instagram, and WhatsApp) verifies your URL with a challenge, then signs every event with your app's App Secret. A handler can do both on its own.

1. In the Meta app dashboard, open **App settings → Basic** and copy the **App Secret**.
2. In Autessa, [create a secret](/docs/guide/agentic/secrets.md#how-to-create-a-secret) (for example `meta-app-secret`) and paste the App Secret as its value.
3. Create a webhook handler, choose **Meta** as the sender, and pick the `meta-app-secret` secret. This sets the handler to check Meta's `X-Hub-Signature-256` signature, answer Meta's verification challenge, and reply `200` to every event.
4. Set up the transformation and resource as usual, for example JSONPath `$.entry[0].changes[0].value` into an agent's user message, then save.
5. Copy the handler's trigger URL (it has no key in it) and the generated verify token.
6. Back in the Meta app dashboard, open **Webhooks**, choose the product (such as Instagram or Page), and paste the URL as the **Callback URL** and the token as the **Verify Token**. Click **Verify and save**. The check appears in the handler's history as **HANDSHAKE**.
7. Subscribe to the fields you want (comments, messages, mentions, and so on).

From then on, each event appears in the handler's execution history and runs your resource. The settings the Meta sender fills in, as they appear in the [webhook config](/docs/api/poweruser/custom-webhooks.md#the-webhookconfig-object):

```json
{
  "authMode": "SIGNATURE",
  "signatureConfig": { "scheme": "META", "secretName": "meta-app-secret" },
  "handshakeConfig": { "preset": "META", "verifyToken": "4f9c2d7e1a6b8053" }
}
```

With a signature and handshake configured, the reply status is `200` by default, which is what Meta expects.

## Recipes

Each recipe shows the authentication, handshake, reply, and duplicate settings as they appear in the [webhook config](/docs/api/poweruser/custom-webhooks.md#the-webhookconfig-object); add your own transformation and resource. In every case, store the provider's signing secret as an [Autessa Secret](/docs/guide/agentic/secrets.md) first and give the provider the plain trigger URL, without a key. Signature-checked handlers reply `200` by default.

### Stripe

In the Stripe dashboard, add an endpoint under **Developers → Webhooks** with the trigger URL, choose your events, and copy the endpoint's signing secret (`whsec_...`) into an Autessa Secret. Stripe retries unacknowledged events; the handler drops repeats by the event `id` automatically.

```json
{
  "authMode": "SIGNATURE",
  "signatureConfig": { "scheme": "STRIPE", "secretName": "stripe-signing-secret" },
  "payloadTransformConfig": {
    "transformType": "JSONPATH",
    "jsonPathMappings": { "eventType": "$.type", "objectId": "$.data.object.id" }
  }
}
```

### GitHub

In the repository's **Settings → Webhooks**, add a webhook with the trigger URL, content type `application/json`, and a secret of your choosing; store the same value as an Autessa Secret. Redeliveries are dropped by the `X-GitHub-Delivery` header automatically.

```json
{
  "authMode": "SIGNATURE",
  "signatureConfig": { "scheme": "GITHUB", "secretName": "github-webhook-secret" },
  "payloadTransformConfig": {
    "transformType": "JSONPATH",
    "jsonPathMappings": { "action": "$.action", "repo": "$.repository.full_name" }
  }
}
```

### Slack (Events API)

In your Slack app, copy the **Signing Secret** from **Basic Information** into an Autessa Secret. Under **Event Subscriptions**, paste the trigger URL as the **Request URL**; the handler answers Slack's `url_verification` challenge right away. Slack's retries are dropped by `event_id` automatically.

```json
{
  "authMode": "SIGNATURE",
  "signatureConfig": { "scheme": "SLACK", "secretName": "slack-signing-secret" },
  "handshakeConfig": { "preset": "SLACK" },
  "payloadTransformConfig": {
    "transformType": "JSONPATH",
    "jsonPathMappings": { "text": "$.event.text", "channel": "$.event.channel", "user": "$.event.user" }
  }
}
```

### Twilio (reply with TwiML)

Store your Twilio account's **Auth Token** as an Autessa Secret. On the phone number's messaging settings, set **A message comes in** to the trigger URL, exactly as Autessa shows it — Twilio signs the full URL, so any difference fails the check.

Twilio waits for your reply to decide what to text back, so use a Tool resource with `HANDLER_OUTPUT`. Twilio's form-encoded fields (`Body`, `From`, and so on) map with JSONPath like JSON:

```json
{
  "authMode": "SIGNATURE",
  "signatureConfig": { "scheme": "TWILIO", "secretName": "twilio-auth-token" },
  "responseConfig": { "mode": "HANDLER_OUTPUT", "syncTimeoutSeconds": 10 },
  "payloadTransformConfig": {
    "transformType": "JSONPATH",
    "jsonPathMappings": { "from": "$.From", "message": "$.Body" }
  },
  "resourceExecutionConfig": {
    "resourceType": "TOOL",
    "resourceId": "your-tool-id",
    "variables": { "from": "@@{from}", "message": "@@{message}" }
  }
}
```

The tool returns the reply as an object with `status`, `contentType`, and `body`:

```json
{
  "status": 200,
  "contentType": "text/xml",
  "body": "<Response><Message>Thanks! We'll get back to you shortly.</Message></Response>"
}
```

If the tool fails, Twilio gets a `500`. If it takes longer than `syncTimeoutSeconds`, Twilio gets the plain acknowledgement instead and the tool finishes in the background; it never runs twice.

### Clean links in messages (redirects)

To share a link in DMs, emails, or posts that runs a handler and then sends the visitor on, use a **public link** with a **redirect** reply. The link has no key in it, so it looks clean and is safe to share:

```
https://api.autessa.com/w/{webhookId}
```

For one destination, set it in the handler. In the app, choose **Public link** under Authentication and fill in **Redirect to** under Reply. In JSON:

```json
{
  "authMode": "PUBLIC",
  "responseConfig": {
    "statusCode": 302,
    "headers": { "Location": "https://example.com/landing-page" }
  }
}
```

Each click runs the handler in the background, for example to record it in an AutessaDB table, while the visitor goes straight to the page.

To send different links to different places from one handler:

1. Add a word after the ID, such as `https://api.autessa.com/w/{webhookId}/summer-sale`.
2. Map the script variable `path` (here `/summer-sale`) to a handler variable with an AutessaScript transform.
3. Run a Tool with **Return the tool's output**, and have it return the destination:

```json
{
  "status": 302,
  "headers": { "Location": "https://example.com/offers/summer-sale" }
}
```

A public link accepts only normal visits (`GET`), and each visitor can open it up to 30 times a minute. Chat apps open links to build previews, so expect those visits too. See [Redirects](/docs/api/custom-webhooks.md#redirects) and [Public link](/docs/api/custom-webhooks.md#public-link).

## Any other service: scripts

A sender whose signature scheme isn't built in can still call the handler directly: you check its signature, and answer its handshake, with a short script. Set `authMode` to `SCRIPT`, and the handler's validation script decides whether each call is accepted; there is no key in the URL, and the handler can't be saved without the script. When the sender's handshake needs a computed answer or a call back to the sender, add a handshake script (`handshakeConfig.script`) as well. The script variables, helpers, and return values are listed in [Webhook scripts](/docs/api/custom-webhooks.md#webhook-scripts).

In each recipe below, the scripts go into the config as strings: the validation script in `validationConfig.validationScript`, and the handshake script in `handshakeConfig.script`. Replace the `YOUR_...` placeholders, store any shared secret as an [Autessa Secret](/docs/guide/agentic/secrets.md) under the name the script uses, and add your own transformation and resource. A script-authenticated handler with no `handshakeConfig` replies `202` by default; set `responseConfig.statusCode` to `200` if the sender expects it. Before you point the sender at the handler, try it with [`custom-webhooks test`](#test-and-replay-from-the-cli).

> A handshake is answered before the validation script runs. A handshake script that answers or acts on a call checks the sender's signature itself, as the Discord, Twitch, and AWS SNS scripts below do.

### Discord (interactions)

Discord signs each interaction with Ed25519 over the timestamp plus the body, and checks a new URL with a `PING` that must be answered with `{"type": 1}`. The public key is the app's **Public Key** from the Developer Portal (hex). For slash-command replies, use a Tool resource with `HANDLER_OUTPUT`.

```json
{
  "authMode": "SCRIPT",
  "validationConfig": { "enableValidation": true, "validationScript": "…validation script…" },
  "handshakeConfig": { "script": "…handshake script…" },
  "responseConfig": { "mode": "HANDLER_OUTPUT" },
  "resourceExecutionConfig": { "resourceType": "TOOL", "resourceId": "your-tool-id" }
}
```

Validation script:

```js
const PUBLIC_KEY = 'YOUR_DISCORD_PUBLIC_KEY_HEX';
const h = JSON.parse(variables.get('headersLower'));
const ok = cryptoUtils.verifySignature('ED25519', PUBLIC_KEY,
    (h['x-signature-timestamp'] || '') + variables.get('body'), h['x-signature-ed25519'] || '00', 'HEX');
response.setResponse(String(ok));
```

Handshake script:

```js
const PUBLIC_KEY = 'YOUR_DISCORD_PUBLIC_KEY_HEX';
const body = JSON.parse(variables.get('body') || '{}');
if (body.type === 1) {
  const h = JSON.parse(variables.get('headersLower'));
  const ok = cryptoUtils.verifySignature('ED25519', PUBLIC_KEY,
      (h['x-signature-timestamp'] || '') + variables.get('body'), h['x-signature-ed25519'] || '00', 'HEX');
  if (!ok) throw new Error('invalid request signature');
  response.setResponse(JSON.stringify({ status: 200, contentType: 'application/json', body: JSON.stringify({ type: 1 }) }));
}
```

The tool answers a slash command by returning the reply:

```json
{"status":200,"contentType":"application/json","body":"{\"type\":4,\"data\":{\"content\":\"hi\"}}"}
```

### Twitch EventSub

Twitch signs each message with an HMAC-SHA256 over the message ID, the timestamp, and the body, and checks a new subscription with a `webhook_callback_verification` message whose `challenge` must be echoed back. Store the EventSub subscription's `secret` as the Autessa Secret `twitch-eventsub-secret`.

```json
{
  "authMode": "SCRIPT",
  "validationConfig": { "enableValidation": true, "validationScript": "…validation script…" },
  "handshakeConfig": { "script": "…handshake script…" }
}
```

Validation script:

```js
const h = JSON.parse(variables.get('headersLower'));
const message = (h['twitch-eventsub-message-id'] || '') + (h['twitch-eventsub-message-timestamp'] || '') + variables.get('body');
response.setResponse(String(secrets.verifyHmac('twitch-eventsub-secret', message,
    h['twitch-eventsub-message-signature'] || '', { algorithm: 'SHA256', encoding: 'HEX', prefix: 'sha256=' })));
```

Handshake script:

```js
const h = JSON.parse(variables.get('headersLower'));
if (h['twitch-eventsub-message-type'] === 'webhook_callback_verification') {
  const message = (h['twitch-eventsub-message-id'] || '') + (h['twitch-eventsub-message-timestamp'] || '') + variables.get('body');
  if (!secrets.verifyHmac('twitch-eventsub-secret', message, h['twitch-eventsub-message-signature'] || '',
      { algorithm: 'SHA256', encoding: 'HEX', prefix: 'sha256=' })) throw new Error('bad signature');
  response.setResponse(JSON.parse(variables.get('body')).challenge);
}
```

### Twitter / X (Account Activity)

X signs deliveries as `x-twitter-webhooks-signature: sha256=<base64 HMAC of the body, keyed by the consumer secret>`, which the built-in `GENERIC_HMAC` scheme covers, so this handler uses `SIGNATURE` mode. Store the app's consumer secret as the Autessa Secret `x-consumer-secret`. The `X` handshake preset answers the CRC check (a `GET` with a `crc_token`) for you with the same secret.

```json
{
  "authMode": "SIGNATURE",
  "signatureConfig": {
    "scheme": "GENERIC_HMAC",
    "secretName": "x-consumer-secret",
    "header": "x-twitter-webhooks-signature",
    "encoding": "BASE64",
    "prefix": "sha256="
  },
  "handshakeConfig": { "preset": "X", "secretName": "x-consumer-secret" }
}
```

X doesn't sign its CRC check, and the CRC answer has the same shape as a delivery signature. So that no one can use the check to get a signature for a fake delivery, the preset refuses a `crc_token` that contains `{` or `[` or is longer than 512 characters. Real CRC tokens never do.

### SendGrid (signed Event Webhook)

SendGrid's Signed Event Webhook signs the timestamp plus the body with ECDSA P-256. The public key is the **Verification Key** from SendGrid's Signed Event Webhook settings (base64).

```json
{
  "authMode": "SCRIPT",
  "validationConfig": { "enableValidation": true, "validationScript": "…validation script…" }
}
```

Validation script:

```js
const PUBLIC_KEY = 'YOUR_SENDGRID_VERIFICATION_KEY_BASE64';
const h = JSON.parse(variables.get('headersLower'));
const ok = cryptoUtils.verifySignature('ECDSA_P256_SHA256', PUBLIC_KEY,
    (h['x-twilio-email-event-webhook-timestamp'] || '') + variables.get('body'),
    h['x-twilio-email-event-webhook-signature'] || 'AA==');
response.setResponse(String(ok));
```

### PayPal

PayPal signs `transmission id|transmission time|webhook id|CRC32 of the body` with RSA, using a certificate it hosts. `WEBHOOK_ID` is the ID PayPal shows for this webhook. The script fetches the certificate only from PayPal's own hosts.

```json
{
  "authMode": "SCRIPT",
  "validationConfig": { "enableValidation": true, "validationScript": "…validation script…" }
}
```

Validation script:

```js
const WEBHOOK_ID = 'YOUR_PAYPAL_WEBHOOK_ID';
const h = JSON.parse(variables.get('headersLower'));
const message = [h['paypal-transmission-id'], h['paypal-transmission-time'], WEBHOOK_ID,
    cryptoUtils.crc32(variables.get('body'))].join('|');
const cert = cryptoUtils.fetchCertificate(h['paypal-cert-url'], ['api.paypal.com', 'api-m.paypal.com', 'api.sandbox.paypal.com', 'api-m.sandbox.paypal.com']);
response.setResponse(String(cryptoUtils.verifySignature('RSA_SHA256', cert, message, h['paypal-transmission-sig'] || 'AA==')));
```

### AWS SNS (HTTPS subscription)

SNS signs every message with a certificate it hosts, and confirms a new subscription by sending a `SubscriptionConfirmation` whose `SubscribeURL` you must call. SNS sends `Content-Type: text/plain` with a JSON body. The event itself is in the message's `Message` field, so use an `AUTESSA_SCRIPT` transform that reads it with `JSON.parse(JSON.parse(variables.get('payload')).Message)`.

```json
{
  "authMode": "SCRIPT",
  "validationConfig": { "enableValidation": true, "validationScript": "…validation script…" },
  "handshakeConfig": { "script": "…handshake script…" },
  "payloadTransformConfig": { "transformType": "AUTESSA_SCRIPT", "transformScript": "…your transform…" }
}
```

Validation script, which also verifies the confirmation messages:

```js
const m = JSON.parse(variables.get('body'));
const fields = m.Type === 'Notification'
    ? ['Message', 'MessageId', 'Subject', 'Timestamp', 'TopicArn', 'Type']
    : ['Message', 'MessageId', 'SubscribeURL', 'Timestamp', 'Token', 'TopicArn', 'Type'];
let stringToSign = '';
for (const f of fields) { if (m[f] !== undefined) stringToSign += f + '\n' + m[f] + '\n'; }
const cert = cryptoUtils.fetchCertificate(m.SigningCertURL, ['sns.*.amazonaws.com']);
const alg = m.SignatureVersion === '2' ? 'RSA_SHA256' : 'RSA_SHA1';
response.setResponse(String(cryptoUtils.verifySignature(alg, cert, stringToSign, m.Signature)));
```

Handshake script, which confirms the subscription. The validation script has not run at this point, so it verifies the signature here too:

```js
const h = JSON.parse(variables.get('headersLower'));
if (h['x-amz-sns-message-type'] === 'SubscriptionConfirmation') {
  const m = JSON.parse(variables.get('body'));
  let stringToSign = '';
  for (const f of ['Message', 'MessageId', 'SubscribeURL', 'Timestamp', 'Token', 'TopicArn', 'Type']) {
    if (m[f] !== undefined) stringToSign += f + '\n' + m[f] + '\n';
  }
  const cert = cryptoUtils.fetchCertificate(m.SigningCertURL, ['sns.*.amazonaws.com']);
  const alg = m.SignatureVersion === '2' ? 'RSA_SHA256' : 'RSA_SHA1';
  if (!cryptoUtils.verifySignature(alg, cert, stringToSign, m.Signature)) throw new Error('bad SNS signature');
  const host = m.SubscribeURL.split('/')[2];
  if (!/^sns\.[a-z0-9-]+\.amazonaws\.com$/.test(host)) throw new Error('unexpected SubscribeURL host');
  const r = JSON.parse(api.get(JSON.stringify({ endpoint: m.SubscribeURL })));
  if (r.statusCode !== 200) throw new Error('confirmation failed: ' + r.statusCode);
  response.setResponse('confirmed');
}
```

## Test and replay from the CLI

The [Autessa CLI](/docs/cli/webhooks-and-queues.md) can store a signing secret, create a handler from a config file, run a sample call through the handler without the sender, and run a stored delivery again:

```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>
```

- **`autessa secrets create`** stores a sender's signing secret as an [Autessa Secret](/docs/guide/agentic/secrets.md); signature checks and scripts refer to it by name.
- **`custom-webhooks test`** sends a sample call through the handler's real checks: the handshake (including a handshake script), the key or signature, the validation script, and the transform. It returns the outcome (`HANDSHAKE`, `REJECTED`, or `ACCEPTED`), each step it went through in plain language, the reason for a rejection, the variables the transform produced, and the exact reply the sender would get. By default it is a dry run: the handler doesn't run and nothing is added to history. With `--run true` the call really runs, exactly like a delivery from the sender. It needs edit access to the handler.
- Handshake scripts **do run** during a dry run, including any call they make back to the sender, such as an AWS SNS subscription confirmation.
- Pass the body with `--body @file` so a signed sample stays byte-exact and its signature still verifies. An inline JSON value is re-serialized, which changes the bytes. To debug a refusal, paste a real delivery's headers and body.
- **`custom-webhooks replay`** runs a stored delivery again with the handler's current settings, like **Replay** in the history. It needs edit access, and `HANDSHAKE`, `REJECTED`, and `DUPLICATE` entries can't be replayed.

## Sharing and access levels

Every handler starts **private** to its owner. Share it with people, teams, company roles, or everyone at your company, each at its own level, from the [Share dialog](/docs/guide/platform/sharing.md). Access adds up, so someone covered by several grants gets the highest one. What each level allows:

| Level | What it lets a teammate do |
| --- | --- |
| READ | View the handler |
| WRITE | Edit the handler and replay deliveries |
| PUBLISH | Same as WRITE — handlers have no publish step |
| ADMIN | Share the handler and regenerate its API key |

Deleting a handler is owner-only — ADMIN is not enough. The owner always has ADMIN implicitly.

## Related

- [Custom Webhooks API](/docs/api/custom-webhooks.md) — trigger URL, authentication, signatures, handshakes, scripts, and the reply
- [Custom Webhooks (Poweruser API)](/docs/api/poweruser/custom-webhooks.md) — managing handlers programmatically
- [Secrets](/docs/guide/agentic/secrets.md) — storing signing secrets
- [Webhooks and Queues (CLI)](/docs/cli/webhooks-and-queues.md)
- [API Keys](/docs/guide/api-management/api-keys.md)
- [Tools](/docs/guide/agentic/tools.md)
- [Triggers](/docs/guide/autessadb/triggers.md)

