0
votes

I have a question about inline-buttons in telegram. So I have a lot of inline-buttons and I want to divide them to several pages. On each page I have forward => and back <= button to move between pages. Click on each button returns document.

After inline keyboard call I placed the handler that processing click on each button. First page buttons works correct except forward and back buttons. Pages don't change. I am using telebot lib.

     bot = telebot.TeleBot(token)
    @bot.message_handler(commands=['start','help'])
    def start(o):
          bot.send_message(o.chat.id,'Hi,use buttons!')

    def name(m):
            keyboard = types.InlineKeyboardMarkup()
            keyboard.add(*[types.InlineKeyboardButton(text=name,callback_data=name) for name
                        in ['button1','button2']])
            keyboard.add(*[types.InlineKeyboardButton(text=name,callback_data=name) for name
                        in ['button3','button4']])
                  keyboard.add(*[types.InlineKeyboardButton(text=name,callback_data=name) for name
                        in ['=>']])
            msg = bot.send_message(m.chat.id,'-----------Choose button----------',reply_markup=keyboard) 
    @bot.callback_query_handler(func=lambda c:True)
    def inline(c):
        if c.data == 'button1':
            bot.send_document(c.message.chat.id,open('button1.pdf', 'rb'))
        elif c.data == 'button2':
            bot.send_document(c.message.chat.id,open('button2.pdf', 'rb'))
        elif c.data == 'button3':
            bot.send_document(c.message.chat.id,open('button3.pdf', 'rb'))
        elif c.data == 'button4' :
            bot.send_document(c.message.chat.id,open('button4.pdf', 'rb'))
        elif c.data == '=>' : 
            keyboard = types.InlineKeyboardMarkup()
            keyboard.add(*[types.InlineKeyboardButton(text=name,callback_data=name) for name
                        in ['button5','button6']])
while True: 
    try:
        bot.polling(none_stop=True)

    except Exception as e:
        print(e)
        time.sleep(15)
1

1 Answers

0
votes

When the => button is clicked, you are just creating a new keyboard, but you are not posting the new keyboard with edit_message_reply_markup.

keyboard = types.InlineKeyboardMarkup()
keyboard.add(*[types.InlineKeyboardButton(text=name,callback_data=name) for name
                    in ['button5','button6']])

bot.edit_message_reply_markup(chat_id=c.message.chat.id, message_id=c.message.message_id, reply_markup=keyboard)