# Triggers

> What can start a flow, how to choose one, how to make a trigger start a run only for the mail or events you care about, and how to switch one off without deleting it.

Source: https://docs.go-lumen.ai/build/triggers

A trigger is what starts a run: an email, a schedule, a call to a webhook, a button you press. Every flow has at least one, and a flow can have up to 16. This page lists them all, shows how to pick one, and covers the two controls every trigger shares: a condition that decides whether to start, and a switch that turns it off.

-   Any workspace
-   Console or YAML

Each run starts from exactly one trigger. The trigger hands its first steps whatever arrived (an email and its files, the fields of a form, the text of a chat message), and the steps after it read those values as `<trigger id>.<field>`, for example `{email.subject}`.

## Choose what starts a flow

**Console:**

1.  Open a flow in the editor. On a new flow, click **Choose what starts this flow**. On an existing one, click its trigger, then **Change**.
2.  Pick one from the list, or type in **Search triggers**.
3.  Fill in its settings, such as the address or the schedule. A red dot on the trigger tile means a required setting is still missing.
4.  Click **Done**.

![The trigger picker, a side panel titled What starts this flow with a Search triggers box. Under Triggers it lists An email arrives, Another flow starts it, A file lands in a folder, On a schedule, I press Run and A chat message arrives, each with an icon and a one-line description.](https://docs.go-lumen.ai/img/build/triggers-01-picker.png)

*The trigger picker. Scroll for the webhook, form, WhatsApp, Jira, GitHub and test-case triggers.*

**YAML:**

Name the catalog trigger in `ref`, add its `config`, and list the first steps in `next`:

```yaml title="A trigger, as YAML"
triggers:
  - id: email
    ref: {name: email-arrives}
    connectorRef: {name: invoices-inbox}
    config: {attachments: separate, requireAttachment: true}
    next: [pdfs]
```

`id` is permanent: runs record which trigger started them, and conditions and placeholders name it. `title` (up to 80 characters) only changes what the canvas calls it.

## Every trigger

| Trigger (console title) | Catalog name | Starts when | Needs | Guide |
| --- | --- | --- | --- | --- |
| **An email arrives** | `email-arrives` | Mail reaches a Lumen forwarding address. | An email forwarding connection | [Email forwarding](https://docs.go-lumen.ai/connectors/email-forwarding.md) |
| **An email arrives**, source **Your mailbox** | `mailbox-email` | A new email lands in a mailbox Lumen reads over IMAP. Checked every 5 minutes unless you change it. | A mailbox connection | [Gmail and mailboxes](https://docs.go-lumen.ai/connectors/gmail-and-mailboxes.md) |
| **On a schedule** | [`on-schedule`](https://docs.go-lumen.ai/reference/triggers/on-schedule.md) | The days and time you choose, or at a fixed interval. | Nothing | [Waits and schedules](https://docs.go-lumen.ai/build/waits-and-schedules.md) |
| **I press Run** | [`manual-run`](https://docs.go-lumen.ai/reference/triggers/manual-run.md) | Someone presses **Run** and chooses files, or runs `lumen run`. | Nothing | [Your first flow](https://docs.go-lumen.ai/getting-started/first-flow.md) |
| **A chat message arrives** | [`chat-message`](https://docs.go-lumen.ai/reference/triggers/chat-message.md) | Someone writes in the chat. The flow's reply is what they read back. | Nothing | [Agents](https://docs.go-lumen.ai/ai/agents.md) |
| **A webhook is called** | [`webhook-received`](https://docs.go-lumen.ai/reference/triggers/webhook-received.md) | Another system calls your webhook address. | A webhook connection | [HTTP and webhooks](https://docs.go-lumen.ai/connectors/http-and-webhooks.md) |
| **A form is submitted** | [`form-submitted`](https://docs.go-lumen.ai/reference/triggers/form-submitted.md) | Someone fills in one of your forms. | A form | [Forms](https://docs.go-lumen.ai/approvals/forms.md) |
| **A WhatsApp message arrives** | [`whatsapp-message-received`](https://docs.go-lumen.ai/reference/triggers/whatsapp-message-received.md) | Someone writes to your WhatsApp number or taps a button you sent. | A WhatsApp connection | [WhatsApp](https://docs.go-lumen.ai/connectors/whatsapp.md) |
| **A Jira issue changes** | [`jira-issue-changed`](https://docs.go-lumen.ai/reference/triggers/jira-issue-changed.md) | An issue in the projects you pick is created, changes status or changes otherwise. Checked every 5 minutes unless you change it. | A Jira connection | [Jira and GitHub](https://docs.go-lumen.ai/connectors/jira-and-github.md) |
| **GitHub activity** | [`github-activity`](https://docs.go-lumen.ai/reference/triggers/github-activity.md) | An issue or pull request in the repositories you pick is opened, labeled, closed or merged, a review is requested, or a draft is marked ready. Checked every 5 minutes unless you change it. | A GitHub connection | [Jira and GitHub](https://docs.go-lumen.ai/connectors/jira-and-github.md) |
| **Another flow starts it** | [`flow-called`](https://docs.go-lumen.ai/reference/triggers/flow-called.md) | Another flow runs it with a **Run flow** step, on the same documents. | Nothing | [Run another flow](https://docs.go-lumen.ai/build/run-another-flow.md) |
| **Test cases** | [`evaluation`](https://docs.go-lumen.ai/reference/triggers/evaluation.md) | You run an evaluation: the flow runs once per row of a table of test cases, in test mode. | A test-cases table | [Test and evaluate](https://docs.go-lumen.ai/build/test-and-evaluate.md) |
| **A file lands in a folder** | [`file-added`](https://docs.go-lumen.ai/reference/triggers/file-added.md) | Planned. The catalog lists it, but nothing fires it yet, so a flow that uses it cannot be switched on. |  |  |

The email trigger is one entry in the editor with a **Source** setting (**A Lumen forwarding address** or **Your mailbox**). In YAML they are two catalog triggers, [`email-arrives`](https://docs.go-lumen.ai/reference/triggers/email-arrives.md) and [`mailbox-email`](https://docs.go-lumen.ai/reference/triggers/mailbox-email.md), with the same outputs. A flow saved with either keeps working as saved.

### What each trigger gives the steps

Every trigger puts its own fields on the document. These are the ones for the email triggers; the others are listed on their guide.

| Field | Type | Meaning |
| --- | --- | --- |
| `from`, `to` | text | Sender and recipients. |
| `subject`, `body` | text | The subject and the text of the email. |
| `attachments` | number | How many files the trigger took (at most 20 per email). |
| `senderVerified` | yes/no | True when the sending server's own check passed: DMARC passed, or the domain has no DMARC policy and SPF or DKIM passed for an aligned domain. |
| `receivedAt` | date | When it arrived. |
| `messageId` | text | The email's Message-ID. |

### Email settings

| Setting (console label) | YAML key | Default | Notes |
| --- | --- | --- | --- |
| **Attachments** | `attachments` | `separate` for a new trigger in the editor | `separate`: each file goes through the flow on its own, with the email's sender, subject and body. `together`: one document holds every file. A trigger saved before this setting existed behaves as `together`. |
| **Include images in the email body** | `includeInline` | off | Takes images shown in the body as attachments too. |
| **Largest mail (MB)** | `maxSizeMB` | 25 | From 1 to 40. A bigger email starts no run. |
| **Only emails with an attachment** | `requireAttachment` | on for an address, off for a mailbox | Turn it off to start on every email. |

A mailbox trigger adds `folder` (default `INBOX`), `pollMinutes` (1 to 60, default 5), `afterHandling` (`markRead`, `moveTo` or `leave`), `includeAttachments`, `importExisting` (0 to 500: take the newest mails already in the folder, once, when the folder is first read) and two optional filters, `fromContains` and `subjectContains`.

## Start only when

**Start only when** is a condition on the trigger's own fields. It is checked the moment the arrival is taken in, before any run exists. An arrival that does not match starts no run and costs nothing.

It is available on the email triggers, **A Jira issue changes** and **GitHub activity**. On any other trigger, use a [filter](https://docs.go-lumen.ai/build/branches-and-filters.md) as the first node instead.

**Console:**

1.  Open the trigger and scroll to **Start only when**.
2.  Build the condition in **Visual** mode (field, operator, value, with **Condition** and **Group** to add more), or switch to **Text** and write it, such as `trigger.subject ~ "invoice" AND trigger.senderVerified = true`.
3.  Click **Done**.

On a trigger created in the console the id is `trigger`, so its fields read `trigger.subject`. The editor says `valid` when the text parses.

![The Start only when section of the email trigger panel, in Text mode. The condition reads trigger.subject ~ "invoice" AND trigger.senderVerified = true, with the note valid, 2 conditions below it.](https://docs.go-lumen.ai/img/build/triggers-02-start-only-when.png)

*A condition in Text mode. The text and the visual builder describe the same condition.*

Mail that was checked and did not start a run is listed in the trigger's **Recent emails**, with the reason (for example **Start only when did not match**), so you can see what a condition kept out.

**YAML:**

`when` takes either `expr` or `field`, `op` and `value`, never both. A field is `<trigger id>.<output>`, and only the trigger's own outputs are allowed.

```yaml title="invoices-only.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: triggers-invoices-only
  namespace: tenant-acme
spec:
  displayName: Invoices from verified senders
  triggers:
    - id: email
      ref: {name: email-arrives}
      connectorRef: {name: invoices-inbox}
      config: {attachments: separate, requireAttachment: true}
      when:
        expr: 'email.subject ~ "invoice" AND email.senderVerified = true'
      next: [pdfs]
  nodes:
    - id: pdfs
      stepRef: {name: keep-pdfs}
      next: [keep]
    - id: keep
      stepRef: {name: keep-in-lumen}
```

Operators and the text grammar are the same as for filters and branches. See [Branches and filters](https://docs.go-lumen.ai/build/branches-and-filters.md#conditions).

A mailbox email that does not match is left where it is: not marked read, not moved.

## Use several triggers in one flow

A flow can start from more than one place. Each trigger lists its own first steps, so the paths can differ, and several triggers can share a step. Each run starts from one trigger and follows only its path.

```yaml title="invoice-intake.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: triggers-invoice-intake
  namespace: tenant-acme
spec:
  displayName: Invoice intake
  triggers:
    - id: email
      title: A supplier emails an invoice
      ref: {name: email-arrives}
      connectorRef: {name: invoices-inbox}
      config: {attachments: separate, requireAttachment: true}
      next: [pdfs]
    - id: manual
      ref: {name: manual-run}
      next: [pdfs]
    - id: monday
      title: Every Monday
      ref: {name: on-schedule}
      config: {cron: "0 8 * * 1", timeZone: Asia/Jerusalem}
      next: [remind]
  nodes:
    - id: pdfs
      stepRef: {name: keep-pdfs}
      next: [keep]
    - id: keep
      stepRef: {name: keep-in-lumen}
    - id: remind
      stepRef: {name: notify-in-app}
      config: {to: admins, title: "Check the invoices folder"}
```

What the steps after the trigger can use depends on what it produces: a schedule produces no document, so only steps that need nothing can follow it. The editor and the API refuse a step whose needs are not met.

To branch on which trigger started a run, use the run field `run.trigger`, which holds the trigger's id (or its catalog name). For example, the condition `run.trigger = "manual"`.

## Turn a trigger off

A disabled trigger keeps its settings and starts nothing, whatever arrives. Use it to pause one entry point of a flow, or to test with the others.

**Console:**

Hover the trigger and click the stop icon in its toolbar, or open its **...** menu and choose **Disable**. Do the same to turn it back on. A disabled trigger is drawn dimmed. When every trigger of a flow is off, the editor warns that nothing starts the flow.

**YAML:**

```yaml
triggers:
  - id: manual
    ref: {name: manual-run}
    disabled: true
    next: [pdfs]
```

What a disabled trigger does depends on how the arrival comes in:

| Trigger | When it is disabled |
| --- | --- |
| Email to a forwarding address | The email is taken in and logged as not started, with the reason "the trigger was disabled". |
| Mailbox | The mailbox is not read for it. |
| Schedule | Nothing fires. Switching it back on does not replay the time it was off. |
| Webhook | The call is accepted (202), no run starts, and the response lists the trigger as skipped. The sender is not told to stop or retry. |
| Form, WhatsApp, chat | Nothing starts. |
| Manual run | A run asked of it is refused. With no trigger named, the first enabled manual trigger is used. |

To pause the whole flow instead, turn off its switch at the top of the editor (`suspend: true` in YAML). Runs already queued still finish.

## Duplicate mail

A redelivered email does not start a second run. Lumen records every email once, keyed on its Message-ID, and derives each run's identity from that record, the flow and the trigger. If a message arrives again, for example after a mail server retries, a message that was already fully handled starts nothing, and one that was recorded but never queued still starts its runs.

A mailbox is deduplicated the same way, per flow, on the Message-ID. So marking a mail unread or moving it back to the folder does not run it a second time.

This protects against the same message arriving twice. It does not recognize two different emails that carry the same invoice. For that, add the **Skip duplicates** step: it remembers a key you choose, such as `{supplier} {invoiceNumber}`, for a number of days, and ends the run quietly when it has seen the key before.

## Next steps

[StepsAdd the steps that follow a trigger, and test each one before you run the flow.](https://docs.go-lumen.ai/build/steps.md)[Branches and filtersRoute a run by what it holds, or stop it quietly when it should not go on.](https://docs.go-lumen.ai/build/branches-and-filters.md)[Waits and schedulesStart on a schedule, or pause a run for a while.](https://docs.go-lumen.ai/build/waits-and-schedules.md)[Data and placeholdersHow a trigger's fields reach the steps after it.](https://docs.go-lumen.ai/concepts/data-and-placeholders.md)
