Enhance Telegram notification system with optional link support
- Updated NotifyUserAsync method in TelegramNotifier to accept an optional linkPath parameter for dynamic URL generation. - Modified various command handlers to utilize the new linkPath feature, providing users with relevant links in their notifications. - Adjusted ITelegramNotifier interface documentation to reflect the changes in method signature and functionality. - Enhanced unit tests to verify the correct invocation of the updated NotifyUserAsync method.
This commit is contained in:
@@ -228,6 +228,7 @@ internal sealed class TelegramNotifier(
|
||||
public async Task NotifyUserAsync(
|
||||
Guid userId,
|
||||
string message,
|
||||
string? linkPath,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
@@ -240,15 +241,14 @@ internal sealed class TelegramNotifier(
|
||||
|
||||
InlineKeyboardMarkup? keyboard = null;
|
||||
if (!string.IsNullOrWhiteSpace(options.Value.PublicSiteUrl))
|
||||
{
|
||||
var url = string.IsNullOrWhiteSpace(linkPath)
|
||||
? options.Value.PublicSiteUrl
|
||||
: $"{options.Value.PublicSiteUrl.TrimEnd('/')}{linkPath}";
|
||||
keyboard = new InlineKeyboardMarkup(
|
||||
new[]
|
||||
{
|
||||
InlineKeyboardButton.WithUrl(
|
||||
"🌐 Открыть на сайте",
|
||||
options.Value.PublicSiteUrl
|
||||
),
|
||||
}
|
||||
new[] { InlineKeyboardButton.WithUrl("🌐 Открыть на сайте", url) }
|
||||
);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -61,6 +61,7 @@ public sealed class ApproveActivationCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
request.UserId,
|
||||
"✅ Ваш аккаунт активирован администратором.",
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
return Result.Success();
|
||||
|
||||
@@ -82,6 +82,7 @@ public sealed class ApproveRoleRequestCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
ticket.UserId,
|
||||
"✅ Ваша заявка на роль одобрена.",
|
||||
$"/support?ticket={ticket.Id}",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public sealed class CloseTicketCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
ticket.UserId,
|
||||
"🔒 Ваше обращение закрыто.",
|
||||
$"/support?ticket={ticket.Id}",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ public sealed class RejectRoleRequestCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
ticket.UserId,
|
||||
"❌ Ваша заявка на роль отклонена.",
|
||||
$"/support?ticket={ticket.Id}",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public sealed class ResolveTicketCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
ticket.UserId,
|
||||
"✅ Ваше обращение решено.",
|
||||
$"/support?ticket={ticket.Id}",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ public sealed class BlockUserCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
command.UserId,
|
||||
"⛔ Ваш аккаунт заблокирован администратором.",
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ public sealed class DeleteUserCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
command.UserId,
|
||||
"🗑 Ваш аккаунт удалён администратором.",
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ public sealed class ForceRevokeConfigCommandHandler(
|
||||
await telegramNotifier.NotifyUserAsync(
|
||||
config.UserId,
|
||||
$"⚠️ Администратор отозвал ваш конфиг «{config.Label ?? config.ClientEmail}».",
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ public interface ITelegramNotifier
|
||||
);
|
||||
|
||||
/// <summary>Личное сообщение пользователю, если у него привязан Telegram (иначе no-op).
|
||||
/// Если задан PublicSiteUrl — добавляет кнопку-ссылку на сайт.</summary>
|
||||
Task NotifyUserAsync(Guid userId, string message, CancellationToken cancellationToken);
|
||||
/// Если задан PublicSiteUrl — добавляет кнопку-ссылку на сайт; linkPath — относительный путь
|
||||
/// (например "/support?ticket={id}"), на который она ведёт, null — на корень сайта.</summary>
|
||||
Task NotifyUserAsync(Guid userId, string message, string? linkPath, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Баг-репорт/предложение — только кнопка-ссылка на сайт (переписка и картинки — там),
|
||||
/// без инлайн-действий.</summary>
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class ApproveRoleRequestCommandHandlerTests
|
||||
.ChangeUserRoleAsync(userId, newRoleId, Arg.Any<CancellationToken>());
|
||||
await _telegramNotifier
|
||||
.Received(1)
|
||||
.NotifyUserAsync(userId, Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
.NotifyUserAsync(userId, Arg.Any<string>(), Arg.Any<string?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ public class DeleteUserCommandHandlerTests
|
||||
);
|
||||
await _telegramNotifier
|
||||
.Received(1)
|
||||
.NotifyUserAsync(userId, Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
.NotifyUserAsync(userId, Arg.Any<string>(), Arg.Any<string?>(), Arg.Any<CancellationToken>());
|
||||
await _identityService.Received(1).DeleteUserAsync(userId, Arg.Any<CancellationToken>());
|
||||
|
||||
var audit = Assert.Single(dbContext.AuditLogs.Local);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState } from 'react'
|
||||
import { getRouteApi } from '@tanstack/react-router'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/shared/ui/button'
|
||||
@@ -10,11 +11,13 @@ import { TicketStatusBadge } from './TicketStatusBadge'
|
||||
import { listMyTickets } from './api'
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
const routeApi = getRouteApi('/support')
|
||||
|
||||
export function SupportTicketList() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = routeApi.useNavigate()
|
||||
const { ticket: selectedTicketId } = routeApi.useSearch()
|
||||
const [page, setPage] = useState(1)
|
||||
const [selectedTicketId, setSelectedTicketId] = useState<string | null>(null)
|
||||
|
||||
const { data, isLoading, isError, refetch } = useQuery({
|
||||
queryKey: ['my-tickets', page],
|
||||
@@ -44,7 +47,7 @@ export function SupportTicketList() {
|
||||
{data && data.items.length > 0 && (
|
||||
<div className="flex flex-col gap-3">
|
||||
{data.items.map((ticket) => (
|
||||
<Card key={ticket.id} className="cursor-pointer" onClick={() => setSelectedTicketId(ticket.id)}>
|
||||
<Card key={ticket.id} className="cursor-pointer" onClick={() => navigate({ search: { ticket: ticket.id } })}>
|
||||
<CardHeader className="flex-row items-center justify-between gap-2">
|
||||
<CardTitle className="text-base">{t(`support.type.${ticket.type}`)}</CardTitle>
|
||||
<TicketStatusBadge status={ticket.status} />
|
||||
@@ -71,7 +74,7 @@ export function SupportTicketList() {
|
||||
)}
|
||||
|
||||
{selectedTicketId && (
|
||||
<TicketDetailDialog ticketId={selectedTicketId} onOpenChange={(open) => !open && setSelectedTicketId(null)} />
|
||||
<TicketDetailDialog ticketId={selectedTicketId} onOpenChange={(open) => !open && navigate({ search: {} })} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -3,7 +3,14 @@ import { useTranslation } from 'react-i18next'
|
||||
import { useRequireActivated } from '@/features/auth/guards'
|
||||
import { SupportTicketList } from '@/features/support/SupportTicketList'
|
||||
|
||||
export const Route = createFileRoute('/support')({ component: SupportPage })
|
||||
export const Route = createFileRoute('/support')({
|
||||
component: SupportPage,
|
||||
// Ссылка из Telegram-уведомления об изменении статуса тикета ведёт на этот же роут с
|
||||
// ?ticket=<id> — отдельного роута на конкретный тикет нет, он открывается диалогом поверх списка.
|
||||
validateSearch: (search: Record<string, unknown>): { ticket?: string } => ({
|
||||
ticket: typeof search.ticket === 'string' ? search.ticket : undefined,
|
||||
}),
|
||||
})
|
||||
|
||||
function SupportPage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
Reference in New Issue
Block a user