-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript03.py
37 lines (26 loc) · 945 Bytes
/
script03.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
This example show how to use inline keyboards and process button presses.
"""
import telebot
from decouple import config
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
TOKEN = config("TELEGRAM_BOT_TOKEN")
bot = telebot.TeleBot(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()