Variables
[[name]] variables in the Multogram Modules Constructor: where they come from, value types, object fields and array elements, local and global variables in a multi-threaded module, viewing them in the inspector.
A variable is a named value that one action writes and others read. This is how data passes between actions: Telegram's answer, the account taken, a counter.
Where variables come from
- An action's result. Many actions have a result variable — the Output Variable on
the card. Send Message puts its result into
[[sendResult]], Get Resource Value — into[[resourceValue]]. The name can be changed in the action's window. - Set Variable — writes the value you give, with the chosen type.
- Function parameters — inside a called function they are available as variables with the same names.
A variable name starts with a letter or _ and consists of Latin letters, digits and _.
How to use them
In any field of an action, write the name in double square brackets:
Account [[account]].phone sent a message to {{chat}}| Notation | What you get |
|---|---|
[[user]] | The whole value |
[[user]].profile.id | An object field |
[[items]][0] | The first element of an array |
[[user]].tags[2] | An array element inside an object |
The path goes outside the brackets
Write [[account]].session_path. The notation [[account.session_path]] won't work: the brackets hold
only the variable name.
Value types
| Type | Example |
|---|---|
string — text | Hello |
number — a number | 42, 3.14 |
boolean — yes or no | true, false |
object — an object or array (JSON) | {"name": "John"}, ["a", "b"] |
If a field contains only [[name]], the action gets the value with its type: a number, an object,
an array. If the variable sits inside text, it turns into text: count=[[n]] → count=5.
Local and global variables
A module runs in several threads at once.
| Local | Global | |
|---|---|---|
| Created by | Set Variable, an action's result | Set Global Variable |
| Visible | Only in its own thread | To all of the module's threads |
| What for | One account's data: session, answer, target | Shared counters and flags |
Use local variables by default — threads don't interfere with each other. For shared counters there is Increment Global Variable, and for figures the user sees — the Statistics module.
Variables in the inspector
Inspector → Variables shows all variables with their type and value after a test. A value can be changed right there to check a branch of the scenario with different data.
Referring through another name
Sometimes the name of a variable or resource is stored in another value:
| Notation | What it does |
|---|---|
{{(varName)}} | The resource whose name is held in the varName variable |
[[(resName)]] | The variable whose name is held in the resName resource |
If there is no name or it is empty, the notation stays as it is.
Updated
Conditions, loops and errors
Controlling the flow of a scenario in the Multogram Modules Constructor: IF with THEN and ELSE branches, WHILE, FOR and FOREACH loops, Break and Continue, Try-Catch and the [[_error]] variable, delay, ending a thread. How to write conditions.
Functions
Functions in the Multogram Modules Constructor: the Main function, your own functions with parameters and a return value, calling them with Call Function, folders and the function manager.