Enhance Telegram bot message handling for login and activation callbacks
CI / Backend (build + test) (push) Successful in 1m20s
CI / Frontend (lint + typecheck + build) (push) Successful in 32s

- Updated the PnvBotUpdateHandler to edit the original message for login and activation requests instead of sending a new message, improving user experience by removing lingering buttons.
- Added null checks for callback messages to ensure robust handling of user interactions.
- Enhanced status messages to provide clearer feedback on user actions during the login and activation processes.
This commit is contained in:
Leonid Pershin
2026-07-13 04:38:06 +03:00
parent b6637a1c03
commit 48e8d06a41
@@ -187,10 +187,12 @@ public sealed class PnvBotUpdateHandler(
: await sender.Send(new RejectTelegramLoginCommand(requestId, fromId), cancellationToken);
await botClient.AnswerCallbackQuery(callback.Id, result.IsSuccess ? "Готово" : result.Error.Message, cancellationToken: cancellationToken);
if (result.IsSuccess)
if (result.IsSuccess && callback.Message is not null)
{
var text = parts[1] == "approve" ? "✅ Вход подтверждён." : "❌ Вход отклонён.";
await botClient.SendMessage(chatId.Value, text, cancellationToken: cancellationToken);
var statusText = parts[1] == "approve" ? "✅ Вход подтверждён." : "❌ Вход отклонён.";
var text = $"{Escape(callback.Message.Text ?? "")}\n\n{statusText}";
await botClient.EditMessageText(
chatId.Value, callback.Message.Id, text, parseMode: ParseMode.Html, cancellationToken: cancellationToken);
}
break;
@@ -208,10 +210,14 @@ public sealed class PnvBotUpdateHandler(
: await sender.Send(new RejectActivationCommand(requestId, Reason: null), cancellationToken);
await botClient.AnswerCallbackQuery(callback.Id, result.IsSuccess ? "Готово" : result.Error.Message, cancellationToken: cancellationToken);
if (result.IsSuccess)
if (result.IsSuccess && callback.Message is not null)
{
var text = parts[1] == "approve" ? "✅ Пользователь активирован." : "❌ Запрос отклонён.";
await botClient.SendMessage(chatId.Value, text, cancellationToken: cancellationToken);
// Редактируем исходное сообщение с запросом вместо отдельного — иначе кнопки
// «Активировать/Отклонить» остаются висеть под уже обработанным запросом.
var statusText = parts[1] == "approve" ? "✅ Пользователь активирован." : "❌ Запрос отклонён.";
var text = $"{Escape(callback.Message.Text ?? "")}\n\n{statusText}";
await botClient.EditMessageText(
chatId.Value, callback.Message.Id, text, parseMode: ParseMode.Html, cancellationToken: cancellationToken);
}
break;