> For the complete documentation index, see [llms.txt](https://docs.chatlayer.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chatlayer.ai/~/changes/zWOY8fNiBBrqneKkuGvA/tutorials/tutorial-your-first-bot/tutorial-conditional-flow-navigation.md).

# 5. Flow navigation with variables

In this tutorial we will look at how to steer the conversation depending on user input.

## Step 19: Go to bot dialog

The `Go To`  dialog enables the bot to redirect the user to another dialog, depending on conditions of the session variables. You can define conditions with operators like `equals`, `greater than`, `smaller than`, etc. You can also combine multiple conditions with `AND` and `OR`.

Consider the following scenario where the user asks the bot the following:

> I want to book a train from Paris to London in first class please.

We already have a lot of information in this expression. Let's say we now want to show a different message for first class tickets, seeing there are more facilities in first than in second class.

* Drag and drop a Go To dialog to your canvas

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FqZ306G8gAB2O7PETDvSA%2FScreenshot%202023-04-25%20at%2013.15.00.png?alt=media&amp;token=e26c11a5-2cee-4fcf-90e5-7999376a5d42" alt=""><figcaption><p>Drag and drop a Go To dialog to your canvas</p></figcaption></figure>

* This will open the Go To dialog
* Click on '+' to add an If condition
* Fill the condition so that if the variable *class* equals *first,* then the bot will go to a new bot dialog that you'll call `Selected first class.` It should look like so:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FaL3kFkK9Ezfy28fn51gl%2FScreenshot%202023-04-25%20at%2013.18.19.png?alt=media&amp;token=d14b56f5-dbb7-45eb-bc86-9c17ef3c5a38" alt=""><figcaption><p>Make an If condition within a Go To dialog</p></figcaption></figure>

* Click on '+' again to add another condition, and fill it in so that it checks if the selected class was *second*. Steer the conversation to a new `Selected second class` dialog accordingly. It should look like so:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FUTgWMtJpA2jZpBZjojaZ%2FScreenshot%202023-04-25%20at%2013.22.43.png?alt=media&amp;token=5453c40c-d8d5-4db8-bca5-547c67e6a9ac" alt=""><figcaption><p>Make an Else If condition within a Go To dialog</p></figcaption></figure>

* If the user has selected no class at all, we want to redirect the user to the bot dialog `,` which we already created. There, the traveler will be asked explicitly in which class they want to travel. Fill your last condition accordingly:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FAfHKbUPHsg1dfHKeCaHA%2FScreenshot%202023-04-25%20at%2013.27.40.png?alt=media&amp;token=bf39052d-6889-4814-8a6e-72e5f7ae4a7b" alt=""><figcaption><p>Fill an Else condition within a Go To dialog</p></figcaption></figure>

* Now, on top of the window, click on `Settings`
* Change the bot dialog name by 'Class redirect'
* Click `Create` to save your changes

On your canvas, your Go To dialog should look like so:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FxKBBu0g4YjlaQWcajQAi%2FScreenshot%202023-04-25%20at%2013.29.50.png?alt=media&amp;token=3ca44fe3-5061-48bf-9180-e81503877821" alt=""><figcaption><p>The Go To dialog Class redirect checks the class and redirects the conversation accordingly.</p></figcaption></figure>

## Step 20: First class options

Let's now add buttons to our dialogs so that the user can also choose a seat on the train. To do this, we will save the user seat option under a variable:

* Open the `Selected first class` bot dialog
* Click on `Buttons`
* Add the following text message: *What kind of seat would you like?*
* Click on `Add button`, select `Go to`
* Under `Title`, write *Window*
* Under `Go To`, select the `Confirm booking` dialog
* Click on `+ Add a variable`
* Fill the `Variable` with *seat* and the `Value` with *window*
* Do the same for the aisle seat option until it looks like so:&#x20;

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FcjauNQKUn601YAnQrY7i%2FScreenshot%202023-04-25%20at%2015.27.39.png?alt=media&amp;token=19c45680-576f-4401-883d-a65e3566cf6a" alt=""><figcaption><p>Save the user input into a variable by using buttons</p></figcaption></figure>

* Click on `Save` to save your changes

Now your user's seat option is asked and saved through a button click!

## Step 21: Final touches

* Open `Selected second class` bot dialog
* Click on `Text` to add a text message
* Enter the following message in the text field: *Second class confirmed*
* Scroll down, and under `Go To`, select the `Confirm booking` dialog
* Click `Save` to save your changes

At this stage, your canvas should look like so:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F4IcrxB9JkMgh3xwqW9zj%2FScreenshot%202023-04-25%20at%2015.34.28.png?alt=media&amp;token=cc2fb54a-6190-4b23-8e13-32512d9b2dae" alt=""><figcaption></figcaption></figure>

Now, let's make sure that after the user was asked for a departure date, then the bot checks if they have selected a class:

* Open the `Departure date` dialog by double clicking on it
* Change its `Go to` to the `Class redirect` Go To dialog
* Click `Save`
* Open the Class dialog by double clicking on it
* Change the `Go to`'s inside the Quick Reply Buttons so that they Go to `Class redirect`
* Click Save&#x20;

Your canvas should look like so:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FMLK9SQfoO67mtXMTfDzc%2FScreenshot%202023-04-25%20at%2015.42.01.png?alt=media&amp;token=bdba51f6-0582-4ca5-8eed-dbca2a80b472" alt=""><figcaption></figcaption></figure>

What we have now done, is that in `Class redirect` we check if the class has already been given in the expression by the user. If that is the case, we confirm second class or give extra options for first class. If class has not been given yet, the user can choose this in the `Class` Input Validation. If the user chooses their class in the Input Validation, then they are redirected to the class options.

Let's test this new functionality in the emulator:

![](https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LLTwFwbOqJj4dDhg8Ju%2F-MWixY5tBqI3mO5AlzMA%2F-MWiyL__jl2G4FBAaMmq%2Fimage.png?alt=media\&token=14e8ed11-d088-4e59-bc92-4b78b2aefbc3)

That looks great! If something is not working correctly, double check the Go Tos in the bot dialogs. Sometimes the parent is changed, but the Go Tos not and that can cause issues.&#x20;

## Lesson recap

That was it! You have completed Choo Choo, great job!&#x20;

You should now be comfortable with the basics of bot building on the Chatlayer platform:

* Creating Bot Messages
* Asking for user input in Input Validations
* Creating intents and expressions&#x20;
* Using contextual entities&#x20;
* Using a Go To to steer the conversation&#x20;

Make sure to check out the rest of the documentation as well.&#x20;

Good luck with building your own bot! If you have any questions, please do not hesitate to contact us at <support@chatlayer.ai>.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.chatlayer.ai/~/changes/zWOY8fNiBBrqneKkuGvA/tutorials/tutorial-your-first-bot/tutorial-conditional-flow-navigation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
