HTTP API: register, list and remove webhooks, kept across restarts #6

Open
opened 2026-09-28 11:10:25 +02:00 by clawbot · 0 comments

Part of #2. Builds on #5 and starts from next once that is merged.

What. An external app registers webhooks on a chat, lists them, and removes one. Registrations survive a restart. Posting messages to them is the next unit.

Decisions (reversible, taken by the repo-manager):

  • POST /api/v1/chats/{id}/webhooks with {"url":"..."} returns 201 and {"id":"...","chat_id":{id},"url":"..."}; the id is 16 random bytes in hex. The URL must be absolute http or https with a host, at most 2048 bytes; otherwise 400. A chat that is not one of the bot's contacts is 404. The same URL already registered on that chat returns 200 with the existing registration.
  • GET /api/v1/chats/{id}/webhooks returns {"webhooks":[...]}. DELETE /api/v1/chats/{id}/webhooks/{webhook_id} returns 204, or 404.
  • Kept in $DATA_DIR/webhooks.json, mode 0600, rewritten whole on each change through a temporary file in the same directory and a rename, so a crash leaves the old file or the new one, never half of one. Read at startup: absent means no webhooks; present but unparseable aborts startup, like configuration.
  • Safe for concurrent use: requests run concurrently.
  • A deleted contact's webhooks stay until removed; they never fire.

Done when:

  • Tests cover register, the repeat, list, remove, the 400 and 404 cases, and a registration surviving a new store read from the same directory.
  • README: the three endpoints in the API section with curl examples, and the file under Operating it (Backup). docs/TODO.md Completed Steps gets a line.
  • make check is green.

Model: opus-5-5

Part of https://git.eeqj.de/sneak/simplexcalc/issues/2. Builds on https://git.eeqj.de/sneak/simplexcalc/issues/5 and starts from `next` once that is merged. **What.** An external app registers webhooks on a chat, lists them, and removes one. Registrations survive a restart. Posting messages to them is the next unit. **Decisions** (reversible, taken by the repo-manager): - `POST /api/v1/chats/{id}/webhooks` with `{"url":"..."}` returns `201` and `{"id":"...","chat_id":{id},"url":"..."}`; the id is 16 random bytes in hex. The URL must be absolute `http` or `https` with a host, at most 2048 bytes; otherwise `400`. A chat that is not one of the bot's contacts is `404`. The same URL already registered on that chat returns `200` with the existing registration. - `GET /api/v1/chats/{id}/webhooks` returns `{"webhooks":[...]}`. `DELETE /api/v1/chats/{id}/webhooks/{webhook_id}` returns `204`, or `404`. - Kept in `$DATA_DIR/webhooks.json`, mode 0600, rewritten whole on each change through a temporary file in the same directory and a rename, so a crash leaves the old file or the new one, never half of one. Read at startup: absent means no webhooks; present but unparseable aborts startup, like configuration. - Safe for concurrent use: requests run concurrently. - A deleted contact's webhooks stay until removed; they never fire. **Done when:** - Tests cover register, the repeat, list, remove, the `400` and `404` cases, and a registration surviving a new store read from the same directory. - README: the three endpoints in the API section with `curl` examples, and the file under Operating it (Backup). `docs/TODO.md` Completed Steps gets a line. - `make check` is green. Model: opus-5-5
clawbot added a new dependency 2026-09-28 11:10:29 +02:00
clawbot added a new dependency 2026-09-28 11:10:30 +02:00
clawbot added a new dependency 2026-09-28 11:10:30 +02:00
clawbot self-assigned this 2026-09-28 11:10:30 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sneak/simplexcalc#6