# 條件漏斗

**條件漏斗（Condition Funnel）** 區塊可根據變數值、使用者輸入或訊息內容，將對話導向不同的流程分支。

常見使用情境包括：驗證使用者輸入（例如電子郵件、電話號碼、數字），使用者屬性分流，透過條件控制流程邏輯。

***

### 1. 條件漏斗介面說明

<figure><img src="/files/kimnDonBSE7TIJdkZMIH" alt="" width="308"><figcaption></figcaption></figure>

#### 介面組成

1. **輸入自訂資料名稱**\
   選擇要進行判斷的資料名稱（例如用戶輸入、自訂資料或系統資料）。
2. **條件運算子**\
   定義變數與輸入值之間的比對方式。
3. **輸入值／規則**\
   用來進行比對的值或規則。
   * 基本條件：文字或數字
   * Regex 條件：正則表達式
4. **新增條件（＋）**\
   新增多個條件分支。
5. **後備路徑**\
   當所有條件皆不符合時，對話會進入此路徑。

***

### 2. 條件運算子說明

#### 比較與數值運算

<figure><img src="/files/TzNOMHUB12mCy9KWSDNi" alt="" width="160"><figcaption></figcaption></figure>

<table><thead><tr><th width="316.84375">運算子</th><th width="177.86328125">說明</th><th>範例</th></tr></thead><tbody><tr><td>等於（Equal）</td><td>變數完全相同</td><td><code>country = USA</code></td></tr><tr><td>不等於（Not Equal）</td><td>變數不相同</td><td><code>country ≠ SG</code></td></tr><tr><td>小於（Less Than）</td><td>數值比較</td><td><code>order_count &#x3C; 3</code></td></tr><tr><td>小於或等於（Less Than or Equal）</td><td>數值比較</td><td><code>score ≤ 60</code></td></tr><tr><td>大於（Greater Than）</td><td>數值比較</td><td><code>order_count > 5</code></td></tr><tr><td>大於或等於（Greater Than or Equal）</td><td>數值比較</td><td><code>amount ≥ 1000</code></td></tr></tbody></table>

> ⚠️ 數值相關的運算子僅適用於數字型變數。

***

#### 清單與文字比對

| 運算子           | 說明        | 範例                     |
| ------------- | --------- | ---------------------- |
| 在（In）         | 符合清單中的任一值 | `country in [USA, SG]` |
| 包含（Contains）  | 包含指定文字    | 訊息包含 `refund`          |
| 是空的（Is Empty） | 變數沒有值     | 電話號碼為空                 |

***

### 3. 符合正則表達式 (Regex)

符合正則表達式可使用正則表達式進行進階格式驗證，適用於需要嚴格輸入規則的情境。

<figure><img src="/files/oTE4JAePFwc8GtKShqsG" alt="" width="276"><figcaption></figcaption></figure>

#### 使用方式

* 在欄位`/ /`中輸入 Regex 表達式
* 可選擇性啟用 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/QflrqYA60fclA8yaX08h" alt="" width="375"><figcaption></figcaption></figure>

<table><thead><tr><th width="178.07421875">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@]+$`

**結果**

* 符合 → 繼續流程
* 不符合 → 請用戶重新輸入 Email

***

#### 範例 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-hk/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.
