skip to Main Content

I’m trying create a news telegram bot. But iI can’t send messages with interactive buttons.

The reason why I use the buttons is to make a menu, I would appreciate if you could show an example of making an interactive menu instead of just adding it.

Using Language : Python 3.9 & Telebot Library

Like this:

enter image description here

3

Answers


  1. Telebot provides the following types for InlineKeyboard:


    An basic example would look like

    from telebot import TeleBot
    from telebot import types
    
    bot = TeleBot("859163076:A......")
    chat_id = 12345
    
    button_foo = types.InlineKeyboardButton('Foo', callback_data='foo')
    button_bar = types.InlineKeyboardButton('Bar', callback_data='bar')
    
    keyboard = types.InlineKeyboardMarkup()
    keyboard.add(button_foo)
    keyboard.add(button_bar)
    
    bot.send_message(chat_id, text='Keyboard example', reply_markup=keyboard)
    

    Which will result in the following message send to chat_id:

    enter image description here

    Login or Signup to reply.
  2.     import telebot
        from telebot import types
        
        bot = TeleBot("859163076:A......")
        chat_id = 12345
            
        def send_welcome(message):
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        but1 = types.KeyboardButton("Button1")
        but2 = types.KeyboardButton("Button2")
        markup.add(but1, but2)
        bot.reply_to(message, "{0.first_name}, Welcome!".format(message.from_user), parse_mode='html', reply_markup=markup)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search