AdPilot · Corpus
T-032 — Inbound triggers: webhooks-in, platform events, schedules
T-032 — Inbound triggers: webhooks-in, platform events, schedules
Frozen spec for the T-032 build (base branch main → head of the build). Goal: make the workflow engine fireable from outside the console — marketing/sales automations trigger on inbound signals, sandbox-safe.
Decisions
- Scope (Q1): triggers bind to workflow plans only. The automation-rules engine (T-023) is still in backlog, so the card's "first-class in automation rules" criterion defers to T-023 (recorded in the card result).
- Implementer — schedule grammar: cron-lite, UTC —
daily@HH:MM,hourly@MM,everyNm(5–1440). First fire is the computed slot (never immediately on registration);next_run_atadvances before firing so a slow run can never double-fire an interval. - Implementer — hook defense order: rate limit (429) → key lookup (404) →
HMAC-SHA256 (401;
sha256=<hex>or bare hex, headerX-AdPilot-Signature) → flat-schema validation (422) → fire (202). Both rejections and fires land in the delivery log. - Implementer — rate limiter: in-memory per-key fixed window (60/min) on
the
Server— load protection, not billing; nil-safe for tests. - Implementer — frontend: the picker ships in the Next.js operator console (apps/web-next, of record per T-035 and the owner's Next.js directive), not the legacy Vite web pages the card originally named.
Surface-area deltas
services/api/internal/domain/triggers.go— trigger types, HMAC verify, flat payload schema (?type= optional),TriggerRateLimiter,NextScheduleRun,ExamplePayloadFor,Validate.services/api/internal/store/triggers.go+services/api/internal/store/migrations/0005_triggers.sql— trigger CRUD, delivery log (insert/update/get/list), due-schedule scan.services/api/internal/api/handlers_triggers.go— hook receiver, the event bus endpoint, trigger CRUD, deliveries + replay,FireDueSchedules,StartScheduler(30s ticker, wired inservices/api/cmd/adpilot/main.go).services/api/internal/api/server.go— 8 new routes +Hookslimiter field; zero existing routes touched.apps/web-next/app/triggers/page.tsxplusapps/web-next/lib/api.ts,apps/web-next/lib/types.ts,apps/web-next/lib/demo.ts— picker with live example payload, secret-once reveal, delivery log with replay; the demo engine implements the same surface so the demo export stays type-checked.apps/web-next/app/layout.tsx— one nav link added for the triggers page.services/api/cmd/adpilot/main_test.go— the covered main test keeps passing undergo test ./...; the scheduler wiring is compile-checked.tasks/10-in-progress/T-032-inbound-triggers-webhooks.md— the claimed board card; moves to tasks/90-done at close with the result note.- Tests:
services/api/internal/domain/triggers_test.go(signatures, schema, limiter, schedule grammar) andservices/api/internal/api/triggers_test.go(lifecycle, schema rejection, rate-limit 429, rotation, event bus, schedule fire, validation).
Verification
Go gates: go test ./... in services/api (6/6 packages, 8 new test funcs).
Web gate: npm run build in apps/web-next (strict tsc). Live E2E on :8090:
bad signature → 401, missing field → 422, valid → 202 + run visible, event
bus matched=1, delivery log shows fired + rejected rows, replay created a
new run.
Out of scope
Outbound webhooks (T-027), automation-rule triggers (T-023), real platform event ingestion (sandbox bus only — the sandbox rule holds).