# 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FOpTqVBEPZ3mUui0Hf7Dq%2FChooChoo%20tutorial%20rework%20(1).jpg?alt=media&#x26;token=00288ef5-a306-49d6-a153-0a5c5b3219a5" 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FeXQDTkIVjsNPMgyrSti9%2FScreenshot%202024-02-07%20at%2015.22.07.png?alt=media&#x26;token=2f099ed1-95ab-45c1-843d-29cd3976b9cd" 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FyvSA3svIfKYqhW3jVxTo%2FScreenshot%202024-03-07%20at%2010.40.50.png?alt=media&#x26;token=a19b205a-142e-49d8-abfd-897c3b2684f4" 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fsvwqt2MuKk6TovRkgC5c%2FScreenshot%202024-03-07%20at%2010.41.41.png?alt=media&#x26;token=6a64d6bc-10a9-469f-817a-45eaf734dbd8" 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FdPavNOfNDFCfn9ByPSWz%2FScreenshot%202024-03-07%20at%2010.44.58.png?alt=media&#x26;token=9332a770-a8cb-4010-b98f-aad38c4da854" 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FVpeMkuYyMzPTWBs1sh1B%2FScreenshot%202024-03-07%20at%2010.46.52.png?alt=media&#x26;token=0f2784c6-b38c-49f0-b825-f69c899f6038" 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FMnEeGhjLjfF55ACpMLvY%2FScreenshot%202024-03-07%20at%2010.51.53.png?alt=media&#x26;token=aa6e3679-c1d2-4a78-b000-ed297a75d3d4" 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Ffqd3UDD83T7dxXhKLhdR%2FScreenshot%202024-03-07%20at%2010.53.15.png?alt=media&#x26;token=e0582baa-a496-4199-bbe1-9f3001c9a745" alt=""><figcaption></figcaption></figure>

What we created should look like this now:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F0fRltJgtmzgOc4V5zmhj%2FScreenshot%202024-03-07%20at%2010.54.13.png?alt=media&#x26;token=1fffcd9b-b143-4209-b453-6a73b9dd0095" 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="5.-empower-your-bot-with-actions" %}
[5.-empower-your-bot-with-actions](https://docs.chatlayer.ai/start-quickly/leadzy-tutorial/5.-empower-your-bot-with-actions)
{% 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 %}
