Hello
How should be implemented the conversations handler state persistence?
For example if i鈥檓 in a conversation and i stop the process (control-c), using pickle persistence and start it again, i can鈥檛 get back to last state of conversation handler
Am i doing something wrong? Any example how to implment this
Thanks!
did you name the conversation and set persistent to true?
https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.conversationhandler.html#telegram.ext.ConversationHandler.name
i will send part of the file i'm using with this bot:
bot_persistence = PicklePersistence(filename=config['telegram_persistence_pickle'])
updater = Updater(use_context=True, bot=self, persistence=bot_persistence)
dp.add_handler(
ConversationHandler(
entry_points=[CommandHandler('start', bot_start, pass_args=True, pass_job_queue=True)],
states={
0: [
MessageHandler(Filters.all, bot_valid),
CallbackQueryHandler(bot_valid, pattern='^.*$')
],
1: [
MessageHandler(Filters.all, bot_run),
CallbackQueryHandler(bot_run, pattern='^.*$'),
]
},
fallbacks=[MessageHandler(Filters.all, bot_start)],
name="global",
allow_reentry=True,
)
)
=) found, the conversation handler have a persistence param, thanks again!
I got a problem...
i'm using a object (BotObject) to run "the bot"
should "the bot" be outside the object, without the "self" / object declarations?
PicklingError("Can't pickle <function BotObject.bot_valid at 0x7fdfc03542f0>: it's not the same object as __main__.BotObject.bot_valid",)
File "/usr/local/lib/python3.6/dist-packages/telegram/ext/dispatcher.py", line 390, in process_update
handler.handle_update(update, self, check, context)
File "/usr/local/lib/python3.6/dist-packages/telegram/ext/conversationhandler.py", line 394, in handle_update
self.update_state(new_state, conversation_key)
File "/usr/local/lib/python3.6/dist-packages/telegram/ext/conversationhandler.py", line 410, in update_state
(self.conversations.get(key), new_state))
File "/usr/local/lib/python3.6/dist-packages/telegram/ext/picklepersistence.py", line 217, in update_conversation
self.dump_singlefile()
File "/usr/local/lib/python3.6/dist-packages/telegram/ext/picklepersistence.py", line 115, in dump_singlefile
pickle.dump(all, f)
Everything you want to put in PicklePersistence must be picklable. Google will help you define custom pickle behaviour for you class. Also, if you're using jupyter notebooks, this SE-answer might help.
This is however not an issue with PTB. So I'm going to close this.
Most helpful comment
did you name the conversation and set persistent to true?
https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.conversationhandler.html#telegram.ext.ConversationHandler.name