# Triggers and sessions

Understand what starts a flow, which flow wins, and how a session keeps track of each run on a conversation.

Source: https://support.rework.com/article/prospect-triggers-and-sessions

A flow starts when something matches its trigger. From that moment until it ends, the flow has a session on that conversation: the record of where it is, what it has learned, and what it's waiting for.

## The trigger block

Every flow has exactly one **Trigger** block **(1)**, and it's the first thing to configure. Click it on the canvas to open its panel on the right. You add one or more conditions to it under **Add condition** **(5)**, and as the panel says, _When ANY of these conditions match, start the flow._ **(2)** A flow with no conditions can't be published.

![Flow editor with the Trigger block selected: (1) the Trigger block on the canvas, (2) the 'When ANY of these conditions match, start the flow' note, (3) the Incoming keyword condition with Keyword, Match mode, Match against and Case sensitive, (4) Output fields, (5) the Add condition buttons](https://storage.googleapis.com/reworkv3-public/success/260928/ClY48NlIUtXpiZSagV1lJwxkFLiUrFRhFwB53UGSgBOopwvTbXSb3GtcmROaLtNQ/img.XTgZGMXha47G0OUdBRqZIMLAYnot422Zm8KI6eP4bpGyeslGlHcHr2L5tmJB7j21.png)

Which conditions you may add depends on the flow's scope. A personal scope (**Only my conversations** or **Me + followers' conversations**) offers only **Manual run** and **Conversation state**, because a conversation only enters a personal scope once somebody owns it. **Specific services** and **All conversations** offer the full set. You pick the **Trigger scope** when you create the flow, and it can't be changed afterwards.

## The trigger types

| Condition | Fires when |
| --- | --- |
| **New conversation** | The first message of a brand-new conversation arrives. |
| **Incoming keyword** | A message (or an attached file name) matches your keyword. |
| **Button payload** | The customer taps a button or quick reply with that exact payload. |
| **Manual run** | An agent starts the flow from the conversation. |
| **Conversation state** | The conversation is reopened, snoozed, unsnoozed or closed. |
| **AI agent trigger** | An AI agent hands the conversation to this flow. |
| **External webhook** | An outside system posts to the flow's webhook URL. |
| **Conversation goes silent** | The conversation goes quiet, with no new messages, for a while. |

**Incoming keyword** **(3)** takes a **Keyword**, a **Match mode** (**Contains**, **Exact**, **Starts with** or **Regex**), a **Match against** target of **Message text**, **File name** or **Message text or file name**, and an optional **Case sensitive** box.

**Conversation state** takes an **Event** of **Reopened**, **Snoozed**, **Unsnoozed** or **Closed**. For **Unsnoozed** you can narrow it further under **Only when unsnoozed by** to **Customer reply**, **Snooze timer elapsed** or **Agent action**; leave all three unticked to fire on any unsnooze.

**AI agent trigger** has an **AI note (what this flow does)** field. Only the AI reads it, never the customer, so it can explain to itself what the flow just did and carry on afterwards.

**External webhook** exposes an **External webhook URL** in **Flow settings**. Until the trigger has an external webhook condition, that spot just asks you to add one in the trigger node. The URL carries its own credential: anyone holding it can start the flow, so treat it as a secret, and use **Regenerate** if it leaks. The trigger panel includes a ready-made `curl` command to test it. Calls are limited to 60 per minute per flow.

Under **Incoming keyword** and **External webhook** you can also map **Output fields** **(4)**. Each name you add becomes a token later blocks can read; for a webhook, it also names the key read from the posted body or query string. Names accept letters, numbers and underscores only.

## Which flow wins

A single event never starts two flows. When several live flows match the same event, the one highest in the **Flows** list runs and the rest are ignored, as the note above the list reminds you **(1)**. Drag rows by the handle next to the number **(2)** to change the order.

![Flows list: (1) the note explaining that list order sets priority when several flows share a trigger, (2) the drag handles and position numbers used to reorder flows](https://storage.googleapis.com/reworkv3-public/success/260928/BeQcZ4biVQGTR1urIj4zp8p9ieq9B8eBrHwfoBlDbZNBSPXa8nJn67JSK0WbZHX5/img.C63P0lk6LZCBMShMBCvdqI8SipLKmkkSfB07i40sBpZiyR8WmZ3XBYaoEuXS1xgC.png)

A flow only fires at all if it's **Live** and the conversation is inside its scope.

## What a session is

A session is one run of one flow on one conversation. It holds the block the flow is sitting on, the variables it has collected, and a snapshot of the flow as it was when the session started. That means republishing a flow never changes a run that's already under way. 💡

**A conversation can only have one session at a time.** While one is running, a matching trigger event is handed to that running session instead of starting a second flow.

| Session status | What it means |
| --- | --- |
| **Running** | Working through blocks right now. |
| **Waiting input** | Parked at an **Ask**, waiting for the customer. |
| **Waiting timer** | Parked at a **Wait**, or on an **Ask** timeout. |
| **Completed** | Reached an **End** block, or ran out of wired outputs. |
| **Cancelled** | Stopped early, by an agent, an error, or the idle clean-up. |

## How long a session stays active

- A **Wait** can park a session for up to 30 days.
  
- An **Ask** with **Wait a limited time for a reply** parks it for the minutes you set.
  
- A session that's **Running** or **Waiting input** with no activity for more than an hour is cancelled automatically, with the outcome _Cleaned up (idle too long)_.
  
- Pausing a flow stops it starting new sessions; sessions already under way keep running on the snapshot they started with.
  

An agent can also stop a running flow from the conversation, which ends the session as _Cancelled by agent_.

## When the customer replies mid-flow

If the session is parked at an **Ask**, the reply is checked against **Expected answer**. A valid answer is saved to your variable and the flow moves on through the **Answered** output. An invalid one triggers the retry behaviour you configured, and when the retries run out, the flow fails, continues, or jumps to the step you chose.

If nothing arrives before the **Ask** timeout, the flow leaves through the **Timeout** output, or ends if that output isn't wired.

## The AI agent while a flow runs

Two automated responders on one conversation produce duplicate replies, so **Flow settings** has **While this flow runs, AI agent** with two choices. **Pause (flow owns the conversation)** is the default and keeps the AI silent until the session ends. **Continue replying in parallel** lets the AI keep answering alongside the flow, which only makes sense for flows that never send messages.

Click **Settings** in the flow editor's top bar to open **Flow settings**. It shows the flow's fixed **Trigger scope** **(1)**, the **While this flow runs, AI agent** choice **(2)**, and the **External webhook URL** section **(3)**.

![Flow settings dialog: (1) Trigger scope, greyed out because scope is fixed after creation, (2) the 'While this flow runs, AI agent' setting, (3) the External webhook URL section, which asks you to add an external condition in the trigger node first](https://storage.googleapis.com/reworkv3-public/success/260928/ZO6x8zOrQkejyUOpp5zqDwSFtrgcmdbGgAVRIIa1btJF1MxTlZrZdERcgPooWgba/img.8A3EsxnyaH7emEJLZiL93DJw4TvbFM151eCKODBtqldU08pyOWHr58l81nQreFxz.png)
