Add notification for ticket reopening to Telegram admins
CI / Backend (build + test) (push) Successful in 1m13s
CI / Frontend (lint + typecheck + build) (push) Successful in 31s

- Implemented NotifyAdminsTicketReopenedAsync method in TelegramNotifier to notify admins when a ticket is reopened, including a link to the ticket on the public site.
- Updated ITelegramNotifier interface to include the new notification method.
- Modified ReopenTicketCommandHandler to invoke the new notification method after a ticket is reopened.
- Enhanced unit tests for ReopenTicketCommandHandler to verify the notification functionality.
This commit is contained in:
Leonid Pershin
2026-07-14 07:22:21 +03:00
parent a833d9aa5b
commit 9d5424bb9c
4 changed files with 50 additions and 4 deletions
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Options;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Domain.Support;
using PnvPanel.Infrastructure.Telegram;
using Telegram.Bot;
using Telegram.Bot.Types.Enums;
@@ -97,6 +98,35 @@ internal sealed class TelegramNotifier(ITelegramBotClient botClient, IIdentitySe
}
}
public async Task NotifyAdminsTicketReopenedAsync(Guid ticketId, string userName, TicketType type, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(options.Value.BotToken))
return;
var typeLabel = type == TicketType.RoleRequest ? "заявка на роль" : "баг/предложение";
var text = $"🔓 Тикет от <b>{Escape(userName)}</b> переоткрыт ({typeLabel})";
InlineKeyboardMarkup? keyboard = null;
if (!string.IsNullOrWhiteSpace(options.Value.PublicSiteUrl))
{
var url = $"{options.Value.PublicSiteUrl.TrimEnd('/')}/admin/support?ticket={ticketId}";
keyboard = new InlineKeyboardMarkup(new[] { InlineKeyboardButton.WithUrl("🌐 Открыть на сайте", url) });
}
foreach (var adminId in options.Value.ParseAdminTelegramUserIds())
{
try
{
await botClient.SendMessage(
adminId, text, parseMode: ParseMode.Html, replyMarkup: keyboard, cancellationToken: cancellationToken);
}
catch
{
// Админ мог не запускать бота (нет чата с ботом) — пропускаем, не валим команду.
}
}
}
public async Task NotifyUsersNewsPublishedAsync(string title, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(options.Value.BotToken))