Skip to content

Action: condition

This is a powerful action that allows you to add conditions to your buttons and commands. Conditions are points in actions where something will be evaluated. For example, if the balance is greater than a certain number, if it's true, it will return True, and if it's false, it will return False. Then, you can decide what to do in each case.

Options of the action:

  • New condition: The condition to evaluate in expression format, within braces { }.
  • If true: What will happen if the expression to evaluate is True, or a value that tends to True. It can be continue (continues to the next action), stop (stops execution and does nothing further), or execute action by ID (runs any action of the current button or command by its #ID#, regardless of its position).
  • If false: What will happen if the expression to evaluate is False, or a value that tends to False, such as None or the number 0. It can be continue (continues to the next action), stop (stops execution and does nothing further), or execute action by ID (runs any action of the current button or command by its #ID#, regardless of its position).

What does the action return through its ID?

This action does not return anything.


Example

Suppose you have created the command from the example in the previous action, called /change_balance, which increases or decreases the balance of a user, passing as parameters the ID of the target user and a number representing the balance to increase or decrease.

This command works perfectly as it is, but it has a serious problem: any user who discovers it can increase their own balance if they wish.

That's where conditions come into play.

To solve the problem, you could add a condition action at the beginning of the command, before the rest of the actions.

In New condition, you have to put some verification so that the bot only executes the command if it's you who is executing it. How to know if it's you? Easy, by your ID, which is unique for each Telegram user. Let's suppose your ID is 98765 (Telegram IDs will always be integer numerical values), the expression would be {id == 98765}.

In If true, you select continue, so it continues with the rest of the actions if indeed the ID is 98765.

In If false, you select stop, so it stops if the ID of the user executing the command doesn't match yours.

And that's it, you now have a completely secure command that changes the balance for any user of the bot, but only if you are the one executing it.