# Variables

Variables are used to store any information the bot knows about a user. This can be their preferred language, or the channel they're using, but also information coming from external data sources like, for example, an API.&#x20;

All variables used in a single conversation are stored in what is called a [user session](https://docs.chatlayer.ai/bot-answers/session).

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FXi1rr5qphUynDLWQQWJN%2FScreenshot%202024-06-06%20at%2013.24.43.png?alt=media&#x26;token=a4a81084-70e9-4ead-94ff-279be329d45d" alt=""><figcaption><p>The Variables pageL</p></figcaption></figure>

## Create a variable

To create a variable from the **Variables** page:

1. Click on **Create variable** 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%2Fy0uezE5HMsF6xYF5XcQ2%2FScreenshot%202023-09-12%20at%2011.51.53.png?alt=media&#x26;token=5572e47d-ac13-4120-9e33-db335964c978" alt="" width="375"><figcaption><p>Create a variable from the Variables page</p></figcaption></figure>

2. A window pops up. Fill in the **Name**, **Default value** and **Description**.

{% hint style="info" %}
For example, a default value can be used for URL path ensures the chatbot can always fetch data or interact with external services correctly.
{% endhint %}

{% hint style="danger" %}
Note that default values are:

* Limited to string data types.
* Exported with the bot export. It means that variables along with their default values will be overwritten at import.
* If a variable has a default value on the LIVE version, publishing won't change it. If not, the DRAFT version's default value will be copied to the LIVE version.
* If you use a [Clear session](https://docs.chatlayer.ai/buildabot/flow-logic/dialog-state/action-bot-dialog#clear-session) action, the value for a variable will be reset to its default value if it had been modified during the session.&#x20;
  {% endhint %}

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F3JmTArjZfAckM968gHXy%2Fimage.png?alt=media&#x26;token=cd7f0416-c2fe-4419-9fe2-13f7e4fe331e" alt=""><figcaption><p>Example of a variable with a default value to call an API endpoint.</p></figcaption></figure>

3. Click on **Create variable**.

## Set a variable as sensitive

Chatlayer allows you to make sure that some variables are processed differently. This is useful when the conversation between a bot and a user contains **sensitive information**, such as the user's bank account number or anything GDPR-sensitive.

{% hint style="danger" %}
If you set your variable as sensitive, its value will never be shown in Chatlayer. Instead, users will see a placeholder. The real variable value can only be retrieved through an [API request](https://api.chatlayer.ai/v1/docs/#operation/getAllMessagesInConversation).
{% endhint %}

To define a variable as sensitive:

1. [Create a variable](#create-a-variable) or edit it using the **Edit** button.
2. Toggle on the **Sensitive** switch if you don't want this variable to be saved in the conversation history.
3. Click on **Create variable**.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FMBOjwTf8Zl0PXska7RFS%2FScreenshot%202023-09-12%20at%2011.52.11.png?alt=media&#x26;token=7676b787-f9a8-4943-8df7-2d3acdefa6ea" alt="" width="375"><figcaption><p>Create a sensitive variable from the Variables page.</p></figcaption></figure>

## Operations on variables

You can perfom operations on your variables.

### Increment

If you want to incrementally increase the value of a variable, you can use the following steps:

1. Define a variable, for example `variableName`, and give it a numeric value such as `0`
2. At the point in the flow where you want to increment the value of `variableName`, enter variableName as the variable and `{variableName|increment}` as the value

This method will increase the value of counter by 1 each time, for example when a specific block is passed or a button is clicked.&#x20;

{% hint style="info" %}
Incrementing a variable can be typically useful when you want to count how many times the user wasn't understood by the bot. Learn how to build a **Not Understood Counter** [here](https://docs.chatlayer.ai/tips-and-best-practices/not-understood-bot-dialog/not-understood-counter).
{% endhint %}

### Change the case

Variables and values are case-sensitive.&#x20;

For example, `capitalVariable` will be regarded as a separate variable from`CapitalVariable`.

The same goes for values. If you check in a [Condition](https://docs.chatlayer.ai/buildabot/flow-logic/dialog-state/plugins) block if a value for `variableX` is equal to `valueY` it will not be triggered if the value for `variableX` is equal to `valuey`

You can transform a value from upper case to lower case and vice versa by adding these modifiers to the value name:

```
{name|toUpperCase}
{name|toLowerCase}
{name|capitalize}
```

{% hint style="warning" %}
Note that [Expression syntax \[Beta\]](https://docs.chatlayer.ai/integrateandcode/expression-syntax) allows you to get the flexibility to use code syntax functions in your bot without the need of extensive coding skills.
{% endhint %}
