Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from uuid import uuid4
- from dotenv import load_dotenv
- from telegram import InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, InputTextMessageContent, \
- Update, InlineQueryResultPhoto, Bot, InputMediaPhoto
- from telegram.ext import ApplicationBuilder, CallbackContext, CallbackQueryHandler, CommandHandler, ContextTypes, \
- InlineQueryHandler
- load_dotenv()
- TOKEN = os.getenv('TOKEN')
- bot = Bot(token=TOKEN)
- async def inline_query(update: Update, context) -> None:
- """Handle the inline query. This is run when you type: @simplewolframbot <query>"""
- keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("Immagine", callback_data="1")]])
- empty_image="https://upload.wikimedia.org/wikipedia/commons/5/59/Empty.png"
- results = [
- InlineQueryResultPhoto(
- id=str(uuid4()),
- photo_url=empty_image,
- thumbnail_url=empty_image,
- reply_markup=keyboard
- )
- ]
- await context.bot.answer_inline_query(update.inline_query.id, results=results)
- async def button(update: Update, context: CallbackContext) -> None:
- """Handle the callback query. Threplyis is run when you click the button."""
- query=update.callback_query
- await query.answer()
- img="https://upload.wikimedia.org/wikipedia/commons/e/e9/Felis_silvestris_silvestris_small_gradual_decrease_of_quality.png"
- img=InputMediaPhoto(media=img, caption="This is a cat")
- if query.data == "1":
- #await query.edit_message_text(f"{update} ")
- await query.edit_message_media(media=img, reply_markup=None)
- app = ApplicationBuilder().token(TOKEN).build()
- app.add_handler(InlineQueryHandler(inline_query))
- app.add_handler(CallbackQueryHandler(button))
- app.run_polling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement