-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_buttons.py
More file actions
39 lines (30 loc) · 1.27 KB
/
inline_buttons.py
File metadata and controls
39 lines (30 loc) · 1.27 KB
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
38
39
# adding InlineButtons
# no message + callbacks → only inline keyboard
# message-based interaction → reply keyboard
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import CommandHandler, CallbackQueryHandler, ContextTypes, ApplicationBuilder
from dotenv import load_dotenv
import os
load_dotenv()
API = os.getenv("BOT_TOKEN")
async def sendkeybs(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = InlineKeyboardMarkup([
[InlineKeyboardButton("InlineKeyb1", callback_data="k1"),
InlineKeyboardButton("InlineKeyb2", callback_data="k2")],
[InlineKeyboardButton("InlineKeyb3", callback_data="k3")]
])
await update.message.reply_text("Choose:", reply_markup=keyboard)
async def handle_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
await query.answer()
if query.data == "k1":
text = "You pressed button 1"
elif query.data == "k2":
text = "You pressed button 2"
else:
text = "You pressed button 3"
await query.edit_message_text(text)
app = ApplicationBuilder().token(API).build()
app.add_handler(CommandHandler("start", sendkeybs))
app.add_handler(CallbackQueryHandler(handle_callback))
app.run_polling()