Skip to content

feat(automations): add webhook trigger backed by org API keys#999

Merged
Bl3f merged 8 commits into
mainfrom
cursor/add-webhook-trigger-automations-e593
Jul 5, 2026
Merged

feat(automations): add webhook trigger backed by org API keys#999
Bl3f merged 8 commits into
mainfrom
cursor/add-webhook-trigger-automations-e593

Conversation

@Bl3f

@Bl3f Bl3f commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a webhook trigger to automations, so an automation can be started by an external POST request instead of (or in addition to) a cron schedule. The webhook is authenticated with the existing organization API key system — the same nao_... Bearer keys used by nao deploy.

What changed

Backend

  • New webhook_enabled column on the automation table (SQLite + Postgres schemas + migrations 0053_webhook_trigger).
  • New REST endpoint POST /api/automations/:automationId/run:
    • Requires Authorization: Bearer nao_...; validates the key via validateApiKey.
    • Authorizes by checking the key's organization owns the automation's project.
    • 403 if the webhook trigger is disabled, 409 if the automation is paused, 404 if unknown / cross-org, 401 for missing/invalid keys.
    • Otherwise starts a run and responds 202 with { runId, automationId, status }.
  • Pausing gates every trigger: a paused (scheduled) automation now rejects its webhook too. Pausing only applies to scheduled automations, so webhook-only automations stay active.
  • tRPC automation.create/update: cron is optional and webhookEnabled is supported; assertTriggers requires at least one trigger; syncAutomationJob clears the scheduled job when an automation becomes webhook-only.
  • Route tests covering auth, authorization, disabled webhook, paused, enabled-scheduled, and webhook-only dispatch.

Frontend

  • "Via webhook" option in the automation trigger picker; an automation can be schedule-only, webhook-only, or both.
  • Detail page shows the webhook POST endpoint URL + copyable example curl, and a Webhook trigger row that reads Enabled / Paused / Disabled in sync with the automation's pause state.
  • Feed side panel surfaces the webhook alongside a schedule (Daily at 9am · webhook) so a Paused badge is not misread as the webhook being gone; the badge/label reflect webhookEnabled.
  • Left sidebar shows a webhook label for webhook-only automations (and paused when disabled) instead of always paused.

Testing

  • npm run -w @nao/backend test -- automation-webhook (8 route tests pass)
  • npm run lint (tsc + eslint + prettier + migration check + cli lint, via pre-commit)
  • ✅ Manual end-to-end (UI + curl): created a webhook automation, generated an org API key, triggered the endpoint, and verified the pause gate.

Live endpoint checks:

  • No header → 401; invalid key → 401; unknown/cross-org id → 404; webhook disabled → 403.
  • Webhook-only, enabled → 202. Schedule+webhook, enabled → 202. Schedule+webhook, paused → 409 {"error":"Automation is paused"}.

Walkthrough — webhook trigger

automation_webhook_trigger_demo.mp4

Creating a webhook automation; sending a webhook request adds a new run to the feed.

Trigger picker with On schedule and Via webhook options
Detail page showing webhook POST endpoint and example curl

Walkthrough — pause gates the webhook

webhook_pause_gating_demo.mp4

Pausing a schedule+webhook automation flips Webhook trigger to Paused, the webhook returns 409, and the feed shows a Paused badge with Daily at 9am · webhook.

Detail panel showing Status: Paused and Webhook trigger: Paused
Feed side panel showing Paused badge and Daily at 9am webhook label

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Review in cubic

Add a webhook trigger to automations, authenticated with the existing
organization API key system (Bearer nao_... keys used by nao deploy).

- Add webhook_enabled column to the automation table (sqlite + postgres)
- POST /api/automations/:id/run validates the API key, checks the key's
  org owns the automation's project, and starts a run
- Make the schedule trigger optional so an automation can be webhook-only;
  require at least one trigger (schedule or webhook)
- Add route tests covering auth, authorization and trigger dispatch
- Add webhook trigger option to the automations trigger picker
- Show the webhook URL and an example curl request once saved
- Surface webhook-only automations in the detail and feed views
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

🧹 Preview Removed

The preview deployment for this PR has been cleaned up.

@Bl3f Bl3f marked this pull request as ready for review June 30, 2026 21:03

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 17 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread apps/frontend/src/components/sidebar.tsx Outdated
Comment thread apps/frontend/src/routes/_sidebar-layout.feed.index.tsx Outdated
cursoragent and others added 5 commits July 1, 2026 08:18
A paused automation now stops all of its triggers, including the webhook,
which previously kept answering. Pausing only applies to scheduled
automations, so webhook-only automations remain active. The webhook route
returns 409 Conflict when a scheduled automation is paused.
- Feed side panel surfaces the webhook trigger alongside a schedule so a
  paused badge is not read as the webhook being gone
- Sidebar status label reflects webhookEnabled for webhook-only automations
- Detail summary shows the webhook trigger as Paused when the automation is
  paused
@Bl3f Bl3f force-pushed the cursor/add-webhook-trigger-automations-e593 branch from b6abd4c to b79fbde Compare July 5, 2026 19:12
@Bl3f Bl3f merged commit 0882742 into main Jul 5, 2026
8 checks passed
@Bl3f Bl3f deleted the cursor/add-webhook-trigger-automations-e593 branch July 5, 2026 19:14
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

URL https://pr-999-b79fbde.preview.getnao.io
Commit b79fbde

⚠️ No LLM API keys configured - you'll see the API key setup flow when trying to chat.


Preview will be automatically removed when this PR is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants