# 3. Collect and display user input

On Chatlayer, collecting responses from your users can be done in 3 ways:

* by using button clicks, which are better for closed questions, i.e. question with a limited set of possible answers.
* by using Collect input blocks, which are better for open questions, i.e. question with an open-ended set of possible answers.
* by using entities.

{% hint style="success" %}
&#x20;[Entities](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp/synonym-entities) are a special NLP feature to detect information within the user message. You’ll discover more about them in another tutorial.
{% endhint %}

In this lesson, you’ll learn how to use button clicks and Collect input blocks to save information that can be reused later.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FvgGsqwTgsVElWoE9jxdb%2FChooChoo%20tutorial%20rework.jpg?alt=media&#x26;token=5607ad24-edd8-4ead-a60b-62fea043417e" alt=""><figcaption><p>What will be built in this lesson.</p></figcaption></figure>

## Step 6: Get responses from button clicks

A nice-and-easy way to get input quickly from your users is to add buttons to your chatbot.

We’ll create a block that asks whether if user is a new client, which will then give a different answer.

### Add buttons

To add buttons to your bot:

1. Go to your canvas.
2. Drag and drop a **Message** block to your canvas.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fz8kcaRCMX6LeXWo4Fpom%2FScreenshot%202024-03-07%20at%2009.31.54.png?alt=media&#x26;token=2be6dd05-f0c3-416a-a133-dc7ab1e08a97" alt="" width="375"><figcaption><p>Add a Message block to your canvas.</p></figcaption></figure>

3. The block opens on the right hand side of the screen. Add a **Buttons** step to your block by clicking on it.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fh3CKu83zhniraPNGmbgP%2FScreenshot%202024-02-06%20at%2012.57.50.png?alt=media&#x26;token=e7e23fd2-08fb-4195-82e1-ce51c6f37bb1" alt="" width="375"><figcaption><p>Add a Buttons step to your block.</p></figcaption></figure>

4. As a **Text message**, add: *Is it your first time shopping with us?*
5. Under it, click on **Add button**.
6. Click on **Go to**.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FhTwkzqz4wAbUALVQR6Gp%2FScreenshot%202024-03-07%20at%2008.43.03.png?alt=media&#x26;token=283139fc-7f28-46b8-880f-df54bede1e20" alt="" width="375"><figcaption><p>Add a Go-to button to your block.</p></figcaption></figure>

{% hint style="success" %}
A [Go-to button](https://docs.chatlayer.ai/bot-answers/go-to-connections#go-tos-in-buttons) is a button that, when clicked, goes to another block in the conversation.
{% endhint %}

7. Under **Title**, add *I’m new*.
8. Under **Go to**, create a **Message** block called ‘Welcome new user’. It is a placeholder where will come back to later in the tutorial.
9. Repeat the same step to create another button called *I’m a client already* which goes to a new block that you’ll call *Welcome returning user.*

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FiaMOPKp2V1iP0jNolF8w%2FScreenshot%202024-03-07%20at%2008.49.53.png?alt=media&#x26;token=3fe69217-1e64-4b58-823c-107ae658261b" alt="" width="375"><figcaption><p>Fill your buttons with a title and a Go-to.</p></figcaption></figure>

10. **Save** your changes.

Your buttons are created! Let’s define what happens when they’re clicked now.

### Define responses after clicks

Time now to modify elements on your canvas so that the right block leads to the right answer.

{% hint style="info" %}
Your canvas offers flexible and multiple ways of navigating in it. Learn all about it [here](https://docs.chatlayer.ai/bot-answers/bot-canvas/canvas-functionalities).
{% endhint %}

#### Change a block’s name and content

1. From the canvas, double click on the last block you created to change its name:
   * Call it *Check user type*.
   * Click the **Checkmark** icon to save it.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FmVAByC9ExQMEMQ5WyDwO%2FScreenshot%202024-03-07%20at%2009.34.49.png?alt=media&#x26;token=badc7c4a-8f8d-48b1-896f-bb4987497c28" alt=""><figcaption><p>Change your block name directly from the canvas.</p></figcaption></figure>

2. Open **Welcome returning user** and and change its content to: *Great to see you again!*
3. Open **Welcome new user** and change its content to: *Welcome then! It's your very lucky day: we have an extra 5% off for newbies!*

The changes should look like so on your canvas:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FOHWb1y2ywcIn6rsA8tgH%2FScreenshot%202024-03-07%20at%2008.55.10.png?alt=media&#x26;token=489b3ba2-f55e-476c-a759-1afea9fbc902" alt="" width="375"><figcaption><p>Each button clicked triggers a different block.</p></figcaption></figure>

Good, your user can now click on a button and have a response accordingly. Let’s make sure that this question follows the previous steps of the conversation.

#### Draw Go-to connections

1. Draw a Go-to connection between **Yes to discount** and **Check user type** by holding down the mouse from the bottom-down node of your **Yes to discount** block.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fa8HpF2at4dpoBsqm48fd%2FScreenshot%202024-03-07%20at%2009.00.15.png?alt=media&#x26;token=ac13e7e7-5704-4e52-804b-053b78d8b073" alt=""><figcaption><p>Draw Go-to connections from your canvas.</p></figcaption></figure>

{% hint style="success" %}
A [Go-to connection](https://docs.chatlayer.ai/bot-answers/go-to-connections) between block A and block B means that block B will happen right after block A in the conversation. Go-to connections are respresented as plain arrows on your canvas.
{% endhint %}

2. Test your bot. If everything works fine, your conversation 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%2FCO9umYNolxRVI9xySCig%2FScreenshot%202024-03-07%20at%2009.11.10.png?alt=media&#x26;token=95799b0e-a386-430b-b0fa-09a555b87195" alt="" width="280"><figcaption><p>Test your buttons flow.</p></figcaption></figure>

You've successfully added buttons to your bot for answering closed questions. Now, let's learn how to pose more open-ended questions.

## Step 7: Use Collect input blocks

Remember, our Bee bot project is a lead generation bot. We've reached the part of the bot flow where you'll collect people's details for future use.

On Chatlayer, you can gather open-ended responses during the conversation using Collect input blocks.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F44eDozRzl78TYTckpkYy%2FScreenshot%202024-02-06%20at%2014.17.35.png?alt=media&#x26;token=6606c68b-42f4-4008-a946-23ae4b97ef50" alt="" width="134"><figcaption><p>The Collect input block.</p></figcaption></figure>

{% hint style="success" %}
[Collect input](https://docs.chatlayer.ai/bot-answers/dialog-state/user-input-bot-dialog) blocks are useful to get input from your user, check it, and save it as a variable that you can re-use later on.
{% endhint %}

### Add a Collect input block

1. From your canvas, drag and drop a **Collect input** block.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FcGm0vIQznhKe1Wk84fHM%2FScreenshot%202024-03-07%20at%2009.39.20.png?alt=media&#x26;token=33e76e02-4abf-47c0-8527-a1d30df74534" alt=""><figcaption><p>Add a Collect input block to your canvas.</p></figcaption></figure>

2. The block opens to the right-hand side.
3. Under its **Settings**, change its name to *Ask name*.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FvMAyXbCUMMTlpvJOF1Qv%2FScreenshot%202024-03-07%20at%2009.39.56.png?alt=media&#x26;token=5d35646f-4abb-492c-9def-b4d08492c643" alt="" width="330"><figcaption><p>Change a block name from its Settings.</p></figcaption></figure>

4. Come back to the block configuration and add a **Text step**.
5. Fill it with the following message: *What’s your name?*
6. Under **Check if response matches**, choose **any**.
7. Under **Destination variable**, create a new variable that you’ll call `userName`.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FDv7nbiAgV9DrWZN75jii%2FScreenshot%202024-03-07%20at%2009.40.56.png?alt=media&#x26;token=146c61ba-031f-4034-a1ff-9d238b945e22" alt="" width="323"><figcaption><p>Check if a Collect input responses matches a variable.</p></figcaption></figure>

8. Under **Go to**, create the next block which will be a **Collect input** block called *Ask email*.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FjgD7C49Iw0wl8HWFIK27%2FScreenshot%202024-02-06%20at%2014.30.41.png?alt=media&#x26;token=75ada538-8fa5-49e5-93f6-6101cdfe6ee8" alt="" width="375"><figcaption><p>Create a Collect input from a Go to.</p></figcaption></figure>

9. **Save** your changes.
10. Draw a Go-to connection between **Welcome new user** and **Ask name**.
11. Draw a Go-to connection between **Welcome returning user** and **Ask name**.

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%2FD4t9niqbE526dABKI1Ns%2FScreenshot%202024-03-07%20at%2009.45.44.png?alt=media&#x26;token=1051ea3d-aed3-4f1f-b609-d8a0cc991f02" alt=""><figcaption><p>What your canvas should look like at this stage.</p></figcaption></figure>

## Step 8: Re-use a variable in the conversation

So that the user feels heard, we would like to re-use their name we’ve just collected in the previous block. To do so, we will re-use the {userName} variable.

{% hint style="success" %}
[Variables](https://docs.chatlayer.ai/bot-answers/settings/secure-variables-gdpr) are used to store any information the bot knows about a user. They can be reused inside text by using curly braces {}. Learn more about variables [here](https://docs.chatlayer.ai/bot-answers/settings/secure-variables-gdpr).
{% endhint %}

To reuse a variable inside text:

1. Open your **Ask email** block.
2. Change its content so that it asks *Great {userName}, and your email?*
3. Under **Check if response matches**, select **@sys.email.**

{% hint style="info" %}
Chatlayer offers [pre-defined](https://docs.chatlayer.ai/bot-answers/dialog-state/user-input-bot-dialog#system-entities-input-type) entities to recognize emails, phone numbers or URLs. They provide a time-saving way to build your Collect input blocks!
{% endhint %}

4. Under Destination variable, create {userEmail}.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FEgG9MBpDfc9SYq9osMnr%2FScreenshot%202024-03-07%20at%2010.00.10.png?alt=media&#x26;token=8df5bf1b-7c3a-4218-900a-907417c8a514" alt="" width="325"><figcaption><p>Save the user email under a variable.</p></figcaption></figure>

5. As a Go-to, create a placeholder block called **Next block**.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FQSMbLNuLzT76fQWELGZP%2FScreenshot%202024-03-07%20at%2010.00.38.png?alt=media&#x26;token=ddec85d5-9088-4377-a206-e838ded18825" alt="" width="334"><figcaption><p>Create the Next block from the Go to.</p></figcaption></figure>

6. **Save** your changes.
7. Fill your **Next block** with a placeholder text like *This is a next block*.
8. **Save** your changes.

What you’ve created should look like so on your canvas:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fe9L183F6FJj8zHYWLBMC%2FScreenshot%202024-03-07%20at%2010.30.39.png?alt=media&#x26;token=6f33f05b-9a1e-4604-a9f8-31ff9c98ad85" alt=""><figcaption><p>What your canvas should look like at this stage.</p></figcaption></figure>

What happens after we implemented something? Testing of course!

### Test your Collect input

You can test your bot from anywhere in the conversation. We’re going to test the small piece of flow we’ve just created only, and see that the variable is indeed understood in the back-end.

#### Test from the middle of a flow

To test a bot from the middle of a flow:

1. Click on the **Ask name** block.
2. A toolbar opens. Click on the **Test** button.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FFIjePXa2pZUlOsG1ybzq%2FScreenshot%202024-02-06%20at%2015.51.36.png?alt=media&#x26;token=26256e34-ec1c-449e-be14-52aa9e69be89" alt="" width="374"><figcaption><p>Test your block from the canvas.</p></figcaption></figure>

3. Test your piece of flow with the Collect input blocks. Your conversation 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%2FMq1mLTwZ4i2K0BvNpXBN%2FScreenshot%202024-03-07%20at%2010.08.53.png?alt=media&#x26;token=f45e7b5f-93f2-43d3-a357-d2a878c755a8" alt="" width="280"><figcaption><p>Test your Collect input flow.</p></figcaption></figure>

#### Check the variable in the user session

The Debugger tab allows you to check your session data and see for yourself that a variable is indeed understood. To do so:

1. Open the Test your bot window.
2. Click on the Debugger icon at the top-right corner of the screen.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FGqVX6i44hN04ghyEzSVc%2FScreenshot%202024-03-07%20at%2010.13.40.png?alt=media&#x26;token=8a2b4154-2d44-494d-bc16-286f735b32b0" alt=""><figcaption><p>Open the Debugger from your Test window.</p></figcaption></figure>

3. Read down the **Session data** and see that {userName} and {userEmail} indeed exist and are filled with the right values.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FsY82XVU9KuwEVmDBpTBB%2FScreenshot%202024-03-07%20at%2010.15.34.png?alt=media&#x26;token=d38bc1d7-b327-47a9-b445-25ad6a7d9216" alt=""><figcaption><p>Check your variables in the Debugger.</p></figcaption></figure>

{% hint style="success" %}
The [Debugger](https://docs.chatlayer.ai/tips-and-best-practices/solving-bot-issues#debugger-tab) is useful to detect where an issue comes from if something went wrong with the behavior of your bot.
{% endhint %}

Hurray! You’ve collected a response and used it inside your conversation, just like humans do.

## Lesson 3 recap

In this lesson, you’ve learned how to:

* [ ] Add buttons to your chatbot.
* [ ] Steer the conversation based on a button click.
* [ ] Get user input by using Collect input blocks, and store it as a variable.
* [ ] Reuse variables inside the conversation.
* [ ] Draw Go-to connections from your canvas.
* [ ] Change a block’s name from your canvas.
* [ ] Test your bot from a certain block in the conversation.
* [ ] Use the Debugger to check that a variable is working.

## Coming next

In the next lesson, we’ll explore how to use variables at any point of the conversation to steer it based on certain conditions.

{% content-ref url="4.-steer-the-conversation-with-conditions" %}
[4.-steer-the-conversation-with-conditions](https://docs.chatlayer.ai/start-quickly/leadzy-tutorial/4.-steer-the-conversation-with-conditions)
{% 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/3.-collect-and-display-user-input.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.
