diff --git a/telegram/ext/inlinemenuhandler.py b/telegram/ext/inlinemenuhandler.py new file mode 100644 index 00000000000..782bc7e6d2a --- /dev/null +++ b/telegram/ext/inlinemenuhandler.py @@ -0,0 +1,328 @@ +#!/usr/bin/env python +# +# A library that provides a Python interface to the Telegram Bot API +# Copyright (C) 2015-2020 +# Leandro Toledo de Souza +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser Public License for more details. +# +# You should have received a copy of the GNU Lesser Public License +# along with this program. If not, see [http://www.gnu.org/licenses/]. +"""This module contains the InlineMenuHandler.""" + +import re +from functools import partial +from telegram import InlineKeyboardButton, InlineKeyboardMarkup +from telegram.ext import ConversationHandler, CommandHandler, CallbackQueryHandler + + +class InlineMenuHandler(ConversationHandler): + """ + A handler to display a menu with the help of :class:`telegram.InlineKeyboardMarkup` by managing + a collection of data for the menus sites. Build on top of + :class:`telegram.ext.ConversationHandler`. + + To build a menu, this handler needs a :obj:`dict` named :attr:`menus` containing the different + menu steps. For each step, the corresponding dict value is a tuple of + + #. A description of the currently avaiable methods sent as the message text + #. An array of tuples containing + + #. The button label + #. the state this button leads to + + #. Optionally a callback function used to process the selected input + + All descriptions/labels may be subsituted by callbacks returning strings to adapt the output to + the user input. + + The usual arguments ``update`` and ``context`` will be passed all callback functions. + + Note that the ``data`` field of the corresponding :class:`telegram.CallbackQuery` will be of + the form ``menu