When access to a Telegram bot is restricted, it can only be used by users who have been granted access manually by adding their identifiers to the list of authorized users.
There are two main ways to grant access:
To grant access through the script, the bot administrator must have access to the script. To grant him access, you must modify the script by adding user IDs manually. To do this, do the following:
Go to the Bots section of personal profile.
Open the desired script in the editor. If you don't have a script, create a new one.
Set the Information block at the very beginning of the script - it will be used to output the user ID in the bot message.
Enter the {messengerUserId} system variable in the Message field. The variable stores the Telegram user ID.
Add a Condition block with two branches: the first branch will allow you to continue the dialog, and the second branch will end it with the message Entry Denied.
Set the following parameters in the arrow going to the continuation of the dialog box:
{messengerUserId} = X, where X is your identifier.The identifier will be output in the bot message after the first run of the script in the Telegram bot. Or use /getid command in Telegram bot MyIdBot.
To add multiple users, you need to add a separate condition for each with a comparison of that user's ID with {messengerUserId} in the same arrow.
Set the output data type to Default in the second arrow going to the other Information block.
The bot administrator can manage the list of authorized users directly from the Telegram messenger, without the need to access the script. This makes it possible to add and remove users from the list of authorized users using bot commands.
To open access via a bot command in Telegram, follow the steps:
Set the Information block at the very beginning of the script - it will be used to output the user ID in the bot message.
Enter the {messengerUserId} system variable in the Message field. This variable stores the Telegram user ID.
Add a Result block and perform the following steps:
{messengerUserId},Add the Statement block.
Open the BPL expression editor, and paste the following expression into it:
$reg = fact.load("userId", $uid, @botId)
The bot will attempt to retrieve the user ID, from its database. If the ID of the user interacting with the bot is found in the database, this ID will be written to the reg variable. If there is no ID in the database, the reg variable will remain empty.
Action type: AND;
Condition: {reg} !=.
A check for the contents of the reg variable will be performed.
The branches with commands are identical, and consist of the Question block, the Statement block and the Information block.
The Question block asks for the ID of the user to whom you want to open or close access.
fact.save("userId", $user, $user, @botId)
fact.delete("userId", $user, @botId)
After that, open access to the bot commands for yourself. To do this, in the first Statement block in the script, replace the expression in the BPL-expression field with the following:
fact.save("userId", YOUR_ID, YOUR_ID, @botId)
$reg = fact.load("userId", $uid, @botId)
Where YOUR_ID is your ID, which you received when you first started the bot.
To ensure that you don't have permanent access, enter another person's ID.
Save the script and run the bot again.
Use the bot commands /adduser and /deluser to open and close access to the bot. The identifier required for access is given to the user when the bot is launched.
In this way you can make a bot with the ability to restrict access.