Table of Contents

Variables in Landbot - Getting Started

Sofia Teran Updated by Sofia Teran

What is a Variable? ๐Ÿ’ฌ

Every time you ask for a question in the bot and want to store that answer somewhere, you save this answer (value) in a variable.

Think of a variable as a "box" that you can give a name and store "things" inside.

In this case, those "things" can be values you give to that variable.

What are the variables format? ๐Ÿ“

Some blocks have a format by default, that you can't change. Nevertheless, is possible to make operations to change a variable type, but it is easier if you choose the block wisely beforehand ๐Ÿ˜‰

According to the use, you will give to the variable you must choose a specific format for each one, like Date, Number, String (Text), and Array.

String (text):ย This is the most flexible type of variable. It is usually used to save Text inside it, but you can also add numbers, dates, signs, emojis, hyperlinks, etc.

Number:ย here you can ONLY save numbers, not symbols or letters.

ย Date: save dates inside these variables.

Array:ย is used to store the collection of data but is more often useful to think of it as a collection of variables of the same type.ย An array variableย is very handy if you are a developer or if you want to try out more of our technical features and workarounds.

Boolean:ย Youย can't create or save variables in this typeย due this is a system variable that is used only in a Condition block to check if the agents are online.

How do the variables work? ๐Ÿง

As the name says itself, the value you save inside a variable may change according to the answer given by the user, or the choices made throughout the bot flow.

To create a variable:

  1. Select a block and add it to the builder.
  2. Scroll down to Save answers in the field.
  3. Name the variable whatever you want, but note that it must always have @ (symbol) before the name.
  4. Choose the format of the variable (number, string, date, array) and save it.
Tip: The Name you assign your variable should be accurately descriptive and understandable to another Teammate in your account ๐Ÿ˜‰
Example 1

If I want to ask for the user's name (value) and save it in the variable @name :

You can create or customize a variable in a block, in the Save answers in the variable > Custom variables subsection of each block.

When 2 different users go through the bot flow, the variable will have the same name ( @name ), but the value will be different for each user:

As you can see in this example, the variable where we store the name of the user is the same, saved under the name @name but the value stored in it will change according to what each user answers. So:

@name = Maria

@name = Paul

Example 2

In the next Button block, the answer will be saved in the variable @testing:

Then we will use the variable @testing in a Message block, to inform the User which option has been chosen before.

To add the variable to the block, we have two options:

  1. Write @testing in the Send a Message block:
  1. Click on the VARIABLES option of the Send a message block (variables list), and choose the variable:
  • Write testing and choose the correct custom variable:
  • Click on the variable testing, then the result will look like this:
  • Now, the final view in the chatbot will be, according to the choice of the user in the Buttons block:

May I reuse variables in distinct blocks? ๐Ÿค“

Sure thing! ๐Ÿคฉ

Example 1

Let's continue with our previous case scenario but now we'll ask for the age as well:

  1. Add the block Question: number in the builder and save the answer in the variable @age
  1. Now add the variable @age in the Send a message block with both variables (@name and @testing):
  1. This is how it sees in the builder:
  1. Last but not least, the chatbot final view:
Tip: you can combine more than two variables. Just be aware that the Send a message block can't be saved in a variable.
Example 2

๐Ÿ‘€ If you want to use two similar blocks, Buttons block, in different parts of the bot, you will have to change the name of the variable set by default so that the previous variable is not overwritten

  1. We added the first Buttons block, then we created and save in the variable named @food_options
  2. We added the second Buttons block, then we create and save in the variable named @drinks

Landbot's System variables types:

Landbot has it owns System Variables that you can use in your bot flow and consult in the Metrics and Chats section.

  1. Variables Lead Data
    Although these are system variables, they can be edited:

Example:

In the next case scenario, we added the Question: email block, as you can see this have the @email variable by default, but we change it to @email_support

  1. Variables Usage details

You will be able to identify which ones are the System variables Usage details because they come with a lock ๐Ÿ”’next to it, so you can't edit them

Note: You can find more information about it by clicking here Landbot System Variables ๐Ÿ”—

May I use a custom variable and a system variable in the same block? ๐Ÿ–‡

Of course, you can! ๐Ÿฅณ

Let's imagine that you want to ask the name of a user, and saved it in a variable to use it later with the previous @testing variable:

  1. Add the block Question: Name in the builder, the answer will be saved by default in the variable @name
  1. Add the variable @name in the Buttons block (to refer to your customer by personal name):

  1. Now, add the variable @name and the variable @testing in the Send a message block:
Here we mixed the ways to typing the variables (choosing through the variables button or writing with the @ symbol before the name)
  1. You will see it like this in the builder bot:
  1. Then, the final view in the chatbot will be:

Are there other uses with variables? ๐Ÿ™Œ๐Ÿป

Yes, they are! You can see some of them here:

Set a Variable

This is a powerful block that allows you to create, establish a format, and set (define) value to a variable, as you can see in this article.

Reset a variable

You can use the Set a variable block to reset a variable, in the next example we made it through the Welcome message block:

  1. Make the Welcome message an Open question deleting the Button:
  1. Add a Set variable block and write @name in the variable to modify and type @welcome in the value:
  1. You can add a Send a message block to confirm that the reset was made correctly:
  1. The final view in the Builder will be:
  1. And the final view in the chatbot will be:
Display images

With a variable containing a URL source, as you can see in this article.

Make a counter for variables

You can find further information about it in this article or this demo ๐Ÿคฉ

Additional information โš ๏ธ

  • Is not possible to leave a variable without values.
  • Is not possible to drop variable
  • If the variable has a value and you want to give it another value or change the format, you can use the Set a variable block to do it.
  • If you find a blank variable list it's because the user didn't answer the question that had that variable.

How did we do?

Contact