# 条件漏斗

**条件漏斗（Condition Funnel）** 模块可根据变量值、用户输入或消息内容，将对话引导至不同的流程分支。

常见使用场景包括：验证用户输入（例如邮箱、电话号码、数字），按用户属性进行分流，使用条件控制流程逻辑。

***

### 1. 条件漏斗界面说明

<figure><img src="/files/1Xju7K8wC0vCsg67FtfD" alt="" width="330"><figcaption></figcaption></figure>

#### 界面组成

1. **输入自定义资料名称**\
   选择需要进行判断的自定义资料名称（例如用户输入、自定义字段或系统变量）。
2. **条件运算符**\
   定义变量与输入值之间的比较方式。
3. **输入值／规则**\
   用于比较的值或规则。
   * 基础条件：文本或数字
   * Regex 条件：正则表达式
4. **新增条件（＋）**\
   添加多个条件分支。
5. **后备路径**\
   当所有条件均不满足时，对话将进入该路径。

***

### 2. 条件运算符说明

#### 比较与数值运算

<figure><img src="/files/XDilH8SLncb4jaBlKFcP" alt="" width="162"><figcaption></figcaption></figure>

| 运算符                          | 说明     | 示例                |
| ---------------------------- | ------ | ----------------- |
| 等于（Equal）                    | 变量完全匹配 | `country = USA`   |
| 不等于（Not Equal）               | 变量不匹配  | `country ≠ SG`    |
| 小于（Less Than）                | 数值比较   | `order_count < 3` |
| 小于或等于（Less Than or Equal）    | 数值比较   | `score ≤ 60`      |
| 大于（Greater Than）             | 数值比较   | `order_count > 5` |
| 大于或等于（Greater Than or Equal） | 数值比较   | `amount ≥ 1000`   |

> ⚠️ 数值相关运算符仅适用于数值类型变量。

***

#### 列表与文本匹配

| 运算符          | 说明        | 示例                     |
| ------------ | --------- | ---------------------- |
| 在（In）        | 匹配列表中的任一值 | `country in [USA, SG]` |
| 包含（Contains） | 包含指定文本    | 信息包含 `refund`          |
| 为空（Is Empty） | 变量为空      | 电话号码为空                 |

***

### 3. 符合正则表达式（Regex）

符合正则表达式支持使用正则表达式进行进阶匹配与格式验证，适用于需要严格输入规则的场景。

<figure><img src="/files/h4fOEFje3bNKma5f66iA" alt="" width="288"><figcaption></figcaption></figure>

#### 使用方式

* 在栏位`/ /`中输入正则表达式规则
* 可选择性启用 Regex flags
* 当变量值符合 Regex 规则时，条件成立

### 常见 Regex 示例

| 使用场景          | Regex 示例                     | 输入示例                   |
| ------------- | ---------------------------- | ---------------------- |
| 验证邮箱格式        | `^[^\s@]+@[^\s@]+\.[^\s@]+$` | `example@chatalog.com` |
| 验证包含国家代码的电话号码 | `^\+[1-9]\d{6,14}$`          | `+14155552671`         |
| 仅允许数字输入       | `^\d+$`                      | `123456`               |

***

### 4. 进阶Regex Flags 说明（可选）

Regex Flags控制模式的评估方式。

<figure><img src="/files/v0qStSm7OteJUwpOb9I0" alt="" width="375"><figcaption></figcaption></figure>

<table><thead><tr><th width="207.63671875">Flag</th><th>名称</th><th>说明</th></tr></thead><tbody><tr><td>g</td><td>Global</td><td>匹配所有符合的结果</td></tr><tr><td>m</td><td>Multi Line</td><td><code>^</code> 与 <code>$</code> 作用于每一行</td></tr><tr><td>i</td><td>Case Insensitive</td><td>忽略大小写</td></tr><tr><td>x</td><td>Extended</td><td>允许空格与注释</td></tr><tr><td>s</td><td>Single Line</td><td><code>.</code> 可匹配换行符</td></tr><tr><td>u</td><td>Unicode</td><td>启用 Unicode 匹配</td></tr><tr><td>U</td><td>Ungreedy</td><td>默认使用非贪婪匹配</td></tr><tr><td>A</td><td>Anchored</td><td>从字符串开头开始匹配</td></tr><tr><td>J</td><td>Jchanged</td><td>允许重复命名分组</td></tr></tbody></table>

***

### 5. 使用示例

#### 示例 1：验证邮箱

* 变量：`User Input`
* 运算符：Matches Regex
* 规则：`^[^\s@]+@[^\s@]+\.[^\s@]+$`

**结果**

* 匹配 → 继续流程
* 不匹配 → 提示用户重新输入邮箱

***

#### 示例 2：按国家分流

* 变量：`Country`
* 运算符：In
* 值：`USA, SG`

**结果**

* 匹配 → 进入区域流程
* 不匹配 → 进入默认流程

***

#### 示例 3：检查电话号码是否为空

* 变量：`Phone Number`
* 运算符：Is Empty

**结果**

* 为空 → 提示用户输入电话号码
* 非空 → 继续流程

***

### 6. 最佳实践

* 从**简单运算符**(等于、包含于、包含)开始，然后再使用正则表达式。
* 务必配置**后备**路径以防止死路。
* 使用正则表达式时:
  * 使用 `^` 和 `$` 锚定模式以避免部分匹配
  * 使用真实用户输入测试模式
* 保持条件逻辑可读性——多个简单条件通常比一个复杂规则更清晰。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chatalog.ai/zh-cn/crm-quickstarts/customized-flow/condition_funnel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
