Switch to English?
Yes
Переключитись на українську?
Так
Переключиться на русскую?
Да
Przełączyć się na polską?
Tak
This is a Telegram bot written in Python using the python-telegram-bot library. Its main purpose is to provide users with workout programs based on their gender, goals (weight loss, muscle gain, etc.), height, and weight. To interact with the user, the bot uses a step-by-step dialogue (ConversationHandler), making the process intuitive.

Main components and their purposes

python-telegram-bot library: This is the foundation that provides interaction with the Telegram API. The code uses its asynchronous version (async def), which is modern practice.

ConversationHandler: This is a key element of the bot's logic. It allows creating a "dialogue" with the user, consisting of several steps or "states." The bot sequentially asks questions and waits for answers, transitioning from one state to another.

States:

The variables SELECT_GENDER, GET_HEIGHT, etc. are unique identifiers for each step of the conversation. They help the ConversationHandler understand at which stage of the dialogue the user is and which function to call next.

Keyboards (ReplyKeyboardMarkup):

Instead of forcing the user to type text ("Male", "Weight Loss"), the bot offers ready-made buttons. This reduces the likelihood of errors and makes the interface more user-friendly. The code includes three different keyboards: for selecting gender, for selecting goals for men and women.

Workout data (male_programs, female_programs):

These are two large dictionaries that serve as the bot's "database." They contain ready-made workout programs, structured by gender, goal, and days of the week. Currently, this data is hardcoded in the code.

Handler functions:

start: Starts the dialogue, greets the user, and offers to choose a gender.

select_gender, select_male_goal, select_female_goal: Handle the user's selection from the keyboard, store data (context.user_data), and ask the next question.

get_height, get_weight: Receive text messages, convert them into numbers, check for correctness, and store them.

show_workout_program: The final function. It gathers all saved data, calculates the Body Mass Index (BMI), and finds the corresponding workout program in the dictionaries. After that, it forms a large text message and sends it to the user.

cancel: Allows the user to interrupt the dialogue at any time with the /cancel command.

Logic of operation (Step-by-step scenario)

The user sends the /start command.

The bot responds with a welcome message and shows a keyboard with "Male" and "Female" buttons. The dialogue transitions to the SELECT_GENDER state.

The user presses one of the buttons.

Depending on the choice, the bot shows a new keyboard:

For men: "Weight Loss", "Gain."

For women: "Weight Loss", "Muscle Tone."

The dialogue transitions to the SELECT_MALE_GOAL or SELECT_FEMALE_GOAL state.

The user selects a goal.

The bot saves the goal and asks for height. The dialogue transitions to the GET_HEIGHT state.

The user sends their height in centimeters. The bot checks if it is a number and saves it.

The bot asks for weight. The dialogue transitions to the GET_WEIGHT state.

The user sends their weight. The bot checks if it is a number and saves it.

The bot calls the show_workout_program function, which:

Calculates BMI using the formula weight / (height in meters)².

Determines the BMI category ("Normal", "Obesity", etc.).

Based on gender and goal, finds the required workout program.

Forms and sends the final message with BMI and a 3-day program.

The dialogue ends (ConversationHandler.END).
Work details
Budget 56 USD
Added 18 October 2025
153 views
Freelancer
Dmytro Romanchuk
Ukraine Cherkassy  7  0

A little busy A little busy
7 Safes completed
On the service 1 year