How to allow the first 30 users in the bot, limiting access to the rest ones

Use this case to limit the number of bot users or, for example, to award prizes to those who were among the first to write.

In the example, the bot sends a gift to the first 30 users who launched the bot, but you can change the number of launches by your choice.

1. Create a screen separate from the main scenario and add Assign a shared variable to it. You can choose any variable name, Data Type is Number, Value is 0

The bot administrator will have to launch this screen once, so the user count will begin.

2. Add another separate screen with Clear shared variables for Var1. Activating this screen will reset the counter. You can run this screen to test the scenario or when you need to start counting users again.

3. Create three new screens:

  • for the first 30 people who have already become participants, display the participant serial number on this screen: {{stringify numbers.Var1}} and add Assign the ban variable with a value of 1,
  • for the first 30 people who have already become participants and relaunched the bot, on this screen the user can be informed that they are already participating,
  • for those who launch the bot after 30 participants have already been gained, you can add a message that the user did not make it on time.

4. On the Start screen or on the screen that should be the first for the user in this scenario, add Fork with one Goal. Add the Name of the variable from where Fork takes the value: ban. By checking the ban variable, Fork will redirect those who have logged in to a separate screen again.

5. Add a value of 1 to the Fork Goals and go to the screen for participants who have logged in again.

6. Right after Fork, add Assign a shared variable. The variable name should be exactly the same as on the screen for the administrator. In the example, it is Var1. Select Increase the number by Type, value 1.

7. Next, add the Read Shared Variables component. The name of the variable where to write the result is nums, the names of the variables to be read: Var1

8. Add another Fork to the same screen. The name of the variable from where the fork will take the value is nums.Var1

9. Add one goal to Fork, change the type to Regular expression, and add a regular expression for the first 30 users:

^([0-9]|([1-2][0-9]|30))$

The transition of this Goal should lead to the screen for the first 30 people.

10. Add a transition screen for the rest users to Default Transition— those users who did not manage to get among the first.

11. Save the changes.

Done.

To the beginning ↑