Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FEATURE] add ConversationHandler state to CallbackContext #2331

@MrTsepa

Description

@MrTsepa

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

While using ConversationHandler there is no possibility to check which state a callback was triggered from.

In my case I have a bot for a group game and I have commands like /add_me, /remove_me which every user may trigger at any time during the game. I would like to update my internal state differently depending on which state the conversation is currently in.

Describe the solution you'd like

As a solution I'd like to see an additional field in CallbackContext, e.g. {"conversation_data": {"current_state": <MY_STATE>}}. This can be easily done by implementing collect_additional_context method in ConversationHandler class.

Describe alternatives you've considered

There are two ways to achieve what I need using current code:

  1. assuming I only has one ConversationHandler and it was added to dispatcher first, I can run

    context.dispatcher.handlers[0][0].conversations[(update.effective_chat.id,)]
    

    however this method is error-prone if i have many conversation handlers or I have nested ones.

  2. I can manually update context with conversation_data field, however this would require editing all of my callbacks and therefore also error-prone.

Additional context

N/A

I will be happy to make a PR if you find this useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions