Skip to content

Conversation

@syntx
Copy link

@syntx syntx commented Jul 8, 2018

Allowed ConversationHandler to possibly return a value from its handle_update method

Useful for allowing ConversationHandler to be nested in another ConversationHandler (see #405).

This solution was inspired by transitions library's implementation of Hierarchical State Machines (HSM) (see the 'remap' keyword).

With this change it's now possible to return arbitrary state names in the nested ConversationHandler as long as the state name is mapped to an external ConversationHandler state (e.g. you can have your callback functions return SUCCESS, FAILURE, CANCELED etc. as you wish. You can also map ConversationHandler.END on one or both ends).

@syntx syntx force-pushed the nested-conversationhandler branch from 00d3d24 to 4981c4e Compare July 8, 2018 09:54
@Eldinnie
Copy link
Member

Hi @syntx

I'm not really seeing how this structure would go down. It's also missing tests. Can you please add tests for expected and failing bahavior? They will be needed for the PR anyway and it might help me understand what this is supposed to do.

Pieter

@jsmnbom jsmnbom added the 📋 pending-reply work status: pending-reply label Jul 22, 2018
…d nesting test in test_conversationhandler.py
@syntx
Copy link
Author

syntx commented Jul 22, 2018

Hi @Eldinnie,

I've added a new test in test_conversationhandler.py (test_nested_conversation_handler).
The test shows the nested mapping options made available by this simple yet powerful change. Please take a look at the definition of "drinking_map_to_parent" for 5 different options:

    self.drinking_map_to_parent = {
        # Option 1 - Map a fictional internal state to an external parent state
        self.REPLENISHING: self.BREWING,
        # Option 2 - Map a fictional internal state to the END state on the parent
        self.STOPPING: self.END,
        # Option 3 - Map the internal END state to an external parent state
        self.END: self.CODING,
        # Option 4 - Map an external state to the same external parent state
        self.CODING: self.CODING,
        # Option 5 - Map an external state to the internal entry point
        self.DRINKING: self.DRINKING
    }

@jh0ker
Copy link
Member

jh0ker commented Aug 23, 2019

Just wanna say, nice solution a problem that came up a couple times already. I never thought it was worth it implementing something cause there didn't seem to be a neat solution, but i think this is good. Even allows you to go up the conversation handler tree arbitrarily high, which is even better. If we have a bit more documentation and an example for this, I'd approve this PR. Oh and there's a couple flake8 errors in the tests.

@tsnoam tsnoam closed this in #1512 Oct 11, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Aug 20, 2020
@Bibo-Joshi Bibo-Joshi added 🔌 enhancement pr description: enhancement and removed enhancement labels Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🔌 enhancement pr description: enhancement 📋 pending-reply work status: pending-reply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants