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

# Condition Node

> How to use the Condition Node in Sendflow to route data based on rules

The **Condition Node** checks a specific rule (a "condition") and decides which path the data should take next.

## How It Works

* You write a simple sentence (a rule).
* If the rule is **True**, the flow follows the path connected to that rule.
* If the rule is **False**, the flow moves to the next rule or the "Else" (fallback) path.

## 1. Comparing Values (Basic Operators)

These operators check if a value matches, is greater than, or differs from another value.

| Operator | Name             | Logic                          | Example Pattern           |
| -------- | ---------------- | ------------------------------ | ------------------------- |
| `==`     | Equals           | Does A equal B?                | `channel == "whatsapp"`   |
| `!=`     | Not Equals       | Is A anything except B?        | `status != "opt-out"`     |
| `>`      | Greater Than     | Is A bigger than B?            | `message_count > 5`       |
| `>=`     | Greater or Equal | Is A bigger or the same as B?  | `credit_balance >= 10.00` |
| `<`      | Less Than        | Is A smaller than B?           | `retry_attempts < 3`      |
| `<=`     | Less or Equal    | Is A smaller or the same as B? | `days_inactive <= 7`      |

<Tip>
  You can use quotes for text (`"whatsapp"`) but they are usually optional. Numbers do not need quotes.
</Tip>

**Real-world examples:**

* Send SMS only if the user is verified: `user_verified == "true"`
* Send RCS only if the balance is positive: `wallet_balance > 0`

## 2. Checking Lists (The `in` Operator)

Use the **in** operator to check if a value belongs to a specific group or list. This is faster than writing multiple "OR" rules.

**Syntax:** `VariableName in [Item1, Item2, Item3]` or `VariableName in item1, item2`

**Examples:**

* `state in [NY, CA, TX]` — True if the state is New York, California, or Texas
* `status in [pending, processing]`

**Real-world examples:**

* Send via WhatsApp if the country supports it: `country_code in [IN, BR, ID, US]`
* Process only specific message statuses: `delivery_status in [failed, undelivered]`
* Target specific user tags: `user_tag in [vip, premium, beta_tester]`

## 3. Pattern Matching (The `matches` Operator)

For advanced users only.

Use **matches** to check if text follows a specific pattern (like a phone number format or email domain) using Regex.

**Syntax:** `variable matches pattern`

**Real-world examples:**

* Check if the phone number is an Indian mobile number: `phone matches "^91\d{10}$"`
* Send email only to corporate domains: `email matches "@company\.com$"`
* Validate an OTP format (4 digits): `otp_input matches "^\d{4}$"`

## 4. The "NOT" Operator (!)

Use **!** to reverse a rule. If the rule inside is True, the **!** makes it False.

**Syntax:** `!variable == value`

**Real-world examples:**

* Send SMS if the user is NOT blocked: `!status == "blocked"`
* Proceed if the email is NOT empty: `!email == ""`
* Target users who are NOT in the 'churn' list: `!segment == "churned"`

## 5. Combining Rules (&& and ||)

You can mix and match rules to create complex logic.

### The AND Operator (&&)

Both sides must be true for the condition to pass.

**Syntax:** `Condition A && Condition B`

**Example:** `age > 18 && country == "USA"`\
**Meaning:** "The user must be over 18 AND they must live in the USA."

**Real-world examples:**

* Send WhatsApp if the user has opted in AND has a valid phone number: `opt_in_whatsapp == "true" && phone_valid == "true"`
* Send critical alert if priority is high AND status is pending: `priority == "high" && status == "pending"`

### The OR Operator (||)

At least one side must be true for the condition to pass.

**Syntax:** `Condition A || Condition B`

**Example:** `role == "admin" || role == "manager"`\
**Meaning:** "Let them in if they are an Admin OR if they are a Manager."

**Real-world examples:**

* Send message via cheaper channel (SMS OR RCS): `channel_preference == "sms" || channel_preference == "rcs"`
* Retry sending if the error was 'timeout' OR 'busy': `error_code == "timeout" || error_code == "busy"`

### Summary of Priority

When you write a complex rule, the system checks them in this order:

1. **!** (NOT) checks happen first.
2. **&&** (AND) groups are checked next.
3. **||** (OR) splits are checked last.

**Complex example:**

```
country == "US" && !status == "unsubscribed" || role == "admin"
```

**Translation:** "Send the message if: (The user is in the US AND is not unsubscribed) OR (The user is an Admin)."

In this system, the "AND" (&&) operator splits the rule first.

**Rule:** `A || B && C` is treated as `(A or B) AND C`.

This is helpful for scenarios like: "Match either channel AND ensure the user is active."

***

## Cheat Sheet Examples

Common use cases in messaging or notification workflows:

* **Check for VIP customers:** `total_spent >= 1000`
* **Check if an order is active:** `status != "cancelled"`
* **Send email only to Gmail users:** `email matches "@gmail.com"`
* **Check logic for shipping fees:** `country == "UK" && order_value < 50`

***

## Use Case Reference

### 1. Scheduling & Time Windows

Assuming you have variables like `current_hour` (0–23) or `day_name`.

| Goal                | Condition String                                 | Explanation                       |
| ------------------- | ------------------------------------------------ | --------------------------------- |
| Business Hours Only | `current_hour >= 9 && current_hour < 18`         | Sends only between 9 AM and 6 PM. |
| Exclude Weekends    | `day_name != "Saturday" && day_name != "Sunday"` | Blocks messages on Sat/Sun.       |
| Specific Days Only  | `day_name in [Monday, Wednesday, Friday]`        | Only allows Mon/Wed/Fri.          |
| Morning Rush        | `current_hour <= 10`                             | Matches times before or at 10 AM. |

### 2. Budget & Limits

Assuming variables like `wallet_balance`, `msg_cost`, `retry_count`.

| Goal                | Condition String             | Explanation                                |
| ------------------- | ---------------------------- | ------------------------------------------ |
| Sufficient Funds    | `wallet_balance >= msg_cost` | Check if user can afford the message.      |
| Stop Infinite Loops | `retry_count < 5`            | Only retry if attempted less than 5 times. |
| High Value Check    | `campaign_budget > 1000`     | Checks for large budget campaigns.         |
| Safety Cap          | `daily_sent <= 10000`        | Stops sending if daily limit is reached.   |

### 3. Smart Routing

Deciding which channel (SMS, WhatsApp, Email) to use.

| Goal              | Condition String                             | Explanation                                  |
| ----------------- | -------------------------------------------- | -------------------------------------------- |
| WhatsApp Priority | `has_whatsapp == "true" && opt_in == "true"` | Use WhatsApp only if installed AND opted-in. |
| Fallback Logic    | `channel == "sms"`                           | Use SMS as fallback channel.                 |
| Vendor Selection  | `country == "US"`                            | Route by country.                            |
| Cheap Route       | `msg_type == "marketing" && cost < 0.05`     | Send marketing only if route is cheap.       |

### 4. Audience Targeting

Filtering specific types of users.

| Goal            | Condition String                       | Explanation                                        |
| --------------- | -------------------------------------- | -------------------------------------------------- |
| VIP List        | `plan in [gold, platinum, enterprise]` | Matches high-tier users.                           |
| Active Users    | `status == "active" && !is_blocked`    | User must be active AND not blocked.               |
| Specific Domain | `email matches "@pixelcorp\.com$"`     | Matches only PixelCorp employee emails.            |
| Local Users     | `zip_code matches "^902\d{2}$"`        | Matches zip codes starting with 902 (e.g., 90210). |

### 5. Content Validation

Checking the message data before sending.

| Goal            | Condition String                           | Explanation                                    |
| --------------- | ------------------------------------------ | ---------------------------------------------- |
| No Empty Msg    | `message_body != ""`                       | Ensures message is not empty.                  |
| Contains Link   | `message_body matches "https?://"`         | Checks if a link exists in the text.           |
| Length Check    | `char_count <= 160`                        | Checks if message fits in one SMS segment.     |
| Variable Exists | `first_name != "null" && first_name != ""` | Ensures name is available for personalization. |

### 6. Complex Combinations

Combining multiple factors.

**Scenario:** Send a promo if the user is a VIP OR it's their birthday, BUT they must be opted-in.

* **Condition:** `is_vip == "true" || is_birthday == "true" && active_optin == "true"`
* **Logic:** (VIP OR Birthday) AND Opted-In

**Scenario:** Send via RCS if phone supports it, otherwise check if SMS is allowed.

This usually requires two steps, but in one node:

* **Condition:** `rcs_enabled == "true" || sms_fallback_allowed == "true"`
