I am making a chatterbot and I wonder how can I put inlinekeyboardbutton, how can I make that? I need a code of keyboardbutton that handles a big conversation, please and thank you.
Asked
Active
Viewed 2,441 times
2 Answers
0
import telebot
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
TELEGRAM_TOKEN = '<TOKEN>'
bot = telebot.TeleBot(TELEGRAM_TOKEN)
def gen_markup():
markup = InlineKeyboardMarkup()
markup.row_width = 2
markup.add(InlineKeyboardButton("Yes", callback_data="cb_yes"),
InlineKeyboardButton("No", callback_data="cb_no"))
return markup
@bot.callback_query_handler(func=lambda call: True)
def callback_query(call):
if call.data == "cb_yes":
bot.answer_callback_query(call.id, "Answer is Yes")
elif call.data == "cb_no":
bot.answer_callback_query(call.id, "Answer is No")
@bot.message_handler(func=lambda message: True)
def message_handler(message):
bot.send_message(message.chat.id, "Yes/no?", reply_markup=gen_markup())
bot.infinity_polling()

The Erish
- 11
- 1
- 5
-
2As itβs currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). β Community Mar 22 '22 at 18:39
-
Also add some more information's to you solution. Code-only is not an answer. β buhtz Feb 01 '23 at 10:58
0
You can create buttons with the code below:
from telebot import types
markup = InlinKeyboardMarkup(row_width=1) # row_width: number of buttons
some_item = types.InlineKeyboardButton("text of your button",
callback_data="main info")
markup.add(some_item)