How to set up buttons for considering requests for the access to the bot

Use this case to approve or reject requests for the access to the bot. Notifications about each request will be sent to Telegram along with buttons that can be clicked to accept or reject the request.

As soon as the user submits a request to continue communication with the bot, get into a certain section, etc., you will receive a screen with the request notification. The user name and user ID will be indicated in the notification text, but you can add other data.

1. Add any kind of buttons to the screen for the user to submit a request by clicking on this button. Write the text in front of the buttons and the text on the button.

The case uses Buttons with hints and Fork with one goal leading to the next screen with the request.

2. Create a new screen. In the example, this screen is called "Request Screen", but you can give it another name. Make the transition to this screen from Goal 1 of Fork that you added to the first screen.

3. Add Assign a Variable to this screen in order to reassign the user ID into a new variable. It will be useful in the future.

You can choose any name for the variable, in our case it is UserID, the value must specify the path to the ID:

{{this_user.platform_id}}

4. Add five new screens. You will need them to distribute users and notofications in the bot.

  • Your request has been accepted — the scenario can continue on this screen for the approved user,
  • Your request hasn’t been accepted — this screen may lead nowhere and it can be the end of the scenario for the user whose request was not approved,
  • Accept — this screen will be sent to the operator after he accepts the request,
  • Reject — this screen will be sent to the operator after he rejects the request,
  • Request error — the screen that will appear if the request is executed with an error.

5. Save the changes, go to SettingsEvents and add two External Events — one for each option. This means that the Request will be accepted for the first event, and the Request will not be accepted for the second one.

6. Save the changes and go back to Bot Editor.

7. Add Buttons to the Request Screen right after Assign a Variable.

8. Expand the component settings on the right and in the recipient id field add the ID of the user who will approve or reject requests. You can copy this ID from the Users section next to the username you need.

9. Write the text in front of the buttons. In the example, there is a link to the username @{{this_user.username}} and the user ID {{this_user.platform_id}}

You can overwrite the ID in the following form: {{UserID}}

10. Add two buttons – one button is to accept the request, another one is to reject the request.

11. Expand the settings of the first button and check Allow to send a request.

12. In the request URL, copy the link from the External Event settings that you set up earlier to accept requests.

13. Select the POST request method.

14. Add Request Body:

    {
        "platform": "tg",
        "users": "{{UserID}}"
    }

17. Select the Screen that will be executed if the request succeeds — Accept.

18. Select the previously created screen for the request error.

19. Click on the Record variables in templates checkbox.

20. Expand the settings of the second button and check Allow to send a request.

21. In the request URL, copy the link from the previously created External Event to reject the request. To do this, go back to the Events section in Settings, copy the link from the desired event and go back to the editor.

22. Select the POST request method as for the previous button and add the same request body:

 {
      "platform": "tg",
      "users": "{{UserID}}"
 }

23. Select the Screen that will be executed if the request succeeds — Reject.

24. Select the previously created screen for the request error.

25. Click on the Record variables in templates checkbox.

26. Save the changes.

Done.

To the beginning ↑