4

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)]
    )
Artem Trunov
  • 1,340
  • 9
  • 16

2 Answers2

1

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
CallMeStag
  • 5,467
  • 1
  • 7
  • 22
0

When another conversation should be prevented for the user if the first one is not finished, looks like the only solution is still:

There is no built-in way to do that. You can however easily set a flag as e.g. context.user_data['in_conversation'] = True in your entry_pointss and set it to False before returning ConversationHandler.END.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
OcMaRUS
  • 329
  • 3
  • 13