The functions in this group add randomness and coordinates to your flow — for giveaways, quizzes and finding the nearest branch.
Where it helps:
- give a participant a random giveaway number;
- make a “prize wheel” or a random tip of the day;
- calculate the distance from the subscriber to your office.
Functions
| Function | Description | Example |
|---|---|---|
| random(from, to) | Returns a random number in the range, both bounds included. If both bounds are integers, the result is an integer. If at least one bound is a decimal, the result may be a decimal. Without arguments, returns a decimal from 0 to 1. | random(1, 3) → 1, 2 or 3 |
| random_choice(list) | Returns a random item from the list. | random_choice(client.prizes) → "10% discount" |
| distance(lat1, lon1, lat2, lon2) | Returns the distance between two points by coordinates (latitude and longitude) in kilometers, in a straight line over the Earth's surface. | round(distance(55.7558, 37.6173, 59.9343, 30.3351), 1) → 633.0 |
Example: a giveaway participant number
client.ticket = random(1000, 9999)
Both bounds are included, so the number can be from 1000 to 9999. If at least one bound is a decimal, the result may be a decimal too.
Example: a prize wheel
client.prize = random_choice(split_list("10% discount, Free delivery, Gift", ", "))prize gets one of the three prizes.
Example: distance to the office
If the subscriber’s coordinates are saved to the lat and lon fields, calculate the distance to an office in central London:
client.km_to_office = round(distance(client.lat, client.lon, 51.5074, -0.1278), 1)
The result is in kilometers in a straight line, for example 4.2. You can show it in a message: Our office is {%km_to_office%} km away.
To pick a random branch of the flow rather than a value, use the “Random choice” step.
If you did not find the answer to your question, feel free to contact us in the chat inside your dashboard, message us on Telegram at @BotHelpSupportBot, or email us at hello@bothelp.io.
Enjoy the full functionality of the BotHelp platform for creating broadcasts, automated funnels, and chatbots — free for 14 days.
Sign up for BotHelp
Get 14 days of full access for free — enough to build your first bot and test it on real subscribers.
Create account