Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python telegram bot disallow nested conversations

I am writing conversations with python-telegram-bot and need a way to disable nested conversations. That is, if a user is in a conversation, then an entry command for another conversation should not activate another handler.

It seems that this is not enforceable in a ConversationHandler object. I.e. I try to catch a command in a state where I don't want another command to run (UPLOAD), but it doesn't work - a bot happily starts another conversation. Also, this does not work with fallbacks alone

submission_conv_handler = ConversationHandler(

        entry_points=[
             CommandHandler('submit', self.submit_command),
             
          ],


        states={
             self.CHOSE_TYPE: [
               CallbackQueryHandler(self.submission_query_callback, pattern=r'^(py|ipynb)')
             ],

             self.UPLOAD: [
               MessageHandler(Filters.document, self.upload_message),
               MessageHandler(Filters.command | Filters.text , done)
             ],

        },

        fallbacks=[MessageHandler(Filters.all, done)]
    )
like image 296
Artem Trunov Avatar asked Feb 04 '26 21:02

Artem Trunov


1 Answers

Interruption behaviour of conversations is a common problem, as PTB currently (v13.0) has no built in way to prevent it. Please have a look at the GitHub issues 1640 and 1447 as well as this FAQ entry.

like image 170
CallMeStag Avatar answered Feb 08 '26 15:02

CallMeStag