# 4. Steer the conversation with Conditions

Apart from being re-used inside the conversation itself, variables can help the bot steer the conversation in different directions, by using Condition blocks.

<figure><img src="/files/uoxeJhNu5mJESOqRJnMv" alt=""><figcaption><p>What we will build in lesson 4. </p></figcaption></figure>

## Step 8: Check a variable in a Condition block

Our Bee bot now asks if the user is new, then asks the user information.

We would like Bee to give a slightly different answer depending on if the user is new or returning. To do so, we’ll need a **Condition** block that checks a {userType} variable.

<figure><img src="/files/eHGiz2ru8RbHdXue0qgr" alt=""><figcaption><p>The Condition block type.</p></figcaption></figure>

{% hint style="success" %}
&#x20;[Condition](https://docs.chatlayer.ai/bot-answers/dialog-state/plugins) blocks enable your bot to redirect the user to another block depending on the conditions of the session variables, following an if-then logic.
{% endhint %}

### Get variables under button clicks

We’ll save a {userType} variable under button click of the **Check user type** block. This variable can have either the value *returning* or *new*.

To save a variable under a button click:

1. Open the **Check user type** block.
2. Under the first **I’m new** button, click on **+ Add a variable** and create the variable *userType.*

<figure><img src="/files/3Hnvl7mlSSEirZRKtEsJ" alt="" width="302"><figcaption><p>Create a variable under a button click.</p></figcaption></figure>

3. Add the value *new*.
4. For the second button, do the same with the value *returning*.

<figure><img src="/files/ToCEK8iTe2ItoKavjeIB" alt=""><figcaption><p>Make your Go-to buttons capture variables.</p></figcaption></figure>

5. **Save** your changes.

Now, when a user clicks on one of these buttons, the system will remember the {userType} variable. Let's utilize this variable within a Condition block.

### Add a Condition block

We aim to create a Condition block that evaluates the {userType} variable and provides a different response based on its value.

To add a Condition block:

1. Open the **Next block** block.
2. Go to its **Settings**.
3. Change its Type to **Condition**.

<figure><img src="/files/ONsicW28araGFlirAjnj" alt=""><figcaption><p>Change a block dialog type from its Settings.</p></figcaption></figure>

4. You’ll get a warning message. Click **Yes, change type**.
5. Under **Bot dialog name**, change the block name to *Route userType*.

<figure><img src="/files/VS9tHBKE3qyBxndt7bXV" alt=""><figcaption><p>Change a block name from its Settings.</p></figcaption></figure>

6. Go back to its configuration, and click on the **+** to add your first condition.
7. Fill in the block as follows, using the **equal case insensitive operator**:
   * If {userType} = new,
     * then Go to **Send email new user**. You can create this new block directly from the text field.
   * Else if {userType} = returning,
     * then Go to **Send email returning user**. You can create this new block directly from the text field.
   * Else:
     * Go to **Error occurred**.

{% hint style="success" %}
The Error occurred block is a [default block](https://docs.chatlayer.ai/bot-answers/dialog-state#default-blocks) triggered when an API integration fails to complete a certain request, or when Chatlayer considers your bot to be blocked in a loop.
{% endhint %}

Your window should look like this:

<figure><img src="/files/O7xEcguCPBDThI9EcT8a" alt=""><figcaption><p>Fill your Condition block with conditions.</p></figcaption></figure>

8. **Save** your changes.

Your canvas looks a bit messy now, and that’s totally normal. Let’s organize it a bit:

### Organize your flow

To re-organize your flow when it looks messy, click on the **Auto-layout** button at the bottom-right corner of your canvas.

<figure><img src="/files/tvd7FvUz1ucg8nGGWHn8" alt=""><figcaption></figcaption></figure>

What we created should look like this now:

<figure><img src="/files/gOBsnoqpDCWaM7sPehm2" alt=""><figcaption><p>What your canvas should look like at this point.</p></figcaption></figure>

## Lesson 4 recap

Congratulations! In this lesson, you’ve learned how to:

* [ ] Store variables from button clicks.
* [ ] Add a Condition block.
* [ ] Check variables inside a Condition block and steer the conversation accordingly.
* [ ] Organize your canvas by using Auto-layout.

## Coming next

Coming next, we’ll see how to connect your bot to 3rd party providers so that you leverage your bot’s functionalities.

{% content-ref url="/pages/hejRQvvKlH9sxWwhYqF6" %}
[5. Empower your bot with Actions](/start-quickly/leadzy-tutorial/5.-empower-your-bot-with-actions.md)
{% endcontent-ref %}

## 💬 Feedback

{% hint style="warning" %}
Your feedback on the tutorial means the world to us! Please, let us know what you think through [this short form.](https://forms.office.com/Pages/ResponsePage.aspx?id=ropROyGJe0qEl2GddWziDlEYn6XpsIRDjnCtdRk8L21UMFZMMlAzN0tHOTI4UjMxVTgzTVAwTE5aOCQlQCN0PWcu)
{% endhint %}


---

# 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.chatlayer.ai/start-quickly/leadzy-tutorial/4.-steer-the-conversation-with-conditions.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.
