Skip to content

Commit d9ace2a

Browse files
committed
fix typo + add inline keyboard example
1 parent 2b3c86b commit d9ace2a

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎examples/inline_example.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This example show how to write an inline mode telegramt bot use pyTelegramBotAPI.
1+
# This example show how to write an inline mode telegram bot use pyTelegramBotAPI.
22
import telebot
33
import time
44
import sys
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This example show how to use inline keyboards and process button presses
2+
import telebot
3+
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
4+
5+
TELEGRAM_TOKEN = '<TOKEN>'
6+
7+
bot = telebot.TeleBot(TELEGRAM_TOKEN)
8+
9+
def gen_markup():
10+
markup = InlineKeyboardMarkup()
11+
markup.row_width = 2
12+
markup.add(InlineKeyboardButton("Yes", callback_data=f"cb_yes"),
13+
InlineKeyboardButton("No", callback_data=f"cb_no"))
14+
return markup
15+
16+
@bot.callback_query_handler(func=lambda call: True)
17+
def callback_query(call):
18+
if call.data == "cb_yes":
19+
bot.answer_callback_query(call.id, "Answer is Yes")
20+
elif call.data == "cb_no":
21+
bot.answer_callback_query(call.id, "Answer is No")
22+
23+
@bot.message_handler(func=lambda message: True)
24+
def message_handler(message):
25+
bot.send_message(message.chat.id, "Yes/no?", reply_markup=gen_markup())
26+
27+
bot.polling(none_stop=True)

0 commit comments

Comments
 (0)