> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uservox.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Conditional Flow

> Route a process action to a different agent based on lead data at run time

## Overview

Conditional Flow lets you pick a different agent (Flow ID) for the same action based on what you know about a lead — without creating separate processes.

> "Use Agent A by default, but if the lead matches these rules, use Agent B instead."

The agent is chosen at the moment the action runs, using the lead's most recent data.

## Where to Find It

**Process editor → any action that has a Flow ID**

<img src="https://mintcdn.com/uservox/Ufh1Wn0D_mD3zybQ/images/conditional-flow.png?fit=max&auto=format&n=Ufh1Wn0D_mD3zybQ&q=85&s=5db9a5e1cc130d2d052aa1b5f044ca9a" alt="Conditional Flow" width="1791" height="1622" data-path="images/conditional-flow.png" /> (Make Call, Send WhatsApp, Send CD WhatsApp, Send Rampwin WhatsApp, Send Rampwin Webhook)

Below the existing Flow ID dropdown you will see a new section: **Conditional Flow ID** with a **+ Add Conditional** button.

## Setting Up a Rule

Each conditional card has four parts:

| Field                      | Purpose                                                                                 |
| -------------------------- | --------------------------------------------------------------------------------------- |
| **Description** (optional) | A short label for the rule                                                              |
| **Time window** (optional) | Only evaluate this rule during specific hours and/or days                               |
| **Conditions**             | The *if* part — variable + operator + value. AND across cards, OR within the same card. |
| **Then use this Flow ID**  | The *then* part — pick an agent or use a `{{variable}}`                                 |

Use the up/down arrows to reorder rules and the trash icon to delete them.

## Time Window

Each rule can optionally be restricted to a time window. When a time window is set, the rule is **skipped entirely** if the current wall-clock time is outside the window — even if the conditions would otherwise match.

Enable it with the **Time window** checkbox on any conditional card.

| Field     | Purpose                                                               |
| --------- | --------------------------------------------------------------------- |
| **Start** | Earliest time the rule is active (e.g. 09:00 AM)                      |
| **End**   | Latest time the rule is active (e.g. 05:00 PM)                        |
| **Days**  | Days of the week the rule applies. Leave all unchecked for every day. |

Times are interpreted in the **Asia/Kolkata** timezone.

> **Note:** Time window and conditions are evaluated together. A rule only fires when the current time is inside the window **and** the conditions match.

## How the Agent Is Picked

1. Rules are evaluated **top to bottom**.
2. The **first rule whose conditions match** is used.
3. If no rule matches, the **default Flow ID** at the top is used.
4. To add a guaranteed fallback that is not the default, add a final rule with **no conditions**.

## Things to Remember

* **Order matters** — first match wins.
* **Default still applies** when no rule matches.
* The decision is made **at run time**, even for delayed or scheduled actions.
* **Existing processes are unaffected** until you add a conditional rule.
* A rule with an **empty Flow ID** is ignored (the UI shows a red warning).
* A rule with a **time window** is skipped if the action runs outside that window — the next rule is tried instead.

## Example

| Rule    | Condition              | Flow ID               |
| ------- | ---------------------- | --------------------- |
| 1       | `language equals hi`   | Agent-B (Hindi agent) |
| 2       | `country equals India` | Agent-C (India agent) |
| Default | —                      | Agent-A               |

A lead with `language = hi` → **Agent-B** (rule 1 matches first).\
A lead with `language = en` and `country = India` → **Agent-C** (rule 2 matches).\
All other leads → **Agent-A** (default).

## Test Cases

Use these to confirm the feature works as expected. For each case, set up the rule, push a test lead through the action, then check which Flow ID was used in the lead's call attempt or WhatsApp activity.

| # | Setup                                                                                                          | Lead data                  | Expected Flow ID                                 |
| - | -------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------ |
| 1 | Default only — no conditional rules. Default = Agent-A.                                                        | Any lead.                  | Agent-A (default).                               |
| 2 | Single rule matches — Rule: `language equals hi` → Agent-B. Default = Agent-A.                                 | Lead with `language = hi`. | Agent-B.                                         |
| 3 | Single rule does not match (fallback) — same setup as #2.                                                      | Lead with `language = en`. | Agent-A (falls back to default).                 |
| 4 | First match wins — Rule 1: `language equals hi` → Agent-B. Rule 2: `country equals India` → Agent-C.           | Lead matching both rules.  | Agent-B (rule 1 is first).                       |
| 5 | Reordering changes outcome — same lead as #4, but move Rule 2 above Rule 1.                                    | Lead matching both rules.  | Agent-C (now rule 2 is first).                   |
| 6 | Catch-all — Rule 1: `language equals hi` → Agent-B. Rule 2 (last): no conditions → Agent-C. Default = Agent-A. | Lead with `language = en`. | Agent-C (catch-all rule, default never reached). |
| 7 | Empty Flow ID rule is ignored — Rule 1: `language equals hi` → (no agent picked). Default = Agent-A.           | Lead with `language = hi`. | Agent-A (rule has no Flow ID, so it is skipped). |
| 9 | Undo conditional — start from #2 setup, then delete the conditional rule.                                      | Lead with `language = hi`. | Agent-A (back to default).                       |

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What variables can I use in conditions?">
    Anything on the lead — `language`, `lastDisposition`, `pastDispositions`, metadata fields, learned-data fields, etc.
  </Accordion>

  <Accordion title="What happens if a rule has an empty Flow ID?">
    The rule is ignored. The UI shows a red warning to flag it.
  </Accordion>

  <Accordion title="How do I undo conditional routing?">
    Delete all conditional rules. The action reverts to the default Flow ID.
  </Accordion>

  <Accordion title="What if the action runs outside the time window?">
    That rule is skipped and the next rule is evaluated. If no remaining rules match, the default Flow ID is used.
  </Accordion>

  <Accordion title="Can I combine a time window with conditions?">
    Yes. Both must be satisfied — the current time must be inside the window and the conditions must match.
  </Accordion>

  <Accordion title="Can I route by time alone, without any conditions?">
    Yes. Leave conditions empty and set only a time window. The rule will then match every lead during that window.

    Example — use Agent A during the day and Agent B in the evening:

    | Rule    | Time window       | Conditions | Flow ID |
    | ------- | ----------------- | ---------- | ------- |
    | 1       | 9:00 AM – 5:00 PM | —          | Agent A |
    | 2       | 5:00 PM – 9:00 PM | —          | Agent B |
    | Default | —                 | —          | Agent A |
  </Accordion>
</AccordionGroup>
