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:

Telebot provides the following types for InlineKeyboard:
InlineKeyboardMarkup; The keyboardInlineKeyboardButton; The markup buttonAn 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:

In this example, we create a menu with two buttons, "Button 1" and "Button 2", and process each button separately. When the user selects one of the buttons, the bot sends the corresponding message.
import telebot
from telebot import types
bot = telebot.TeleBot('YOUR_BOT_TOKEN')
#Command /start
@bot.message_handler(commands=['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Bottom 1")
item2 = types.KeyboardButton("Bottom 2")
markup.add(item1, item2)
bot.send_message(message.chat.id, "Select option:", reply_markup=markup)
#Bottom 1
@bot.message_handler(func=lambda message: message.text == "Bottom 1")
def button1(message):
bot.send_message(message.chat.id, "U select bottom 1")
#Bottom 2
@bot.message_handler(func=lambda message: message.text == "Bottom 2")
def button2(message):
bot.send_message(message.chat.id, "U select bottom 2")
#Start bot
if __name__ == '__main__':
bot.polling(none_stop=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With