> For the complete documentation index, see [llms.txt](https://docs.ownchat.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ownchat.app/bot/utility/if-statement.md).

# IF Statement

The **IF Statement** action allows chatbot builders to create **conditional logic workflows** inside the bot builder.

This utility action helps the chatbot evaluate conditions and make decisions automatically based on stored customer responses or variables. Depending on whether the condition is successful or fails, different chatbot actions can be triggered.

The walkthrough demonstrates configuring payment validation logic using variables, OR conditions, comparison operators, and automated response actions.

{% embed url="<https://app.supademo.com/demo/cmmvirtnk14jken0ywnofzgbu?utm_source=link>" %}

### When to Use IF Statement &#x20;

Use the **IF Statement** action when the chatbot needs to make decisions based on customer inputs, selections, or stored variables.

#### Common Use Cases &#x20;

* Payment method validation
* Lead qualification
* Order status checking
* Customer segmentation
* Conditional workflow branching
* Dynamic chatbot responses

**Example Interaction** &#x20;

User: Online Payment\
\
Condition Result:\
Success

The chatbot automatically triggers a success response when the condition matches the configured value.

### How to Add IF Statement &#x20;

Follow these steps to add the **IF Statement** action to your bot workflow.

1. Open **Bot Builder**
2. Click the **Add Node** button
3. Open the **Utilities** tab
4. Select **IF Statement**
5. Configure the condition settings
6. Add variables and values
7. Configure Success and Fail actions
8. Click **Create**
9. Click **Publish** to deploy the workflow

The walkthrough shows the IF Statement node being added from the Utilities section of the bot builder.

### Accessing the Utilities Section &#x20;

To access the IF Statement action:

1. Click **Add Node**<br>

{% embed url="<https://app.supademo.com/demo/cmpavopqv077kz70jnbhtqwga?utm_source=link>" %}

2. Open the action panel
3. Click the **Utilities tab**<br>

{% embed url="<https://app.supademo.com/demo/cmpavrduu066nz80jd1aujjnj?utm_source=link>" %}

The Utilities section contains workflow logic and automation actions.

### Selecting IF Statement &#x20;

Inside the Utilities tab:

1. Locate the **IF Statement** action.<br>

{% embed url="<https://app.supademo.com/demo/cmpavsx6y0003z20jb4338a6t?utm_source=link>" %}

2. Click the action to open the configuration panel.

The walkthrough highlights the IF Statement node used for checking conditions and making workflow decisions.

### IF Statement Configuration &#x20;

When configuring the **IF Statement** action, several fields must be completed.

#### Action Name &#x20;

The **Action Name** identifies the condition logic inside the workflow.

This name is visible only within the bot builder.<br>

{% embed url="<https://app.supademo.com/demo/cmpavtx8v077uz70jyihkq03c?utm_source=link>" %}

**Example** &#x20;

Payment Check\
Validate Payment Method\
Order Status Validation

The walkthrough demonstrates renaming the action to:

Payment Check

before saving the configuration.

### Condition Type &#x20;

The **Condition Type** field defines how multiple conditions should be evaluated.

Available options include:

* AND
* OR

The walkthrough specifically selects:

OR

as the logical operator.

{% embed url="<https://app.supademo.com/demo/cmpavvgr307msxa0jamnnptgn?utm_source=link>" %}

OR Condition Logic &#x20;

When using **OR**:

* The condition succeeds if **any one condition** matches.

Example:

Condition 1 = Online Payment\
OR\
Condition 2 = UPI

If either condition matches, the IF Statement returns **Success**.

### Operator &#x20;

The **Operator** field defines the comparison method used for validation.

To configure:

1. Open the **Operator** dropdown.
2. Select the required comparison type.

The walkthrough selects:

Is equals to

for comparing the variable value.<br>

{% embed url="<https://app.supademo.com/demo/cmpavxonh0673z80j0i4qim4c?utm_source=link>" %}

#### Key Field &#x20;

The **Key** field contains the variable that should be evaluated.

Before configuring the IF Statement:

The required value must first be stored using another action such as:

* Payment Collection
* Ask Actions
* Assign Variable

The walkthrough specifically notes that the payment value must first be collected and stored before being used in the IF Statement.

### Adding Variables &#x20;

To add a variable:

1. Click **Add Variable**<br>

{% embed url="<https://app.supademo.com/demo/cmpaw0iwt0675z80jv2b69lz6?utm_source=link>" %}

2. Search for the required variable
3. Select the variable from the list

The walkthrough demonstrates selecting:

payment

from the variables list.<br>

{% embed url="<https://app.supademo.com/demo/cmpaw455j078cz70j868fwt76?utm_source=link>" %}

The selected variable appears as:

{{variables.payment}}

inside the Key field.

### Data Type &#x20;

The **Data Type** field defines the type of data being validated.

Example types include:

* Text
* Number
* Boolean

The walkthrough uses:

Text

as the selected data type.

### Value Field &#x20;

The Value field contains the expected value for the condition.

Example:

Online Payment

The IF Statement compares the variable value against this configured condition.<br>

{% embed url="<https://app.supademo.com/demo/cmpaw61k20679z80jj0wc09pi?utm_source=link>" %}

### Adding Multiple Conditions &#x20;

To add additional conditions:

1. Click **Add New Condition**<br>

{% embed url="<https://app.supademo.com/demo/cmpaw9bb107n9xa0jcdnoxce6?utm_source=link>" %}

2. Configure another operator, variable, and value<br>

{% embed url="<https://app.supademo.com/demo/cmpawbcqr078lz70jedfnkd2n?utm_source=link>" %}

3. Repeat as needed

The walkthrough demonstrates adding multiple conditions using the OR operator.

### Creating the IF Statement &#x20;

After configuring all conditions:

1. Review the condition logic
2. Click the **Create** button<br>

{% embed url="<https://app.supademo.com/demo/cmpawdjlp078pz70j76yefnj5?utm_source=link>" %}

The IF Statement node will now appear in the workflow.

### Workflow Behavior &#x20;

Once triggered, the **IF Statement** action:

* Evaluates variables dynamically
* Compares values using operators
* Supports multiple conditions
* Triggers Success or Fail workflows
* Enables decision-based chatbot automation

The walkthrough specifically notes:

This is the condition that we have added in the IF statement. Here, you can see the logic that we have defined in the condition.<br>

{% embed url="<https://app.supademo.com/demo/cmpawouok0795z70ja6uteys6?utm_source=link>" %}

### Success and Fail Actions &#x20;

After creating the IF Statement:

* **Success** output triggers when the condition matches
* Fail output triggers when the condition does not match

You can connect any chatbot action to either output.

Example:

Success → Send Payment Confirmation\
Fail → Send Payment Failure Message

The walkthrough demonstrates dragging **Send Text** nodes for both Success and Fail conditions.<br>

{% embed url="<https://app.supademo.com/demo/cmpawqhl707nrxa0jmkw8xp18?utm_source=link>" %}

### Configuring Success Response &#x20;

To configure the success message:

1. Drag a **Send Text** node from the Success output<br>

{% embed url="<https://app.supademo.com/demo/cmpawrh9i0001xb0jktrkzrri?utm_source=link>" %}

2. Enter the action name<br>

{% embed url="<https://app.supademo.com/demo/cmpawzsx707spxa0jgy6p8qe5?utm_source=link>" %}

3. Add the success notification message<br>

{% embed url="<https://app.supademo.com/demo/cmpawrh9i0001xb0jktrkzrri?utm_source=link>" %}

4. Click **Create**<br>

{% embed url="<https://app.supademo.com/demo/cmpax0vuw079ez70jm1alclob?utm_source=link>" %}

Example:

Bot: ✅ Your payment method has been verified successfully.<br>

{% embed url="<https://app.supademo.com/demo/cmpaymxip009xu40j529p3a5t?utm_source=link>" %}

### Configuring Fail Response &#x20;

To configure the fail message:

1. Drag a **Send Text** node from the Fail output<br>

{% embed url="<https://app.supademo.com/demo/cmpayo6ad07uaxa0jr8t41u5z?utm_source=link>" %}

2. Enter the action name<br>

{% embed url="<https://app.supademo.com/demo/cmpaype6y07uexa0j3bep1uon?utm_source=link>" %}

3. Add the fail notification message<br>

{% embed url="<https://app.supademo.com/demo/cmpayqbrj00a0u40jsttscvrc?utm_source=link>" %}

4. Click **Create**<br>

{% embed url="<https://app.supademo.com/demo/cmpayt2wi06l3z80j9pub2jig?utm_source=link>" %}

Example:

Bot: ❌ Invalid payment method selected.\
Please try again.

### Publishing the Bot Changes &#x20;

After configuring the IF Statement workflow:

1. Review the Success and Fail paths
2. Click the **Publish** button<br>

{% embed url="<https://app.supademo.com/demo/cmpayx47f07dxz70jtl9tn105?utm_source=link>" %}

3. Deploy the workflow to production

The final step in the walkthrough demonstrates publishing the configured bot logic successfully.

### Example Workflow &#x20;

**Example Chatbot Workflow** &#x20;

Collect Payment Method\
&#x20;       ↓\
IF Statement\
&#x20;       ↓\
Success → Payment Approved\
Fail → Payment Rejected

**Example Interaction**&#x20;

User: Online Payment\
\
Condition:\
{{variables.payment}} = Online Payment\
\
Result:\
Success

The chatbot automatically routes the workflow based on the condition result.

### Best Practices &#x20;

Follow these recommendations when using **IF Statement.**

#### Store variables before validation &#x20;

Ensure customer responses are stored before evaluating conditions.

#### Use meaningful action names &#x20;

Clearly identify the purpose of the conditional logic.

#### Use proper condition operators &#x20;

Choose AND or OR based on your workflow requirements.

#### Keep conditions organized &#x20;

Avoid overly complex condition structures.

#### Test Success and Fail flows &#x20;

Verify both outputs behave correctly before publishing.

### Summary &#x20;

The **IF Statement** action allows chatbot builders to create **dynamic conditional workflows inside Ownchat bots.**

With **IF Statement**, you can:

* Build conditional chatbot logic
* Validate customer responses dynamically
* Compare variable values using operators
* Trigger Success and Fail workflows
* Automate decision-based chatbot interactions

This utility action helps businesses build **smarter chatbot automation and advanced workflow logic within Ownchat.**
