30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
|
|
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, Updater, CallbackQueryHandler, CallbackContext
|
|
|
|
|
|
# Function to handle button clicks (callback queries)
|
|
async def button(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
query = update.callback_query
|
|
|
|
user = query.from_user
|
|
|
|
await query.answer() # Acknowledge the button press
|
|
|
|
if query.data == 'register':
|
|
try:
|
|
keyboard = [[InlineKeyboardButton("Abmelden", callback_data='cancelRegister')]]
|
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
|
await context.bot.send_message(user.id, "Registered", reply_markup=reply_markup)
|
|
except Exception as e:
|
|
await context.bot.send_message(query.message.chat_id, f"@{user.username} Leider kam es zu einem Fehler: {str(e)}")
|
|
|
|
if query.data == 'cancelRegister':
|
|
try:
|
|
await context.bot.send_message(user.id, "Cancelled")
|
|
except Exception as e:
|
|
await context.bot.send_message(query.message.chat_id, f"@{user.username} Leider kam es zu einem Fehler: {str(e)}")
|
|
|
|
return
|
|
|
|
|