From 387a504801e2e5fd54346fe59ff048036b2ab872 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Fri, 8 May 2026 19:52:07 +0700 Subject: [PATCH] Tighten Telegram bot login UX --- src/auth/telegram-bot-login.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/auth/telegram-bot-login.ts b/src/auth/telegram-bot-login.ts index 60551f1..f76814b 100644 --- a/src/auth/telegram-bot-login.ts +++ b/src/auth/telegram-bot-login.ts @@ -110,13 +110,25 @@ export async function fetchTelegramPhoto(fileId: string) { }; } -async function sendLoginMessage(chatId: number, text: string, token?: string) { +function formatRemaining(expiresAt: Date) { + const seconds = Math.max(0, Math.ceil((expiresAt.getTime() - Date.now()) / 1000)); + const minutes = Math.floor(seconds / 60).toString(); + const rest = (seconds % 60).toString().padStart(2, '0'); + return `${minutes}:${rest}`; +} + +async function sendLoginMessage( + chatId: number, + text: string, + token?: string, + expiresAt?: Date, +) { const replyMarkup = token ? { inline_keyboard: [ [ { - text: 'Вернуться в MapFlow', + text: `Открыть MapFlow · ${formatRemaining(expiresAt ?? expiresIn(0))}`, url: `${config.webAppUrl}?telegram_login=${encodeURIComponent(token)}`, }, ], @@ -159,7 +171,7 @@ export async function getTelegramBotLoginStatus(token: string) { return { status: 'EXPIRED', sessionToken: null, user: null }; } - if (request.status === 'PENDING' && request.expiresAt <= new Date()) { + if (request.expiresAt <= new Date()) { await prisma.telegramLoginRequest.update({ where: { id: request.id }, data: { status: 'EXPIRED' }, @@ -202,7 +214,7 @@ export async function handleTelegramBotWebhook( }); if (!request || request.status !== 'PENDING' || request.expiresAt <= new Date()) { - await sendLoginMessage(chatId, 'Ссылка входа устарела. Открой вход заново.'); + await sendLoginMessage(chatId, 'Ссылка входа устарела.'); return; } @@ -228,5 +240,5 @@ export async function handleTelegramBotWebhook( }, }); - await sendLoginMessage(chatId, 'Готово. Можно вернуться в MapFlow.', token); + await sendLoginMessage(chatId, 'MapFlow', token, request.expiresAt); }