Skip to main content

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

VariableWhat It Contains
user.idTelegram user ID
user.first_nameFirst name
user.last_nameLast name
user.username@username
user.languageLanguage code

ctx.* — Context (Read-Only)

Info about the current message

VariableWhat It Contains
ctx.InputMessage text or callback data
ctx.MatchDeep link parameter
ctx.ArgsCommand 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:

  1. Name: The variable path (e.g., var.is_registered)
  2. 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:

  1. Name: Which variable
  2. Outputs:
    • Value — The data
    • Found — Variable exists
    • NotFound — Variable is missing
Handling Missing Variables

Always handle the "NotFound" case when a variable might not exist yet!


Variable Types

Variables can hold different types of data:

TypeExamples
Text (String)"hello", "alice@email.com"
Number42, 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

Naming Conventions

Use descriptive names:

  • var.is_verified
  • var.referral_count
  • var.x
  • var.flag1
Test with Real Data

During development, send yourself messages showing variable values to verify they're set correctly.


Next Steps