# Triggers

Start workflows from webhooks, cron schedules, Redis Streams or SQS queues, and Slack, Telegram, WhatsApp or email messages, and reply in the same channel.

Source: https://glamorous-boar.cloudvent.net/triggers/

---

Trigger nodes start runs from outside events. They are ordinary nodes in *Inputs & triggers*, versioned with the graph, and each outputs `payload`, `text` and `event`.

## How activation works

1. Add a trigger node and configure it (secrets as references).
2. Tick **`enabled`** and **save**. A trigger listens only in the project's **latest saved revision**.
3. Select the node: the **Trigger** panel in the inspector shows its status (*Listening* or *not ready* with what is missing), URL, next run, event count, last event and run, last error, and setup steps.
4. Each event starts an ordinary recorded run (visible in run history), with the event in the run input under `_trigger`. Duplicate deliveries (Slack retries, WhatsApp redeliveries, Telegram `update_id`) are de-duplicated.

When you click **Run** in the IDE (or run via the CLI or tests), the trigger outputs its `sample` event marked `simulated: true`, so trigger graphs are always testable.

The trigger service rescans projects at start-up, after every save, create or delete, and every 60 s. With several API processes, one elected **trigger leader** runs schedules and pollers; every process accepts webhooks.

## Webhook Trigger

Endpoint: `POST /api/triggers/{project}/{node}` (public; the trigger authenticates its caller).

| `auth` | Caller sends |
|---|---|
| `token` (default) | `Authorization: Bearer <secret>` or `X-Webhook-Token: <secret>` |
| `hmac` | HMAC-SHA256 of the raw body as `sha256=<hex>` in `signature_header` (default `X-Hub-Signature-256`, GitHub style) |
| `none` | Nothing. Explicit opt-in only. |

| `respond` | Response |
|---|---|
| `ack` (default) | `202` with the run ID, immediately. |
| `wait` | Runs, then answers with all outputs (or only `response_output`) within `wait_seconds` (30). |

<CodeBlock language="bash" filename="terminal" showCopy={true}>

```
curl -X POST http://localhost:8000/api/triggers/prj_abc123/webhook \
  -H "Authorization: Bearer $MY_WEBHOOK_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the capital of Australia?"}'
```

</CodeBlock>

Bodies over 2 MB are refused. Secrets are compared in constant time and resolved per request.

## Schedule Trigger

- `mode: cron` with `cron` (e.g. `0 9 * * 1-5`, `*/15 * * * *`, `@daily`) and an IANA `timezone` (e.g. `Europe/London`). The built-in parser supports lists, ranges, steps, names, aliases and the standard rule that either restricted day field may match.
- `mode: interval` with `interval_minutes`.
- `payload`: JSON sent as the event on every run.

Checked every 5 seconds. Missed runs are not replayed after a restart.

## Queue Trigger

| Backend | Settings |
|---|---|
| **Redis Streams** | `redis_url`, `redis_password`, `stream`, consumer `group` (created if missing). A single JSON field (`data`, `payload`, `body` or `json`) is parsed. |
| **Amazon SQS** | `queue_url`, `region`, access key secrets (or default AWS credentials), `endpoint_url` for LocalStack. Long polling. |

`acknowledge: on_start` removes the message when its run starts; `on_success` only after the run succeeds, leaving failed messages for redelivery. `max_messages` per poll.

## Chat Trigger

One node, four channels. Each incoming message starts a run; when it ends, the output named `reply_output` (default `answer`) is sent back. A failed run sends `error_reply`.

| Channel | You need | Verification and replies |
|---|---|---|
| **Telegram** | `telegram_bot_token` (from @BotFather), `telegram_secret_token` | Checks `X-Telegram-Bot-Api-Secret-Token`; skips bots; replies with `sendMessage`. Register the URL with `setWebhook` (the Trigger panel shows the exact call). |
| **Slack** | `slack_signing_secret`, `slack_bot_token` (`xoxb-…`) | Verifies the `v0=` HMAC with a 5-minute replay window; answers `url_verification`; ignores bot messages; acknowledges immediately (Slack's 3-second rule); replies with `chat.postMessage`, in thread by default. |
| **WhatsApp** (Cloud API) | `whatsapp_verify_token`, `whatsapp_app_secret`, `whatsapp_access_token` | GET `hub.verify_token` handshake; `X-Hub-Signature-256` check; replies via the Graph API (`whatsapp_graph_version`, default v27.0). |
| **Email** | IMAP host/port/username/password/folder, SMTP host/port, `from_address` | Polls unread mail every `poll_seconds` (60), marks it seen; replies by SMTP with `Re:`, `In-Reply-To` and `References`. |

<Alert variant="warning" title="Chat platforms need a public HTTPS URL" text="Slack, Telegram and WhatsApp must reach your server over the internet. When running locally, use a tunnel (for example cloudflared or ngrok) and use its HTTPS URL in the platform's settings."/>

### Example: a Telegram bot in five minutes

1. **New** → *Chat bot (Telegram, Slack, WhatsApp, email)*.
2. Create a bot with @BotFather; add `TELEGRAM_BOT_TOKEN` and a random `TELEGRAM_WEBHOOK_SECRET` in Settings → Secrets.
3. In the Chat Trigger, set `channel: telegram`, pick the two secrets, tick `enabled`, save.
4. Start a tunnel to port 8000 and call Telegram's `setWebhook` with the URL and secret shown in the Trigger panel.
5. Message your bot.

## Status API

`GET /api/projects/{id}/triggers` returns each trigger's state, path, next run, event count, last event and run, and last error.

## Limits

Exported standalone apps do not host triggers. Missed schedules are not replayed. No Discord, Teams, Kafka or RabbitMQ yet.
