Variables — Storing Data
Variables let you remember information about users, store temporary data, and manage bot-wide settings.
What Are Variables?
Variables are like labeled containers that hold information:
┌─────────────┐
│ var.name │ → "Alice"
└─────────────┘
┌─────────────┐
│ var.balance │ → 150
└─────────────┘
You can set a value, then get it later — even in a completely different conversation!
Variable Scopes
There are several "places" to store variables, each with different behavior:
var.* — User Variables (Most Common)
Saved forever, per user
Each user has their own set — Alice's var.name is different from Bob's.
| Use For |
|---|
| User preferences |
| Account balance |
| Registration status |
| Scores and stats |
Example: var.is_registered, var.language, var.referrer_id
global.* — Global Settings
Read-only, same for everyone
Set by you (the bot owner), accessible by all users.
| Use For |
|---|
| Bot configuration |
| Admin user IDs |
| Feature flags |
Example: global.admin_id, global.maintenance_mode
shared.* — Shared State
Writable, same for everyone
All users see the same value — use carefully!
| Use For |
|---|
| Total user count |
| Product catalog |
| Leaderboards |
Example: shared.total_users, shared.products
flow.* — Temporary Variables
Disappears after the flow ends
Use for calculations or temporary storage within one flow.
| Use For |
|---|
| Loop counters |
| API response data |
| Temporary calculations |
Example: flow.api_result, flow.current_item
user.* — User Info (Read-Only)
Automatic info from Telegram
| Variable | What It Contains |
|---|---|
user.id | Telegram user ID |
user.first_name | First name |
user.last_name | Last name |
user.username | @username |
user.language | Language code |
ctx.* — Context (Read-Only)
Info about the current message
| Variable | What It Contains |
|---|---|
ctx.Input | Message text or callback data |
ctx.Match | Deep link parameter |
ctx.Args | Command arguments |
Using Variables
In Text (Templates)
Use double curly braces:
Hello {{user.first_name}}!
Your balance is ${{var.balance}}.
In Expressions
Reference directly:
var.balance > 100
user.id == 12345
Setting Variables
Use the Set Variable node:
- Name: The variable path (e.g.,
var.is_registered) - Value: What to store
Dynamic Values
You can store:
- Static values:
"hello",42,true - Expressions:
var.balance + 10 - Other variables:
{{user.first_name}}
Getting Variables
Use the Get Variable node:
- Name: Which variable
- Outputs:
- Value — The data
- Found — Variable exists
- NotFound — Variable is missing
Always handle the "NotFound" case when a variable might not exist yet!
Variable Types
Variables can hold different types of data:
| Type | Examples |
|---|---|
| Text (String) | "hello", "alice@email.com" |
| Number | 42, 3.14, -10 |
| True/False (Boolean) | true, false |
| List (Array) | ["apple", "banana", "cherry"] |
| Object | {"name": "Alice", "age": 25} |
Common Patterns
Track Registration
Update Balance
Expression: var.balance + amount
Toggle Setting
Tips
Use descriptive names:
- ✅
var.is_verified - ✅
var.referral_count - ❌
var.x - ❌
var.flag1
During development, send yourself messages showing variable values to verify they're set correctly.
Next Steps
- Expressions → — Work with variable values
- Subflows → — Pass variables between flows