Hey folks! I’m working on a Telegram bot and I’m a bit stuck. Here’s what I want it to do:
A user sends a request
The bot saves it and informs the user that the request is pending approval
The bot notifies another user to accept or reject the request
That second user selects an option
The bot records the choice and updates both users
I’ve got the initial conversation set up with ConversationHandler, but I don’t know how to properly start a new conversation with the second user. I considered sending a message directly, but handling the reply remains unclear.
I do have both users’ chat IDs stored in my database. Any advice or example code would be appreciated. Thanks for your help!
hey RunningTiger, sounds like a tricky setup! have u tried using JobQueue to schedule a new convo with the 2nd user? u could create a custom job that sends the notification and sets up a new ConversationHandler for that user. might need to play around with context to pass data between handlers. good luck!
I’ve dealt with similar situations in my Telegram bots. One approach that worked well for me was using a combination of ConversationHandler and CallbackQueryHandler. Here’s the gist:
Create a separate ConversationHandler for the approval process. When the first user submits a request, use bot.send_message() to notify the second user with inline buttons for accept/reject.
Set up a CallbackQueryHandler to catch the second user’s response. In the callback function, update your database, send notifications to both users, and end the conversation.
You might need to juggle some context variables to pass data between handlers, but it’s quite flexible once you get the hang of it. Just remember to properly handle conversation timeouts and edge cases.
This method keeps your code modular and easier to maintain as your bot grows more complex. Hope this helps!
I’ve encountered a similar challenge in my Telegram bot projects. One effective approach is to utilize the Application’s dispatcher to manually start a new conversation with the second user. You can create a separate ConversationHandler for the approval process and trigger it using the chat_id of the second user.
A possible method involves storing the request details and both user chat_ids, then sending the initial message using bot.send_message() and dynamically adding a new ConversationHandler via application.dispatcher.add_handler(). This setup lets you handle approval callbacks, update your database, and notify both parties efficiently. Though it may require some refactoring, this approach offers considerable flexibility.