Search code examples
pythontelegram-botpython-telegram-bot

How do show the result to user after he or she clicks multiple inline buttons


So this is my code. Basically you guys are familiar with subway...i want to create a part whereby when the user clicks multiple buttons and then clicks ok, it returns whatever that user has clicked except the Ok.

def sauce(update: Update, context: CallbackContext) -> int:
        if update.message.text == "Y" or update.message.text == "y":
            keyboard = ([
                    InlineKeyboardButton("No Sauce",callback_data='No Sauce'),
                    InlineKeyboardButton("Chipotle Southwest", callback_data='Chipotle Southwest'),
                    InlineKeyboardButton("Ranch", callback_data='Ranch'),
                    InlineKeyboardButton("BBQ", callback_data='BBQ'),
                    InlineKeyboardButton("Chilli Sauce", callback_data='Chilli Sauce'),
                    InlineKeyboardButton("Tomato Sauce", callback_data='Tomato Sauce'),
                    InlineKeyboardButton("Mustard", callback_data='Mustard'),
                    InlineKeyboardButton("Mayonese", callback_data='Mayonese'),
                    InlineKeyboardButton("Sweet Onion", callback_data='Sweet Onion'),
                    InlineKeyboardButton("Hot Pepper", callback_data='Hot Pepper'),
                    InlineKeyboardButton("Cheese Sauce", callback_data='Cheese Sauce'),
                    InlineKeyboardButton("Sweet Chilli", callback_data='Sweet Chilli'),
                    InlineKeyboardButton("Garlic Aioli", callback_data='Garlic Aioli'),
                    InlineKeyboardButton("Honey Mustard", callback_data='Honey Mustard'),
                ])
            reply_markup = InlineKeyboardMarkup([[button] for button in keyboard])

            update.message.reply_text('Please choose your sauces:', reply_markup = reply_markup)
            return CHECK2

        elif update.message.text == "N" or update.message.text == "n":
            update.message.reply_text("Please re-pick your option")
            return vegetables(update,context)

def check2(update: Update, context: CallbackContext) -> int:
        global sauces
        query = update.callback_query
        query.answer()
        sauces += query.data + ","
        query.edit_message_text(text=f"Selected option: {sauces}. Anymore(MAX 2)? Y/N")
        return SEASONING

I am only receiving back whatever that the user clicks once. E.g. if he clicks "no vegetables", he gets back "no vegetables", but if I click multiple buttons nothing happens.


Solution

  • You can use a dictionary whose key is the UserID and in the first step has an empty list

    When the user clicks on any of these buttons, data with the desired and appropriate text will be entered into your list.

    And finally, you can have the values ​​of the list After clicking on the OK button, you must set the list to an empty value

    To determine the status of each key, you can also have the confirmation or disapproval of each key by checking the list

    This way is an answer, if you have taken the idea I said you can easily implement it