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
- 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("Info Update", callback_data="Info")]])
- results = [
- InlineQueryResultArticle(
- id=str(uuid4()),
- title="Risultato",
- input_message_content=InputTextMessageContent("boh"),
- 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()
- if query.data == "Info":
- await query.edit_message_text(f"{update} ")
- async def answer(update: Update, context: CallbackContext) -> None:
- """Handle the /answer command."""
- # Check if the message is a reply to another message
- if update.message.reply_to_message:
- # Get the text of the replied message
- reply_text = update.message.reply_to_message.text
- reply_id = update.message.reply_to_message.message_id
- # Echo the text back to the chat
- await context.bot.send_message(chat_id=update.message.chat_id, text=str(reply_id))
- app = ApplicationBuilder().token(TOKEN).build()
- app.add_handler(InlineQueryHandler(inline_query))
- app.add_handler(CallbackQueryHandler(button))
- app.add_handler(CommandHandler("answer", answer))
- app.run_polling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement