So I’m making a telegram bot with pyTelegramBotApi.
I made a reply keyboard which appears after a /start command, the thing is that when user presses the button they should receive some message and an inline keyboard with that.
I don’t know how do I put inline keyboard (kinda) in a reply keyboard.
def start_command(message):
keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
button1 = types.KeyboardButton(text="Button 1", FUNC1)
button2 = types.KeyboardButton(text="Button 2", FUNC2)
button3 = types.KeyboardButton(text="Button 3", FUNC3)
keyboard.add(button1, button2, button3)
bot.send_message(
message.chat.id,
'Hello!',
reply_markup=keyboard
)
FUNC1, FUNC2, FUNC3 represent that thing (function) that should send a text with an inline keyboard.
2
Answers
Don’t be confused with the word “keyboard”, when you see a “classic” keyboard which sticks to a bottom of the chat, this is just a bunch of message templates, nothing else (there’re 2 special buttons, one asking for Geo and another one asking for Phone, but nevermind for now).
So, what happens when user presses your button with “Button 1” text? A message is sent to your bot with that text. And to properly react to that text, write a handler which checks for
message.text
exact match. For your convenience, I’ve updated your code a bit and wrote a handler for a case when user presses button with “Button 1” text.When user press “Button 1”, your bot will send them a message with an inline keyboard consisting of one inline button, leading to stackoverflow.com.
Find codes in the image below to embed an inline keyboard inside a reply keyboard