Exemple #1
0
def on_select(bot, callback_query, value, selected):
    print(value, not selected)
    if selected:
        bot.answer_callback_query(callback_query_id=callback_query.id)
    else:
        keyboard = InlineKeyboard(
            callback_query.message.reply_markup.inline_keyboard)
        buttons = keyboard.group("select")
        for idx, button in enumerate(buttons, start=1):
            text, _ = select_options[idx]
            keyboard.replace(
                button.callback_data,
                InlineKeyboardButton(text="{0}{1}".format(emoji[1], text),
                                     callback_data=build_callback_data(
                                         "select", idx, False)))
        new_button = InlineKeyboardButton(
            text="{0}{1}".format(emoji[0], select_options[value][0]),
            callback_data=build_callback_data("select", value, True))
        if keyboard.replace(build_callback_data("select", value, False),
                            new_button):

            bot.edit_message_text(chat_id=callback_query.from_user.id,
                                  message_id=callback_query.message.message_id,
                                  text=callback_query.message.text,
                                  reply_markup=keyboard.markup())
    return bot.stop_call
def on_show_items(bot, message):
    btn_0 = InlineKeyboardButton(text="some data", callback_data="some data")
    btn_1 = InlineKeyboardButton(text="my btn 1",
                                 callback_data=build_callback_data(
                                     "my-btn", "one", 1, True, {"a": 1}))
    btn_2 = InlineKeyboardButton(text="my btn 2",
                                 callback_data=build_callback_data(
                                     "my-btn", "two", 2, False, {"b": 2}))

    keyboard = InlineKeyboard([[btn_0], [btn_1, btn_2]])
    bot.send_message(chat_id=message.chat.id,
                     text="select one",
                     reply_markup=keyboard.markup())
    return bot.stop_call
def on_change(bot, callback_query, value, selected):
    keyboard = InlineKeyboard(
        callback_query.message.reply_markup.inline_keyboard)
    new_button = InlineKeyboardButton(
        text="{0}status".format(emoji[1] if selected else emoji[0]),
        callback_data=build_callback_data("switch", value, not selected))
    if keyboard.replace(build_callback_data("switch", value, selected),
                        new_button):

        bot.edit_message_text(chat_id=callback_query.from_user.id,
                              message_id=callback_query.message.message_id,
                              text="switch status: {0}".format(not selected),
                              reply_markup=keyboard.markup())
    return bot.stop_call
def on_select_item(bot, callback_query, item_id, selected):
    keyboard = InlineKeyboard(
        callback_query.message.reply_markup.inline_keyboard)
    new_button = InlineKeyboardButton(
        text="{0}{1}".format(emoji[1] if selected else emoji[0],
                             menu[item_id][0]),
        callback_data=build_callback_data("select-item", item_id,
                                          not selected))
    if keyboard.replace(build_callback_data("select-item", item_id, selected),
                        new_button):
        bot.edit_message_text(chat_id=callback_query.from_user.id,
                              message_id=callback_query.message.message_id,
                              text=callback_query.message.text,
                              reply_markup=keyboard.markup())
    return bot.stop_call
def on_show_keyboard(bot, message):
    keyboard = InlineKeyboard()
    keyboard.add_buttons(
        InlineKeyboardButton(text="{0}status".format(emoji[0]),
                             callback_data=build_callback_data(
                                 "switch", 123, True)))
    keyboard.add_buttons(
        InlineKeyboardButton(text="submit", callback_data="submit"))
    bot.send_message(chat_id=message.chat.id,
                     text="switch status: {0}".format(True),
                     reply_markup=keyboard.markup())
    return bot.stop_call
def on_show_menu(bot, message, *args):
    keyboard = InlineKeyboard()
    keyboard.add_buttons(*[
        InlineKeyboardButton(text=text,
                             callback_data=build_callback_data(
                                 "select-item", item_id, False))
        for item_id, (text, _) in menu.items()
    ])
    keyboard.add_buttons(
        InlineKeyboardButton(text="submit", callback_data="submit"))
    bot.send_message(
        chat_id=message.chat.id,
        text="your menu",
        reply_markup=keyboard.markup(),
    )
    return bot.stop_call
Exemple #7
0
def on_show_keyboard(bot, message):
    keyboard = InlineKeyboard()
    keyboard.add_buttons(*[
        InlineKeyboardButton(
            text="{0}{1}".format(emoji[0] if selected else emoji[1], text),
            callback_data=build_callback_data("select", value, selected))
        for value, (text, selected) in select_options.items()
    ])
    keyboard.add_buttons(
        InlineKeyboardButton(text="submit", callback_data="submit"))
    bot.send_message(
        chat_id=message.chat.id,
        text="Your selections:",
        reply_markup=keyboard.markup(),
    )
    return bot.stop_call