Skip to content

Instantly share code, notes, and snippets.

@Firemoon777
Created June 23, 2022 13:45
Show Gist options
  • Save Firemoon777/4fc9a94652c4f9c6eca2197e8fe25b7a to your computer and use it in GitHub Desktop.
Save Firemoon777/4fc9a94652c4f9c6eca2197e8fe25b7a to your computer and use it in GitHub Desktop.
import logging
import os
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Application, CommandHandler, CallbackContext, CallbackQueryHandler
TOKEN = os.environ["TOKEN"]
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
async def setup(update: Update, context: CallbackContext):
context.user_data.clear()
keyboard = [
[InlineKeyboardButton("perform", callback_data="perform")]
]
msg = await update.message.reply_text(
text="test",
reply_markup=InlineKeyboardMarkup(keyboard)
)
await msg.pin()
async def perform(update: Update, context: CallbackContext):
query = update.callback_query
await query.answer("short text", show_alert=True)
await query.message.unpin()
await query.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup([]))
all_handlers = [
CommandHandler("setup", setup),
CallbackQueryHandler(perform),
]
app = Application.builder().token(TOKEN).build()
app.add_handlers(all_handlers)
app.run_polling()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment