Table of Contents

Variables in Landbot - Getting Started

Jonathan Goodfellow Updated by Jonathan Goodfellow

Prefer watching than reading? No problem, we've got you covered πŸ‘‡

What is a Variable? πŸ’¬

Every time you ask 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, it's 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:Β An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, like a String or Number.Β 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's seen 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 saved in the variable named @food_options
  2. We added the second Buttons block, then we created and saved in the variable named @drinks

Landbot's System variables types:

Landbot has it's own 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 has 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 save 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 ⚠️

  • It's not possible to leave a variable without values.
  • It is not possible to delete a variable once you've created it.
  • However, it is possible to manually delete the variables for a specific user in the Chats section. Only the variables you’ve created (Custom Variables) will be deleted, not the Landbot System Variables. Click here for more information.
  • It is not possible to change the type of variable eg. string to number once it is set.
  • If a variable has a value set and you want to overwrite it, you can use a set variable block.
  • If you find a blank variable list it's because the user didn't answer the question that had that variable.
  • Arrays have a limit of 1MB anything more will cause errors in the Dynamic Data block.

How did we do?

Landbot System Variables

Contact