Advertisement
icarussiano

Untitled

Apr 3rd, 2024 (edited)
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. import os
  2. from uuid import uuid4
  3. from dotenv import load_dotenv
  4. from telegram import InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, InputTextMessageContent, \
  5.     Update, InlineQueryResultPhoto, Bot, InputMediaPhoto
  6. from telegram.ext import ApplicationBuilder, CallbackContext, CallbackQueryHandler, CommandHandler, ContextTypes, \
  7.     InlineQueryHandler
  8.  
  9. load_dotenv()
  10. TOKEN = os.getenv('TOKEN')
  11. bot = Bot(token=TOKEN)
  12.  
  13. async def inline_query(update: Update, context) -> None:
  14.     """Handle the inline query. This is run when you type: @simplewolframbot <query>"""
  15.     keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("Immagine", callback_data="1")]])
  16.     empty_image="https://upload.wikimedia.org/wikipedia/commons/5/59/Empty.png"
  17.     results = [
  18.         InlineQueryResultPhoto(
  19.             id=str(uuid4()),
  20.             photo_url=empty_image,
  21.             thumbnail_url=empty_image,
  22.             reply_markup=keyboard
  23.         )
  24.     ]
  25.     await context.bot.answer_inline_query(update.inline_query.id, results=results)
  26.  
  27. async def button(update: Update, context: CallbackContext) -> None:
  28.     """Handle the callback query. Threplyis is run when you click the button."""
  29.     query=update.callback_query
  30.     await query.answer()
  31.     img="https://upload.wikimedia.org/wikipedia/commons/e/e9/Felis_silvestris_silvestris_small_gradual_decrease_of_quality.png"
  32.     img=InputMediaPhoto(media=img, caption="This is a cat")
  33.     if query.data == "1":
  34.         #await query.edit_message_text(f"{update} ")
  35.         await query.edit_message_media(media=img, reply_markup=None)
  36.  
  37. app = ApplicationBuilder().token(TOKEN).build()
  38. app.add_handler(InlineQueryHandler(inline_query))
  39. app.add_handler(CallbackQueryHandler(button))
  40. app.run_polling()
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement