Advertisement
icarussiano

test

Apr 1st, 2024
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 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
  6.  
  7. from telegram.ext import ApplicationBuilder, CallbackContext, CallbackQueryHandler, CommandHandler, ContextTypes, \
  8.     InlineQueryHandler
  9.  
  10. load_dotenv()
  11. TOKEN = os.getenv('TOKEN')
  12. bot = Bot(token=TOKEN)
  13.  
  14. async def inline_query(update: Update, context) -> None:
  15.     """Handle the inline query. This is run when you type: @simplewolframbot <query>"""
  16.     keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("Info Update", callback_data="Info")]])
  17.     results = [
  18.         InlineQueryResultArticle(
  19.             id=str(uuid4()),
  20.             title="Risultato",
  21.             input_message_content=InputTextMessageContent("boh"),
  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.     if query.data == "Info":
  32.         await query.edit_message_text(f"{update} ")
  33.  
  34. async def answer(update: Update, context: CallbackContext) -> None:
  35.     """Handle the /answer command."""
  36.     # Check if the message is a reply to another message
  37.     if update.message.reply_to_message:
  38.         # Get the text of the replied message
  39.         reply_text = update.message.reply_to_message.text
  40.         reply_id = update.message.reply_to_message.message_id
  41.         # Echo the text back to the chat
  42.         await context.bot.send_message(chat_id=update.message.chat_id, text=str(reply_id))
  43.  
  44. app = ApplicationBuilder().token(TOKEN).build()
  45. app.add_handler(InlineQueryHandler(inline_query))
  46. app.add_handler(CallbackQueryHandler(button))
  47. app.add_handler(CommandHandler("answer", answer))
  48. app.run_polling()
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement