Move bot login timer into message text
All checks were successful
Build and deploy Backend / build (push) Successful in 41s
All checks were successful
Build and deploy Backend / build (push) Successful in 41s
This commit is contained in:
@@ -129,7 +129,7 @@ function loginReplyMarkup(token: string, expiresAt: Date) {
|
|||||||
inline_keyboard: [
|
inline_keyboard: [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
text: `Открыть MapFlow · ${formatRemaining(expiresAt)}`,
|
text: 'Открыть MapFlow',
|
||||||
url: `${config.webAppUrl}?telegram_login=${encodeURIComponent(token)}`,
|
url: `${config.webAppUrl}?telegram_login=${encodeURIComponent(token)}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -137,6 +137,15 @@ function loginReplyMarkup(token: string, expiresAt: Date) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loginMessageText(expiresAt: Date) {
|
||||||
|
return [
|
||||||
|
'Вход в MapFlow',
|
||||||
|
'',
|
||||||
|
'Перейдите по ссылке ниже.',
|
||||||
|
`Ссылка активна: ${formatRemaining(expiresAt)}`,
|
||||||
|
].join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
async function sendLoginMessage(
|
async function sendLoginMessage(
|
||||||
chatId: number,
|
chatId: number,
|
||||||
text: string,
|
text: string,
|
||||||
@@ -206,7 +215,7 @@ function scheduleLoginMessageTimer(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await editLoginMessage(chatId, messageId, 'MapFlow', token, expiresAt);
|
await editLoginMessage(chatId, messageId, loginMessageText(expiresAt), token, expiresAt);
|
||||||
const handle = setTimeout(() => {
|
const handle = setTimeout(() => {
|
||||||
void tick();
|
void tick();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@@ -267,7 +276,7 @@ export async function completeTelegramBotLogin(token: string) {
|
|||||||
await editLoginMessage(
|
await editLoginMessage(
|
||||||
request.telegramChatId,
|
request.telegramChatId,
|
||||||
request.telegramMessageId,
|
request.telegramMessageId,
|
||||||
'Вход выполнен.',
|
'Вход выполнен.\nМожно вернуться в MapFlow.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +304,7 @@ export async function handleTelegramBotWebhook(
|
|||||||
|
|
||||||
const [command, payload] = text.split(' ');
|
const [command, payload] = text.split(' ');
|
||||||
if (command !== '/start' || !payload?.startsWith(loginPrefix)) {
|
if (command !== '/start' || !payload?.startsWith(loginPrefix)) {
|
||||||
await sendLoginMessage(chatId, 'Открой вход с сайта MapFlow.');
|
await sendLoginMessage(chatId, 'Начните вход с сайта MapFlow.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +314,7 @@ export async function handleTelegramBotWebhook(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!request || request.status !== 'PENDING' || request.expiresAt <= new Date()) {
|
if (!request || request.status !== 'PENDING' || request.expiresAt <= new Date()) {
|
||||||
await sendLoginMessage(chatId, 'Ссылка входа устарела.');
|
await sendLoginMessage(chatId, 'Ссылка входа устарела.\nВернитесь на сайт и начните вход заново.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,7 +331,12 @@ export async function handleTelegramBotWebhook(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const sentMessage = await sendLoginMessage(chatId, 'MapFlow', token, request.expiresAt);
|
const sentMessage = await sendLoginMessage(
|
||||||
|
chatId,
|
||||||
|
loginMessageText(request.expiresAt),
|
||||||
|
token,
|
||||||
|
request.expiresAt,
|
||||||
|
);
|
||||||
|
|
||||||
await prisma.telegramLoginRequest.update({
|
await prisma.telegramLoginRequest.update({
|
||||||
where: { id: request.id },
|
where: { id: request.id },
|
||||||
|
|||||||
Reference in New Issue
Block a user