What are native variables?¶
- Native variables are predefined values that the bot already has and that you can use without the need to create them.
- These variables are automatically updated and are useful for obtaining information about users, the bot, or the context of messages.
- They cannot be created or deleted.
User native variables¶
- id: The user's unique ID.
- first_name: The user's first name.
- last_name: The user's last name (if available).
- username: The user's Telegram username, without
@
. - mention: A mention of the user with a link to their profile.
- language_code: The user's language code in the ISO 639-1 standard ISO 639-1 format (e.g.,
es
for Spanish). - ref_link: The user's unique referral link.
- ref_by: The ID of the person who referred the user. If there is no referrer, it returns
None
. - ref_count: The number of people the user has directly referred (level 1).
- ref_count_all: The total number of referrals across all levels (1, 2, 3, etc.).
- ref_count_(level): The number of referrals at a specific level (e.g.,
ref_count_2
for level 2). - ref_list: A list of the user's referrals. Use the loop() function to display them.
- date_joined: The date the user joined the bot. You can format it with date_format().
- last_seen: The last time the user interacted with the bot. It can be formatted with date_format().
- is_admin: Whether the user is an admin of the bot:
True
if yes,False
if not. - is_new: Whether the user is new (has not completed the
/start
actions):True
if yes,False
if not. - is_active: Whether the user is active on the bot:
True
if yes,False
if not. - is_banned: Whether the user is banned from the bot:
True
if yes,False
if not. - is_premium: Whether the user has Telegram Premium:
True
if yes,False
if not.
Bot native variables¶
- bot_name: The name of the bot.
- bot_username: The bot's username, without
@
. - bot_top_ref: A list of users with the most referrals. Use loop() to display them.
- total_users: The total number of users who have started the bot.
- total_active_users: The total number of active users on the bot.
- total_unregistered: The total number of users who started the bot but did not complete the verification you created in
/start
. - total_banned: The total number of banned users in the bot.
- total_deposits: The total amount of deposits made in the bot.
- total_deposits_amount: The total sum in USD of the deposits made.
- total_withdrawals: The total number of withdrawals made.
- total_withdrawals_amount: The total sum in USD of the withdrawals made.
Message and chat native variables¶
- chat_type: The type of chat where the message was sent. If it was sent in the bot, it will return
private
; if sent in a group, it will returngroup
; if sent in a channel, it will returnchannel
. - reply_to_message_id: If the message is a reply, it returns the ID of the original message.
- reply_to_message.id: The ID of the sender of the original message being replied to.
- reply_to_message.first_name: The first name of the sender of the original message.
- reply_to_message.username: The username of the sender of the original message, without
@
. - reply_to_message.language_code: The language code of the sender of the original message in ISO 639-1.
- reply_to_message.is_bot: Whether the sender is a bot:
True
if yes,False
if not. - reply_to_message.is_premium: Whether the sender has Telegram Premium:
True
if yes,False
if not.
How to use native variables¶
Just like regular variables, native variables can be used in messages, actions, and anywhere expressions can be used. Simply enclose them in curly braces {}
in the messages you send.
-
Example 1:
-
Message:
Hello {first_name}, welcome to {bot_name}.
-
Result:
Hello John, welcome to MyBot.
-
-
Example 2:
-
Message:
You have referred {ref_count} people.
-
Result:
You have referred 10 people.
-
-
Example 3:
-
Message:
Your referral link is {ref_link}
-
Result:
Your referral link is https://t.me/MyBot?start=123456789
-