Skip to content

Conversation

Bibo-Joshi
Copy link
Member

While working on my personal bot, I found building menus with InlineKeyboardMarkups to be somewhat tiresome sometimes. You have to build a lot of InlineKeyboardButtons, add a lot of CallbackQueryHandlers to your ConversationHandler and keep the overview in the process.

This is an attempt to build a more user friendly handler as "wrapper" on top of the ConversationHandler for creating menus. For each state only the following information is needed:

  • A message text
  • An array of (button_label, next_state)-type tuples
  • optionally a callback to handle the user input

All the labels/text may also be replaced by a callback to adjust the texts according to the user input, but that is optional.
A InlineMenuHandler could look like this:

InlineMenuHandler(
    name = 'imh',
    start_command='start',
    parse_mode='Markdown',
    menus = {
       InlineMenuHandler.MAIN_MENU : (
            '*Menu 1:* _Top Level Menu_',
            [
                [('1.1', '1.1'), ('1.1', '1.1')],
                [('1.2', '1.2'), ('1.2', '1.2')]
            ]
        ),
        '1.1': (
            '*Menu 1.1:* _One Of Two Lower Level Menus_',
            [
                [('1', InlineMenuHandler.MAIN_MENU), ('1.2', '1.2')]
            ]
        ),
        '1.2': (
            description_callback,
            [
                [('1', InlineMenuHandler.MAIN_MENU), ('End', ConversationHandler.END)]
            ],
            parse_input_callback
        ),
        ConversationHandler.END: (
            'The conversation ends here. Bye'
        )
    },
    fallbacks = [CommandHandler('cancel', fallback)]
)

Especially for menus that need little processing of the user input, I hope that this is easier to maintain than a full grown ConversationHandler.

I'm aware that such a new feature will needs thorough discussion, may well be rejected and also that we have other issues to discuss in dev chat :D Still, I wanted to put it out here.

@JosXa
Copy link
Contributor

JosXa commented Jan 26, 2020

I just drafted
image
is response to this user's message and it seems to be related.

@JosXa
Copy link
Contributor

JosXa commented Jan 26, 2020

How about entry_points instead of start_command to make it more generic?

@Bibo-Joshi
Copy link
Member Author

How about entry_points instead of start_command to make it more generic?

Do you mean just the naming of the parameter or would you suggest allowing arbitrary entry points?

@Bibo-Joshi
Copy link
Member Author

Closing for now. I don't think this approach will ever make it into the main lib. We might see better approaches in a contrib repo. Refer to #1912

@Bibo-Joshi Bibo-Joshi closed this Oct 15, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2020
@Bibo-Joshi Bibo-Joshi deleted the inline_menu_handler branch November 23, 2020 09:11
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants