feat(automations): add webhook trigger backed by org API keys#999
Merged
Conversation
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
Contributor
🧹 Preview RemovedThe preview deployment for this PR has been cleaned up. |
Contributor
There was a problem hiding this comment.
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
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
b6abd4c to
b79fbde
Compare
Contributor
🚀 Preview Deployment
Preview will be automatically removed when this PR is closed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a webhook trigger to automations, so an automation can be started by an external
POSTrequest instead of (or in addition to) a cron schedule. The webhook is authenticated with the existing organization API key system — the samenao_...Bearer keys used bynao deploy.What changed
Backend
webhook_enabledcolumn on theautomationtable (SQLite + Postgres schemas + migrations0053_webhook_trigger).POST /api/automations/:automationId/run:Authorization: Bearer nao_...; validates the key viavalidateApiKey.403if the webhook trigger is disabled,409if the automation is paused,404if unknown / cross-org,401for missing/invalid keys.202with{ runId, automationId, status }.automation.create/update:cronis optional andwebhookEnabledis supported;assertTriggersrequires at least one trigger;syncAutomationJobclears the scheduled job when an automation becomes webhook-only.Frontend
POSTendpoint URL + copyable examplecurl, and aWebhook triggerrow that readsEnabled/Paused/Disabledin sync with the automation's pause state.Daily at 9am · webhook) so aPausedbadge is not misread as the webhook being gone; the badge/label reflectwebhookEnabled.webhooklabel for webhook-only automations (andpausedwhen disabled) instead of alwayspaused.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)Live endpoint checks:
401; invalid key →401; unknown/cross-org id →404; webhook disabled →403.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 triggertoPaused, the webhook returns409, and the feed shows aPausedbadge withDaily 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.