Skip to content

Commit

Permalink
Merge pull request #6 from kercos/master
Browse files Browse the repository at this point in the history
fixe web-app-launcher for PTB > 20
  • Loading branch information
MBoretto authored Jan 21, 2024
2 parents f71fef0 + 3d8f493 commit 5cb9057
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions web-app-launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import logging

from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, WebAppInfo
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext
from telegram.ext import Application, CommandHandler, CallbackQueryHandler, CallbackContext

from config import TOKEN, URL, URL_TEST

Expand All @@ -26,54 +26,50 @@
logger = logging.getLogger(__name__)


def start(update: Update, context: CallbackContext) -> None:
async def start(update: Update, context: CallbackContext) -> None:
"""Sends a message with three inline buttons attached."""
keyboard = [
[InlineKeyboardButton("Scan QR codes", web_app=WebAppInfo(url=URL))],
]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Press to launch QR scanner', reply_markup=reply_markup)
await update.message.reply_text('Press to launch QR scanner', reply_markup=reply_markup)

def develop(update: Update, context: CallbackContext) -> None:
async def develop(update: Update, context: CallbackContext) -> None:
"""Sends a message with three inline buttons attached."""
keyboard = [
[InlineKeyboardButton("Scan QR codes with develop branch", web_app=WebAppInfo(url=URL_TEST))],
]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Press to launch QR scanner', reply_markup=reply_markup)
await update.message.reply_text('Press to launch QR scanner', reply_markup=reply_markup)

def button(update: Update, context: CallbackContext) -> None:
async def button(update: Update, context: CallbackContext) -> None:
"""Parses the CallbackQuery and updates the message text."""
query = update.callback_query

# CallbackQueries need to be answered, even if no notification to the user is needed
# Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
query.answer()

query.edit_message_text(text=f"Selected option: {query.data}")
await query.edit_message_text(text=f"Selected option: {query.data}")


def help_command(update: Update, context: CallbackContext) -> None:
async def help_command(update: Update, context: CallbackContext) -> None:
"""Displays info on how to use the bot."""
update.message.reply_text("Type /start and open the QR dialog.")
await update.message.reply_text("Type /start and open the QR dialog.")


def main() -> None:
"""Run the bot."""
# Create the Updater and pass it your bot's token.
updater = Updater(TOKEN)
# Create the Application and pass it your bot's token.
application = Application.builder().token(TOKEN).build()

updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CommandHandler('dev', develop))
updater.dispatcher.add_handler(CallbackQueryHandler(button))
updater.dispatcher.add_handler(CommandHandler('help', help_command))
application.add_handler(CommandHandler('start', start))
application.add_handler(CommandHandler('dev', develop))
application.add_handler(CallbackQueryHandler(button))
application.add_handler(CommandHandler('help', help_command))

# Start the Bot
updater.start_polling()

# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT
updater.idle()
application.run_polling(allowed_updates=Update.ALL_TYPES)


if __name__ == '__main__':
Expand Down

0 comments on commit 5cb9057

Please sign in to comment.