Variables, also known as attributes, allow to save user information. With variables you can easily gather information through the chat or the user profile and use it in the dialogue with the chatbot, when sending notifications in WhatsApp or in chatblocks when manually responding to a ticket.
Here are some examples for the use of variables:
- Saving user preference: product color preferences, travel destinations…
- Personalizing conversation: e.g. addressing user by a name
- Targeting: creating target user groups for notification/content distribution, e.g. personalizing content sent to a user based on the selected news categories
- Conditioning the conversation flow: e.g. if user name is already known, a user should not be asked for it again
Creating variables
Variables must be assigned a name (for example, age) and a data type (for example, number). It’s also possible to assign further attributes, such as a label, a range of valid values, default value, as well as determine variable’s lifespan and visibility on a user profile.
Name
The name of the variable is defined in the relevant field. When creating dialogues in the chatbot builder you can call a variable by setting its name between two $ signs. For instance, $first_name$ in the field “user question” in a dialogue signals the bot that user’s input should be saved as the first name. Variable names are case sensitive so make sure to correctly address variables when setting up dialogues. Only alphanumeric symbols and undescrores _ can be used in variable names.
Type
Depending on what type of information you want a variable to store, you have to define a correct data type for the variable (see below descriptions of various data types).
Value
When necessary, in the value field you can define a range of values for the variable. For numbers, the value field can be limited with comparative operators (>; <; >=; <=). You can define numerous conditions by listing them with just a space as a separator: the space is then treated as “and.” For example, to create a valid value field from 0-100 you can write the condition >=0 <=100.
Default
In the default field you can predetermine a default value for a variable which will be used as a fallback in chatbot answers if no other value was set.
Example: a variable “quantity” is used in a dialogue to store information about the number of ordered products. If a user does not explicitly indicate the amount of products to be ordered, a default value 0 will be used.
Lifespan and profile visibility of a variable
A floppy disc symbol in the column “user profile” defines if a varible should save values temporarily or permanently. The avatar symbol stands for the visitbility of a variable on a user profile site. The user can edit the values of variables visible on the profile page by sending a command “profile” into the chat.
Datatypes
Each variable has to be identified with a specific data type. Example: If a variable has datatype ‘number’, it can only receive numeric characters as values.
Here are some details about different datatypes.
Number
Variables of the type ‘number’ save integers as well as floats.
Word
Variables of the type ‘word’ save text input up until the first space or punctuation mark. An input with a dash will also be interpreted as one word.
Example: If you type in ‘Hans Joachim’, only ‘Hans’ will be saved as name if a variable $name$ is of type “word”. The input ‘Hans-Joachim’ written with a dash would however count as one word.
Text
Variables of the type ‘text’ can contain chunks of text, including punctuation marks.
Date
Variables of the type ‘date’ save dates. You can input dates in both German (dd.mm.yyyy.) or English (dd/mm/yyyy.) format. Make sure that if you are importing date-values by uploading a dataset, dates should be in the format yyyy-mm-dd in your cvs-file.
Time
Variables of the type ‘time’ accept values in 24-hour format, such as 14:30.
Location
Setting variables of type location triggers a request to Google Maps Geocoding API. You can restrict google maps serach criteria by using components filter in the field “values”, such as to restrict a search only to Germany. For more information check Google Maps Geocoding API documentation. You can access geocordinates of the variables of type location as follows: $varname.location.lat$ and $varname.location.lng$
Enumeration
Variables of the type ‘enumeration’ will store one value from a list of predifined values. You can enter a list of valid values separated by commas in the field “values” of a variable.
Example: you can store user’s consent to be contacted on the phone in a variable of type enumeration where the valid values are “yes” or “no” (see $phone_contact$ in the screenshot above). If a user writes “yes” or simply “1”, the value of a variable will be set to “yes”.
Collection
Variables of the type ‘collection’ function in a similar way to variables of type enumeration: it can store values from a list a predefined options. In contast to variables of type enumeration, collections can store several values at a time.
Example: variable $favourite_colors$ can take the values blue, green, yellow, black and red. A user can write multiple colors separated by comma like blue, black for saving multiple values. Or he/she can access list elements by their indices, e.g., 1, 4.
Depending on how many values are saved to the variable, the ‘collection’ type can trigger a variety of different dialogues (see screenshot below). For that an expression $variablename_x$ can be used as user input, where, where x is the x the number of currently saved elements * the collection.
$variablename_duplicate$ as user input in the dialogue box allows you to set up bot-responses to a repeated input of a collection element , i.e. when the user accidentally types the the same element of a collection twice.
An expression $variablename_num$ provides an overview of the quantity of the saved values for a variable in the ‘collection’ type and can be conveniently used to condition bot-responses.
With an expression $variablename_list_options$ you can return predefined values of the variables of types collection and enumeration ($variablename_list_options_bold$).
Entity
Whilst you can call data models directly, you can also access them through variables of type entity. A variable with the type ‘entity’ recognizes entity identifiers as valid values. Creating the entity thus sets the value field of the variableto be a list of entity identifiers. For more information about entities, have a look here.
MIA Topics
Variables of type „MIA Topics“ save MIA categories. Multiple values are possible. This datatype can be selected upon upon creating a new variable and can be used only once. Categories available in MIA are to be defined in the column “values”. Should a category be activated for a user automatically upon MIA-subscription, put its value additionally in the column “default”. In our example, a category “Popular” will be activated for a user with a MIA-optin. Other categories can be chosen on a user profile page or via the chatbot.
Using Variables in Dialogues
In the dialogues, variables are called with dollar signs around variable names, for example $name$. Variable names are case sensitive. Variables can be used both in user questions and bot answers.
Example
User query = $first_name$ > Bot saves the given name. (e.g. Jasmine)
Bot answer: nice to meet you, $first_name$ > Bot answers with “nice to meet you, Jasmine” and navigates to the topic “color” to ask for favourite colors.
Users can see and edit their personal data if you allow so by viewing their profile pages (see above how to set profile visibility for variabes). A keyword ‘profile’ sent to a chat returns a link user’s profile page.
When working with ticketing system, agents can also view user information in the panel “User properties”.
Using Variables in Conditions
Variables are very useful in conditioning bot-answers. For more information on using variables in conditions, see Conditions.
Commands for Variables
Special expressions can be used to set/delete variable values, display user information obtained from messengers (e.g., telephone number in WhatsApp and profile name in Facebook messenger), etc. Have a look at the section “Special expressions” to find out more on this.