Skip to content

[FEATURE] #2148

Closed
❔ question
@ImKewal

Description

@ImKewal

Is your feature request related to a problem? Please describe.

I made a global class which extends the functionality of sending message by saving the chat id and message id of message sent by bot. So object of this class will have the list of all the messages sent by bot and also have methods to delete duplicate bot messages. I want to add this object to pickle persistence of bot but there is no way to it. Pickle Persistence class of PTB library only give options to add chat_data, bot_data and user_data to persistence; No option to add user defined objects and variables to the persistence.

Describe the solution you'd like

I think it would be nice if you would add a feature to pass a dictionary as a parameter to the PicklePersistence() method which will add the global variables mentioned in the dictionary to the persistence, and after restarting bot, those variables will be reloaded.

Describe alternatives you've considered

I considered saving those objects to the bot_data of the Callback context while exiting bot and restoring that bot_data copy at every restart of bot; as bot_data get persisted with inbuilt persistence. But that didn't work, as callback context is only accessible inside any handler not in main. So I need to call a dump_handler once before exiting and call a load_handler after the restart. So there should be predefined functions through which user can call any function just after bot start and just before bot stop.
Also bot_data should be available in whole main function or there should be any other *_data free from callback context to which any object can be saved inside main function so it get persisted with default persistence.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions