I am writing a Python code for a Telegram bot for the first time, using the ‘python-telegram-bot’ library. The bot supposed to work like this: When entering the bot for the first time, pressing the ‘/start’ button initiates a conversation. This conversation has only a single message, and for specific reasons, I need all actions to occur within this single message without creating separate messages. This message contains text and some buttons below it.
The menu that appears when the start button is pressed is named ‘main_menu’ in its callback_data, and the buttons below it each have their specific text and are numbered with the prefix ‘menu’ in their callback_data: for example, the first button is ‘menu_1’, the second button is ‘menu_2’, and the third button is ‘menu_3’.
By clicking one of the buttons, such as the first button (whose callback_data is ‘menu_1’), we enter its submenu. This time, only the conversation text is edited (No new message is created), and there is a button below it with the callback_data ‘submenu_1_1’. If this button is clicked, the message text changes again, prompting ” Ok. The default number is 0. Please enter a number:” and asking the user for a numeric input. After the user sends the number, the same message text should change again and update displaying the previous message with the number the user entered. I asked ChatGPT about this, but the provided answer did not resolve my issue. The problem arises in the part where the user sends the number, but I got confused how to write the code to make the bot change the text of the same message again and show the user the number they entered, and re-display the buttons that were in ‘menu_3’. Is there any solution to do this?
I’ve created a repository in my Github with the name ‘python-telegram-bot-issue’ and uploaded the codes there. My problem is at the end of file: handlers.py > function: get_number_handler.
python-telegram-bot-issue link in github
Maryam Mirfazaelian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.