Variables
Let’s assume that you want to change the output of an automation depending on who you are talking to.
This can be accomplished with variables. A variable is a special token that is substituted with the current value of a particular piece of information.
Assuming we had a variable named first_name
, we could write:
Hello, {{first_name}}!
This will output something like:
Hello, Kina!
A variable is indicated by a pair of double curly braces around the variable's name.
Creating variables
You can make your own variables in a template using the set command:
{% set name = "Kina" %}
{% set quantity = 5 %}
{{name}} has {{quantity}} gold stars.
Kina has 5 gold stars.
Variables are temporary. When you define a new variable in one action, it can’t be referenced from other actions. In programmer parlance, the scope of a variable is limited to the same template.
Placeholders
Placeholders are special variables that are already set for you. For instance, in an automation the event inputs are placeholders.
Modifying variables with filters
The value of a variable may be modified by appending filters with a pipe (|
) character.
When editing actions on a bot behavior, the possible filters are automatically suggested when you type |
after a variable name.
For example, we can use the upper filter to display a variable’s value in uppercase:
Hi, {{first_name|upper}}!
Hi, KINA!
Default values
You can use the default filter to give a default value to empty variables:
{% set name = '' %}
Hi {{name|default('there')}}
Hi there
Stacking filters
You can send the output from one filter as the input to another filter:
{% set first_name = null %}
Hi, {{first_name|default('there')|upper}}!
Hi, THERE!