Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Webhooks Phase 3: admin-guide docs and roadmap update (#275)

Murtaza Nasir85ccec8ab312
diff --git a/docs/admin-guide/webhooks.md b/docs/admin-guide/webhooks.md
new file mode 100644
index 00000000..a9611ff0
--- /dev/null
+++ b/docs/admin-guide/webhooks.md
@@ -0,0 +1,188 @@
+# Webhooks
+
+Speakr can POST a signed JSON envelope to any HTTPS URL when a
+recording's lifecycle changes. Use it to push events into automation
+flows (n8n, Make, Zapier), home dashboards, or any service that
+prefers push over polling `GET /api/v1/recordings`.
+
+Webhooks are configured per-user from **Account settings → Webhooks**,
+or programmatically via the `/api/v1/webhooks` API.
+
+## Event vocabulary
+
+| Event | Fired when | Payload `data` fields |
+|---|---|---|
+| `recording.created` | A recording row is created (upload arrived) | `recording_id`, `title`, `file_size`, `original_filename` |
+| `recording.transcription.completed` | Transcription job finished successfully | `recording_id`, `title`, `language`, `audio_duration_seconds`, `transcription_duration_seconds` |
+| `recording.transcription.failed` | Transcription failed permanently (retries exhausted) | `recording_id`, `title`, `error` |
+| `recording.summary.completed` | Summary generated successfully | `recording_id`, `title`, `summarization_duration_seconds` |
+| `recording.summary.failed` | Summary failed permanently | `recording_id`, `title`, `error` |
+| `recording.events.extracted` | Calendar event extraction finished and produced at least one event | `recording_id`, `events_count` |
+| `recording.updated` | Title, tags, folder, notes, or speakers changed (debounced; one per recording per 30 s) | `recording_id`, `fields_changed` |
+| `recording.deleted` | Recording removed | `recording_id`, `title` |
+| `webhook.test` | Synthetic event from the **Test** button or `POST /api/v1/webhooks/{id}/test` | `reason`, `webhook_id` |
+
+Only `recording.created`, `recording.transcription.*`, `recording.summary.*`,
+and `recording.deleted` are wired in the current backend. The remaining
+events are reserved in the vocabulary and will fire as the corresponding
+code paths gain webhook emission.
+
+## Envelope
+
+Every delivery is a `POST` with a JSON body shaped like:
+
+```json
+{
+ "id": "f4e6a4e1-3b9b-4a04-9d4f-0e7a5d8b3c10",
+ "type": "recording.transcription.completed",
+ "timestamp": "2026-06-04T15:23:11.124Z",
+ "user_id": 42,
+ "data": {
+ "recording_id": 9173,
+ "title": "Q3 planning",
+ "language": "en",
+ "audio_duration_seconds": 3624.7
+ }
+}
+```
+
+Headers:
+
+| Header | Purpose |
+|---|---|
+| `Content-Type: application/json` | Body format |
+| `User-Agent: Speakr-Webhook/1.0` | Identifies Speakr to receivers |
+| `Speakr-Event` | The event type — useful for routing without parsing the body |
+| `Speakr-Delivery-Id` | UUID echo of `data.id` — receivers use it for idempotency |
+| `Speakr-Timestamp` | ISO-8601 UTC of dispatch — receivers may reject stale deliveries |
+| `Speakr-Signature` | `sha256=<hex>` HMAC of the raw body with the webhook's secret |
+
+## Signature verification
+
+Every receiver must verify the `Speakr-Signature` header before
+trusting the body. Failure to verify means anyone who guesses the URL
+can forge events.
+
+### Python
+
+```python
+import hmac
+import hashlib
+
+def verify_speakr(secret: str, raw_body: bytes, signature_header: str) -> bool:
+ if not signature_header.startswith('sha256='):
+ return False
+ expected = hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
+ given = signature_header[len('sha256='):]
+ return hmac.compare_digest(expected, given)
+```
+
+### Node.js
+
+```js
+const crypto = require('crypto');
+
+function verifySpeakr(secret, rawBody, signatureHeader) {
+ if (!signatureHeader || !signatureHeader.startsWith('sha256=')) return false;
+ const expected = crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
+ const given = signatureHeader.slice('sha256='.length);
+ try {
+ return crypto.timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(given, 'hex'));
+ } catch (_) {
+ return false;
+ }
+}
+```
+
+### Bash (for sanity-checking)
+
+```bash
+echo -n "$RAW_BODY" | openssl dgst -sha256 -hmac "$SECRET" | awk '{print "sha256="$2}'
+```
+
+Compare the output against the `Speakr-Signature` header value.
+
+## Retry policy
+
+Delivery attempts use the following backoff schedule:
+
+| Attempt | Delay before this attempt |
+|---|---|
+| 1 | immediate |
+| 2 | 30 s |
+| 3 | 2 min |
+| 4 | 10 min |
+| 5 | 1 hour |
+
+After attempt 5, status flips to `permanent_failure` and the webhook's
+`consecutive_failures` counter increments. When it reaches
+`WEBHOOK_AUTOPAUSE_FAILURES` (default 10) the webhook is auto-paused; the
+user must manually re-enable it.
+
+**Retryable HTTP responses:** 408, 429, 5xx, plus network errors and
+timeouts.
+**Non-retryable:** 2xx (success), 3xx (we disable `allow_redirects` on
+purpose), 4xx other than 408/429.
+
+A successful delivery (2xx) resets `consecutive_failures` to 0.
+
+## SSRF guard
+
+Webhook URLs are validated at save time and again at dispatch time:
+
+- Scheme must be `http://` or `https://`. `http://` is rejected unless
+ the webhook has `allow_http=true`.
+- The hostname is resolved; if any returned address is private
+ (RFC 1918, link-local, loopback, multicast, reserved), the URL is
+ rejected.
+- Operators can carve out internal hosts via
+ `WEBHOOK_INTRANET_HOST_ALLOWLIST` — a regex matched against the
+ hostname.
+
+This prevents accidentally pointing a webhook at an internal service
+(metadata endpoints, admin consoles) that should not receive Speakr
+payloads.
+
+## Configuration
+
+| Env var | Default | Purpose |
+|---|---|---|
+| `WEBHOOK_GLOBAL_ENABLED` | `true` | Admin kill switch. Set to `false` to disable all dispatch system-wide. |
+| `WEBHOOK_MAX_PER_USER` | `10` | Hard cap on webhooks per user. |
+| `WEBHOOK_DELIVERY_TIMEOUT_SECONDS` | `10` | Per-attempt HTTP timeout. |
+| `WEBHOOK_MAX_ATTEMPTS` | `5` | Retry cap before `permanent_failure`. |
+| `WEBHOOK_AUTOPAUSE_FAILURES` | `10` | Consecutive failures before auto-pause. |
+| `WEBHOOK_DISPATCHER_INTERVAL_SECONDS` | `5` | How often the dispatcher polls for due deliveries. |
+| `WEBHOOK_INTRANET_HOST_ALLOWLIST` | empty | Regex of allowed private hosts. Empty = SSRF block always applies. |
+
+## API surface
+
+All endpoints under `/api/v1/webhooks` require an authenticated session
+or an API token. The OpenAPI schema documents every field.
+
+| Method | Path | Purpose |
+|---|---|---|
+| GET | `/api/v1/webhooks` | List the caller's webhooks. Returns `event_types` + `max_per_user` for UI rendering. |
+| POST | `/api/v1/webhooks` | Create a webhook. Response includes the secret **once**; capture it. |
+| GET | `/api/v1/webhooks/{id}` | Read one. Secret is never returned. |
+| PATCH | `/api/v1/webhooks/{id}` | Update name / url / events / enabled / allow_http. |
+| DELETE | `/api/v1/webhooks/{id}` | Delete (cascades to deliveries). |
+| POST | `/api/v1/webhooks/{id}/rotate-secret` | Generate a fresh HMAC secret. Returned once. |
+| POST | `/api/v1/webhooks/{id}/test` | Queue a synthetic `webhook.test` delivery. |
+| GET | `/api/v1/webhooks/{id}/deliveries` | Recent deliveries (default 50, max 200). |
+| GET | `/api/v1/webhooks/{id}/deliveries/{did}` | Full delivery record including the original payload. |
+| POST | `/api/v1/webhooks/{id}/deliveries/{did}/replay` | Re-fire the payload as a new delivery. |
+
+## Operational notes
+
+- The dispatcher runs in a daemon thread inside the Speakr web process.
+ In multi-worker Gunicorn setups, every worker runs its own dispatcher;
+ the dispatcher polls the database with a small batch limit so the
+ total outbound throughput is naturally bounded.
+- `webhook_delivery` rows accumulate over time. There is no automatic
+ pruning yet — operators should run a periodic delete of rows older
+ than a month or two when the table grows large. A future release
+ will add a retention sweep similar to the recording-session cleanup.
+- Auto-paused webhooks stay in the database with `enabled=false`,
+ `auto_paused=true`. The user re-enables manually after fixing their
+ receiver; that also clears the `auto_paused` flag.
diff --git a/docs/roadmap.md b/docs/roadmap.md
index 126c7266..44369b00 100644
--- a/docs/roadmap.md
+++ b/docs/roadmap.md
@@ -38,47 +38,32 @@ These are landed locally and waiting on release:
no longer requires an email-verification round-trip
(issue #288, PR #289 by checkmeck).
-## Designed, implementation pending
+## Built, awaiting release
-These have a complete architecture proposal and a phasing plan. Each one
-is a multi-day effort and will land in its own release once started.
+Both of the features that used to live in this section have been
+implemented and are waiting on the next tagged release:
-### Server-side recording chunks (issue #287 c/d)
+### Server-side recording chunks (issue #287 c/d) — built
-Stream recording chunks to the server during recording instead of
-holding the entire audio blob in browser RAM. Removes the current 200 MB
-client-side cap, makes browser-crash recovery reliable on arbitrarily
-long recordings, and replaces the soft-stop behaviour with a quota
-based on per-user server-side storage.
+Streams recording chunks to the server during recording. The 200 MB
+cap is replaced by a configurable hours-based ceiling. Crash recovery
+on reload prompts the user to finalize whatever was already uploaded.
+Off by default until enabled with `ENABLE_SERVER_RECORDING_CHUNKS=true`.
-**Scope:** new `recording_session` table; `/upload/session*` endpoints
-for create / chunk-POST / status / finalize / abort; APScheduler-driven
-cleanup of expired sessions; client rewire of the recording stack to
-stream chunks with retry; resume-on-reload prompt; replacement of the
-hard 200 MB cap with a soft warning + absolute hours ceiling.
+Full setup, env-var reference, reverse-proxy guidance, and on-disk
+layout in [Recording Sessions](admin-guide/recording-sessions.md).
-**Estimated effort:** 3 phases, roughly 5-7 days of focused work.
+### Webhooks (issue #275) — built
-### Webhooks (issue #275)
+Push-based notifications on recording lifecycle events. Each user
+manages their own webhook endpoints from Account settings → Webhooks
+(or programmatically via `/api/v1/webhooks`). HMAC-SHA256 signatures,
+SSRF guard against private IPs, exponential-backoff retries with
+auto-pause after 10 consecutive failures.
-Push-based notifications on recording lifecycle events. Eliminates
-polling for companion apps (n8n flows, home dashboards, automation
-scripts).
-
-**Scope:** per-user webhook endpoints model (multiple per user, named,
-toggleable, per-event subscription); HMAC-SHA256 signing with
-`Speakr-Signature` / `Speakr-Delivery-Id` headers; retry policy with
-exponential backoff and auto-pause; SSRF guard against internal URLs;
-account-settings UI for create/edit/test-fire/recent-deliveries; admin
-overview; v1 CRUD API with OpenAPI parity.
-
-**Event vocabulary (initial set):** `recording.created`,
-`recording.transcription.started`, `recording.transcription.completed`,
-`recording.transcription.failed`, `recording.summary.completed`,
-`recording.summary.failed`, `recording.events.extracted`,
-`recording.updated`, `recording.deleted`.
-
-**Estimated effort:** 3 phases, roughly 2.5 days of focused work.
+Event types, signature verification examples in Python/Node/bash,
+retry schedule, and env-var reference in
+[Webhooks](admin-guide/webhooks.md).
## Open ideas (not yet designed)
diff --git a/mkdocs.yml b/mkdocs.yml
index cad8239d..0538f785 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -178,6 +178,7 @@ nav:
- Default Prompts: admin-guide/prompts.md
- Vector Store: admin-guide/vector-store.md
- Recording Sessions: admin-guide/recording-sessions.md
+ - Webhooks: admin-guide/webhooks.md
- Migration Guide: admin-guide/migration-guide.md
- Troubleshooting: troubleshooting.md