Skip to content

Commit

Permalink
WebApp for QR
Browse files Browse the repository at this point in the history
  • Loading branch information
annndruha committed Jan 21, 2023
1 parent facff49 commit 6526170
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
'auth': '🔑 Авторизация',
'about': '📄 Описание',
'back': '◀️ Назад',
'kb_print': 'Настройки печати',
'kb_print_copies': 'Копий:',
'kb_print_side': 'Односторонняя печать',
'kb_print_two_side': 'Двухсторонняя печать',
'qr': '📷 Отсканировать QR',
'kb_print': '⚙️ Настройки печати',
'kb_print_copies': '📑 Копий:',
'kb_print_side': '📎 Односторонняя печать',
'kb_print_two_side': '🖇 Двухсторонняя печать',
'hello': '👋🏻 Привет! Я телеграм-бот бесплатного принтера.\n'
'Отправьте PDF файл и получите PIN для печати.',
'help': 'Я телеграм-бот бесплатного принтера профкома студентов физического факультета МГУ!\n\n'
Expand Down Expand Up @@ -45,8 +46,8 @@
'file_size_error': '⚠️ Принимаются только файлы размером меньше 3 MB.\nФайл <b>{}</b> не принят.',
'send_to_print': '✅ Файл <b>{}</b> успешно загружен. '
'Для печати подойдите к принтеру и введите PIN:\n\n<b>{}</b>\n\n'
'Или <a href="https://printer.ui.profcomff.com/qr#{}">отсканируйте QR код на экране '
'принтера.</a>\n',
'Или нажмите кнопку ниже.',
'qr_print': 'https://printer.ui.test.profcomff.com/qr#{}',
'settings_warning': '\nНастройки сохраняются автоматически.',
'settings_change_fail': 'Что-то сломалось, настройки печати не изменены, попробуйте через пару минут.',
'unknown_keyboard_payload': 'Видимо бот обновился, выполните команду /start',
Expand Down
8 changes: 5 additions & 3 deletions src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, WebAppInfo
from telegram.constants import ParseMode
from telegram.error import TelegramError
from telegram.ext import ContextTypes, CallbackContext
Expand Down Expand Up @@ -119,9 +119,10 @@ async def handler_print(update: Update, context: ContextTypes.DEFAULT_TYPE):
rfile = requests.post(settings.PRINT_URL + '/file/' + pin, files=files)
if rfile.status_code == 200:
reply_markup = InlineKeyboardMarkup(
[[InlineKeyboardButton(ans['kb_print'], callback_data=f'print_settings_{pin}')]])
[[InlineKeyboardButton(text=ans['qr'], web_app=WebAppInfo(ans['qr_print'].format(pin)))],
[InlineKeyboardButton(ans['kb_print'], callback_data=f'print_settings_{pin}')]])
await update.message.reply_text(
text=ans['send_to_print'].format(update.message.document.file_name, pin, pin),
text=ans['send_to_print'].format(update.message.document.file_name, pin),
reply_markup=reply_markup,
reply_to_message_id=update.message.id,
disable_web_page_preview=True,
Expand Down Expand Up @@ -201,6 +202,7 @@ async def __print_settings_solver(update: Update, context: CallbackContext):
return

keyboard = [
[InlineKeyboardButton(text=ans['qr'], web_app=WebAppInfo(ans['qr_print'].format(pin)))],
[InlineKeyboardButton(f'{ans["kb_print_copies"]} {options["copies"]}', callback_data=f'print_copies_{pin}')],
[InlineKeyboardButton(ans['kb_print_two_side'] if options['two_sided'] else ans['kb_print_side'],
callback_data=f'print_twosided_{pin}')]]
Expand Down

0 comments on commit 6526170

Please sign in to comment.