# Webhooks

> Waddle posts your notes to other apps as you save them, signed the Standard Webhooks way, and tries again when the app is down.

## Add one

Webhooks are added and changed only in Waddle's Preferences → Webhooks: give it an address, and pick which notes go (folders, `#tags`, meetings from a calendar, with rules and a "never" list). No agent, script or API can add one, so nothing can route your notes off your Mac without you.

Turn on **Ask me first** for anything sensitive: each send waits in Waddle for your yes.

## What arrives

A POST with a JSON body in the [Standard Webhooks](https://www.standardwebhooks.com) shape, so an existing library can read it:

```json
{
  "type": "note.saved",
  "timestamp": "2026-11-23T09:41:00.000Z",
  "data": {
    "note": { "path": "meetings/standup 23 nov.md", "folder": "meetings", "title": "standup 23 nov", "tags": ["work"], "edited": "2026-11-23T09:40:41.000Z", "markdown": "# standup 23 nov\n\n…" },
    "created": true
  }
}
```

| Type | When | `data` |
|---|---|---|
| `note.saved` | A note stopped changing for 20 seconds, or you left it | `note` (path, folder, title, tags, edited, markdown), `created` |
| `note.moved` | Moved or renamed | `from`, and the `note` at its new path |
| `note.trashed` | Into the Trash | `note` (path, folder, title, tags), no text |
| `meeting.noted` | A meeting note was written | `note`, `meeting` (title, calendar, started, minutes, people) |
| `meeting.summarised` | A meeting's summary was written (Waddle Club; off until you turn it on per webhook) | `note`, `summary` |
| `waddle.test` | You pressed Send a test | `message`, `webhook` |

A note's `path` is the id to key on. Only the newest version of a note is ever waiting: a newer save replaces it.

## Check the signature

Each request has `webhook-id`, `webhook-timestamp` and `webhook-signature` headers. The signature is `v1,` and the base64 HMAC-SHA256 of `id.timestamp.body`, keyed with your secret's bytes (the part after `whsec_`, base64). Preferences copies the secret for you.

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

/** True if Waddle sent this body. `secret` is the whsec_… from Preferences. */
export function fromWaddle(secret, headers, body) {
  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
  const want = createHmac('sha256', key).update(`${headers['webhook-id']}.${headers['webhook-timestamp']}.${body}`).digest('base64');
  return (headers['webhook-signature'] ?? '').split(' ').some((s) => {
    const [v, sig = ''] = s.split(',');
    return v === 'v1' && sig.length === want.length && timingSafeEqual(Buffer.from(sig), Buffer.from(want));
  });
}
```

Use the body exactly as it arrived, before parsing it. You can also add one header of your own to every request (for an app that wants `Authorization: Bearer …`).

## Delivery

- **Retries:** a network error, a timeout (15 seconds), 408, 429 or a 5xx tries again in 1 minute, 5, 30, then hourly, for 24 hours. `Retry-After` is honoured.
- **Any other 4xx** means your app said no: Waddle stops and waits for an edit or Try now, and walks over once if retrying won't help.
- **Redirects aren't followed.** A 3xx is a failure, so a send can't be bounced somewhere else.
- **In order.** One send at a time per webhook, so a move never overtakes the save before it. Offline or asleep, the clock stops, and the queue survives a quit.
- **https only,** except to this Mac (`localhost`, `127.0.0.1`, `::1`), which may be http.
- `User-Agent: Waddle/<version>`.

Waddle keeps a record of the last 200 sends per webhook (when, the type, the path, the status, how long), never the note's text.
