Skip to content

What are variables?

Variables allow you to store data for later use in messages and actions. They must be sent within expressions.

VisualMaker provides you with 2 types of variables:

  • Normal variables: it stores a different and individual value for each user of the bot. An example of a normal variable could be the balance, which by nature should be different for each user.
  • Global variables: it stores the same value for the entire bot. For example, the values of the bot's statistics.

In addition to variable types, you also have 6 data types that can be stored in variables. These are:

  • Text: to store all kinds of texts, such as names, addresses, emails, etc. Its default value is an empty text string ''.
  • Numeric: to store numbers. The balance variable is already created by default. Its default value is 0.
  • Date: to store dates. Its default value is 01-01-0001.
  • Multimedia: to store multimedia files, such as photos, videos, audios, documents, etc. Its default value is {}.
  • Forwarded: to store forwarded messages. Its default value is {}.
  • Dictionary: to store more advanced data types, such as {"name": "John", "age": 20}. Its default value is {}.

How to create a variable?

  1. To create a variable, go to 🔑 Manage, then to 🗃 Variables, and finally to 💠 Create variable 💠.
  2. Select the data type to store and send the variable name. If it is a global variable, the name must start with global_.
  3. The variable has been created, and you can now use it in your bot.
Note

The maximum number of variables you can use per bot is conditioned by your current Subscription Plan. The higher the plan, the more variables you can use.

How to delete a variable?

  1. To delete a variable, go to 🔑 Manage, then to 🗃 Variables, and finally to ⛔️ Delete variable ⛔️.
  2. Send the name of the variable to delete.
  3. The variable will be automatically deleted.
WARNING

When you delete a variable, all its data will be permanently deleted, with no possibility of recovery.

Reset variable data to default value

To reset the data of a variable to its default value, simply delete it and recreate it. The stored data of the users will be reset to its default value.

How to use variables?

Variables can be used in messages, in actions, and in all places where expressions can be used. Variables must always be enclosed in braces {}, as braces indicate to VisualMaker that it is an expression. More information about expressions here.

Example of using a variable

You have {balance} coins.

That will automatically replace {balance} with the value of the balance variable, and would print something like:

You have 10 coins.

Representing multimedia types

When saving a multimedia file in a multimedia variable, VisualMaker automatically sets the multimedia type. So when calling the variable, its multimedia type will be automatically represented. However, there are cases where you need to define what data type you want to represent, whether it is a photo, video, audio, or others. For example, to represent a photo from a Telegram file_id it would be: {photo:"file_id"}. You can also do it with variables. For example, to represent a video, of which you saved its file_id in a text variable, it would be: {video:text_variable}. Note that to represent from text, quotation marks " " are used, and to represent from a variable no.

All the multimedia types that can be represented in this way are: photo, video, audio, document, animation, voice, sticker

What are primitive variables?

Primitive variables are variables that are already available in VisualMaker with the creation of any bot. They differ from normal and global variables in that they cannot be created or deleted, nor are they counted as variables per se, but they are always there for use, and are automatically updated as needed.

User primitive variables

  • id: Telegram ID of the user.
  • first_name: User's first name.
  • last_name: User's last name.
  • username: Username, without @.
  • mention: User's first name with a link to their profile.
  • language_code: User's language code, in ISO 639-1 format.
  • ref_link: User's referral link.
  • ref_by: ID of the person who referred the user, if any. It returns None if there is none.
  • ref_count: Number of referrals attracted through the referral link.
  • ref_list: List of all user referrals, in cursor format, use the loop() function to display them.
  • date_joined: Date the user joined the bot, use the date_format() function to represent it as you like.
  • last_seen: Date when the user was last seen in the bot, use the date_format() function to represent it as you like.
  • is_admin: Returns True if the user is a bot administrator, or False if not.
  • is_new: Returns True if the user is new to the bot, or False if not. A user is new if they have not completed all the actions of /start; once they reach the main menu, is_new will become False.
  • is_active: Returns True if the user is active in the bot, or False if not. A user is active if they have not deleted the bot.

  • is_banned: Returns True if the user is banned in the bot, or False if not.

  • is_deleted: Returns True if the user is a deleted account in Telegram, or False if not.
  • is_bot: Returns True if the user is a bot, or False if not.
  • is_premium: Returns True if the user is a Telegram user with an active Premium subscription, or False if not.
  • is_verified: Returns True if the user is a verified user by Telegram, or False if not.
  • is_restricted: Returns True if the user has any restrictions, or False if not.
  • is_scam: Returns True if the user has the scam tag imposed by Telegram, or False if they do not.
  • is_fake: Returns True if the user is flagged as fake by Telegram, or False if they are real.

Bot primitive variables

  • bot_name: Returns the bot's name.
  • bot_username: Returns the bot's username, without @.
  • bot_top_ref: List of the users with the most referrals in the bot, in cursor format, use the loop() function to display them.
  • total_users: Returns the total number of users who have started the bot.
  • total_active_users: Returns the total number of active users in the bot.
  • total_unregistered: Returns the total number of users who sent /start but did not pass the verification created by you.
  • total_banned: Returns the total number of users banned in the bot.
  • total_deposits: Returns the total number of deposits made in the bot, including external and internal deposits.
  • total_deposits_amount: Returns the total sum in USD of deposits made in the bot, including external and internal deposits.
  • total_withdrawals: Returns the total number of withdrawals made in the bot, including external and internal withdrawals.
  • total_withdrawals_amount: Returns the total sum in USD of withdrawals made in the bot, including external and internal withdrawals.

Message and chat primitive variables

  • chat_type: Returns the type of chat where the message was sent. If it was sent in the bot, it will return 'private', if it was sent in a group or a channel, it will return 'group' or 'channel'.
  • reply_to_message_id: If the message is a reply to another message, returns the ID of the replied message.
  • reply_to_message.id: If the message is a reply to another message, returns the ID of the original sender.
  • reply_to_message.first_name: If the message is a reply to another message, returns the first name of the original sender.
  • reply_to_message.username: If the message is a reply to another message, returns the username of the original sender.
  • reply_to_message.language_code: If the message is a reply to another message, returns the language code of the original sender, in ISO 639-1 format.
  • reply_to_message.is_deleted: If the message is a reply to another message, returns True if the original sender is a deleted account on Telegram, or False if not.
  • reply_to_message.is_bot: If the message is a reply to another message, returns True if the original sender is a bot, or False if not.
  • reply_to_message.is_premium: If the message is a reply to another message, returns True if the original sender has an active Premium subscription from Telegram, or False if not.
  • reply_to_message.is_verified: If the message is a reply to another message, returns True if the original sender is verified by Telegram, or False if not.
  • reply_to_message.is_restricted: If the message is a reply to another message, returns True if the original sender has any restrictions, or False if not.
  • reply_to_message.is_scam: If the message is a reply to another message, returns True if the original sender has the scam tag imposed by Telegram, or False if not.
  • reply_to_message.is_fake: If the message is a reply to another message, returns True if the original sender is labeled as fake by Telegram, or False if real.

How to use primitive variables?

Primitive variables, like normal and global variables, can be used in messages, in actions, and in all places where expressions can be used. They must also always be enclosed in braces {}, for example:

Your name is {first_name}, and your username is @{username}.