Skip to main content

Conditions

Conditions in @MenuBuilderBot gives administrators the ability to determine the behavior of their bots depending on the state of individual variables and other parameters. Conditions can be added to Buttons, Actions, as well as used during Mailing.


What are Conditions


Conditions are particular case of Expressions (expression manual here) with additional symbols and boolean operators. You can use the full power of Expressions in Conditions.

The condition must return True or False as a result (1 or 0).


Condition Syntax

The syntax for Conditions is inherited from Expressions. For this reason, Conditions must be enclosed in curly braces "{}", inside, besides the Operators peculiar only to the Conditions, you can use expressions in parentheses, calculations and macros.

In general, the Conditions template might look something like this:
{(...) and (...) or (...) not (...)}

IMPORTANT: in some cases, in particular, in the conditions of buttons, Actions and etc, if text is used in the Condition for comparison, then this text can be, and most often will be, converted to lowercase - that is, all capital letters in text will become lowercase. There is no need to be more specific about possible cases, just keep this in mind when working with conditions.

In other words, the Conditions are made case-insensitive. This makes it easier for the average bot admin to work with them.

Comparison Operators

Using these operators, two parts of an expression are compared.

  1. >, >= (Greater than, Greater or Equal to)
  2. <, <= (less, less or equal to)
  3. == (equal) Notice! Not one "=" sign, but two!
  4. != (not equal)

Example:
{1 < %refcount% < 10}
TRUE if the number of referrals the user has is more than 1 and less than 10.

Logical operators

Boolean operators combine the results of several logical expressions. Each logical expression must return True / False. It is strongly recommended that you use parentheses "( )" to define each logical expression.

and (boolean "and")
or (boolean "or")
not (boolean "not")

Examples:
{(%balance% > 0) and (%refcount1% > 0)}
TRUE if the user has money in his balance and (and) one or more referrals.

{(%balance% > 0) or (%usd% > 0)}
TRUE if the user has money on the balance or (or) funds on his USD variable.

{((%balance% > %vip_price%) and (%manual_ban% == 0)) or (%vip% == 1)}
TRUE if the User's Balance is more than the VIP value and (and) he is not banned or (or) he is a VIP user.

{not(%balance% > 0)}
TRUE if the user's balance is not (not) greater than zero (less than or equal to zero). Mainly used in complex expressions.


More complex options are also possible {(xxx) and ((yyy) or (zzz))}:
{(%balance% > 100) and ((%refcount% > 10) or (%invest% > 500))}
In the example above, two conditions must be met - the first is exact and either of the last two. Thus, the user must have %balance% more than 100 AND either more than 10 on %refcount% OR more than 500 on %invest%.


Checking the presence of data in a variable

Sometimes in a condition you need to check whether there is any data at all in the Variable (mainly relevant for Text Variables).

Examples:
{%var% == ""}
The condition will return true if the Text Variable var is empty.

{%var% != ""}
The condition will return true if the Text variable var is NOT empty - it contains data.

 

The use of Conditions

When adding a Condition to a button or Action, it, sometimes, becomes difficult to determine how and at what particular moment the added Condition will trigger.

It is important to remember that in all cases the Condition added by you describes the normal state of the system, the state in which the system usually works. This way, while the system is within the boundaries described in the condition - no additional actions will be taken by the Condition itself. As soon as, during the next check, the Condition will turn out to be "not true" (False or 0) - the restriction mechanism in the Condition will trigger and the function protected by this condition will be interrupted. The same applies to the "Action of Condition" - in this case, FAILURE in fulfilling its Conditions will interrupt the further chain of Actions.

LOGIC OF CONDITIONS: Thus, whenever you encounter difficulties with the Conditions, think as follows: "Until - (here is your condition) - do nothing, otherwise interrupt."

TIP: When creating complex Conditions, always start with their structure and only then insert the necessary expressions.
For example:
● Step 1 (basic):
{(...) or (...)}
● Step 2 (complication):
{( (...) and (...) ) or ( (...) and (...) )}
● Step 3 (general structure):
{( ((...)or(...)) and (...) ) or ( (...) and (...) )}
● Step 4: Replace ... with the required expressions.


Conditions in buttons


Conditions, when added to a button, determine whether a particular user has the right to access a particular button.

Before you can use the Conditions in the buttons of your bot, they must be activated.

Conditions.
To do this, go in your bot:
☞ 🔐Admin | 🧩Extensions | 📂Buttons


Go to button's settings:


f06bb92f4d7288cf30693.jpg


Click "Assign Condition":


2b58047c3bb683cda0682.jpg


And... Assign a Condition:


1ee70167f2baecf8964c6.jpg


After sending the Conditions to the bot, you will be prompted to add a message that will be shown to the user if the condition is not met (error message). This action is optional.


Screenshot_2023_08_24_18_47_40_204_org_telegram_messenger_web_edit.jpg


Three options:
1. Add a New Message («Advanced Mode» is available - allows you to add Inline Buttons and Media Variable to the error message)
2. «Leave as Is» - if the message was added earlier
3. leave it blank (the «Set Empty» button will clear the text of the message if it was added earlier).

After selecting one of the options, the Condition for the button will be created.

Thus, the created button will work for the user only if its balance is greater than 100. Otherwise, the button will display an error message if it was added by the administrator.


Conditions for mailing


Conditions can be used when sending messages to users of your bot. With the help of the Conditions, you can determine which users will receive the sent message.

Before you can use the Conditions in Mailing, you need to activate it.

Conditions for Mailing.
To do this, go in your bot:
☞ 🔐Admin | 🧩Extensions | 📂Optimization


f5af8df230c9e2478c914.jpg


You can set any acceptable conditions.

For example:
{%balance% > 0}
The message will be sent only to users who have something on their balance (who has a balance greater than zero).


Additional Information


Conditions are also used in Actions

Read more about the types of Actions and the use of the Conditions in them in a separate "Action's Guide".


Conditions can be used in Feedback Forms.

More info in "Manual on Forms".