feat(automations): make the webhook trigger fire — inbound bearer route, token generation, row UI
Merged
SA
3mo ago+514+514+012345678901234567890123456789-8-8-0123456789
Summary
The webhook trigger kind existed on main as a row that could never fire: no inbound route, no token, no UI. This PR adds all three.
- API
POST /api/automations/webhook/{automationId}— verifiesAuthorization: Bearer sset_wh_…against every enabled webhook trigger on the automation before reading the body (SHA-256 hash inautomation_triggers.secret_hash, constant-time compare; 401 on miss;sset_wh_prefix precheck and a 300/min per-automation rate limit sit before the trigger query), records the JSON body verbatim inautomation_events(provider=webhook,event_type=webhook.received, fresh uuidexternal_event_id), then hands off to the shareddispatchMatchingTriggers({…, automationId}). No dedupe — measured against the reference: one authenticated POST is one event and one run,Idempotency-Keyis not honored. Body must be a JSON object/array (empty →{}), 400 otherwise; 413 over 1 MiB; paused automation → 400Automation <id> is disabled; disabled trigger row → its token stops authenticating. If the QStash publish fails the event row is deleted and 500 returned so a sender retry re-enters cleanly. - Shared
WebhookMatchableEvent+case "webhook"intriggerMatches→{matches:true}(automation-matching/webhook.ts). - tRPC
automation.rotateWebhookSecret({triggerId})returns the token once (hash stored);automation.setTriggerSecret({triggerId, secret})stores a provider-issued signing secret verbatim for HMAC kinds (Circleback);automation.getreturnssecretPrefix/secretRotatedAtper trigger (never the column). - Desktop row:
Webhook triggered · <URL chip, click copies> · Generate auth header→Copy auth header(copies the literalAuthorization: Bearer …line) → after reloadRegenerate auth header(confirm dialog naming the old prefix).EndpointChipis a sharedTriggerSentence/componentschip (Circleback reuses it byte-identical). Uses main'sSentenceContext.triggerId.
No migration: secret_hash/secret_prefix/secret_rotated_at and the webhook enum value were already on main. Schema comment on secret_hash updated (bearer kinds hash, HMAC kinds raw; never returned by the API).
Verified
- Desktop over CDP (pre-seam-consolidation build; the rebase was mechanical): add "Webhook triggered" → Save → Generate auth header → Copy auth header (clipboard =
Authorization: Bearer sset_wh_…); reload → Regenerate auth header; regenerate → old token 401, new token accepted. - curl against the local API on the final head: no auth 401 · bad token 401 · null/scalar body 400 · 1.1 MB 413 · paused automation 400 · two identical bodies → two distinct events · same
Idempotency-Keytwice → two distinct events · 320-request bad-token burst → 293×401 + 27×429 · good token reaches the shared dispatcher (QStash rejects loopback destinations locally, so the publish itself isn't provable here — same path as the GitHub route). turbo typecheck(desktop, api, trpc, shared, db) exit 0; rootbun run lintexit 0.
Not in scope: injecting the event payload into the run prompt (dispatch.ts doesn't read automation_events for GitHub either).
Summary by CodeRabbit
- New Features
- Added webhook trigger support for receiving authenticated JSON payloads and dispatching matching automations.
- Added webhook endpoint display with copy-to-clipboard support, HTTP method details, and helpful status feedback.
- Added secure webhook token generation, rotation, and one-time token display.
- Added support for storing provider signing secrets and viewing secret metadata.
- Security & Reliability
- Added authorization checks, rate limiting, payload size limits, and validation for webhook requests.
- Webhook events are cleaned up if automation dispatch fails.