Add Telegram notification for news publication to users
CI / Backend (build + test) (push) Successful in 3m0s
CI / Frontend (lint + typecheck + build) (push) Successful in 31s

- Implemented NotifyUsersNewsPublishedAsync method in TelegramNotifier to send notifications to activated Telegram users when a news post is published.
- Updated CreatePostCommandHandler to invoke the new Telegram notification method after creating a news post.
- Enhanced IIdentityService to retrieve activated linked Telegram user IDs for notifications.
- Updated ITelegramNotifier interface to include the new notification method documentation.
This commit is contained in:
Leonid Pershin
2026-07-14 07:19:19 +03:00
parent 6bd34441fb
commit a833d9aa5b
5 changed files with 47 additions and 1 deletions
@@ -6,7 +6,7 @@ using PnvPanel.Domain.News;
namespace PnvPanel.Application.Admin.News;
public sealed class CreatePostCommandHandler(IAppDbContext dbContext, IRealtimeNotifier notifier)
public sealed class CreatePostCommandHandler(IAppDbContext dbContext, IRealtimeNotifier notifier, ITelegramNotifier telegramNotifier)
: ICommandHandler<CreatePostCommand, Result<NewsPostDto>>
{
public async Task<Result<NewsPostDto>> Handle(CreatePostCommand command, CancellationToken cancellationToken)
@@ -15,6 +15,7 @@ public sealed class CreatePostCommandHandler(IAppDbContext dbContext, IRealtimeN
dbContext.NewsPosts.Add(post);
await notifier.NotifyNewsPublishedAsync(post.Id, post.Title, post.CreatedAt, cancellationToken);
await telegramNotifier.NotifyUsersNewsPublishedAsync(post.Title, cancellationToken);
return Result.Success(NewsPostDto.FromDomain(post));
}
@@ -60,4 +60,8 @@ public interface IIdentityService
Task<Guid?> FindUserIdByTelegramUserIdAsync(long telegramUserId, CancellationToken cancellationToken);
Task<TelegramLinkInfo> GetTelegramLinkInfoAsync(Guid userId, CancellationToken cancellationToken);
/// <summary>Telegram ID активных (активированных, не заблокированных) пользователей с привязкой —
/// для рассылки уведомлений вроде публикации новости.</summary>
Task<IReadOnlyCollection<long>> GetActivatedLinkedTelegramUserIdsAsync(CancellationToken cancellationToken);
}
@@ -21,4 +21,8 @@ public interface ITelegramNotifier
/// <summary>Заявка на роль — инлайн-кнопки «Одобрить/Отклонить», решается полностью в Telegram.</summary>
Task NotifyAdminsRoleRequestCreatedAsync(
Guid ticketId, string userName, string roleDescription, string justification, CancellationToken cancellationToken);
/// <summary>Рассылка о публикации новости всем активированным пользователям с привязанным Telegram
/// (кнопка-ссылка на сайт, где новость показана целиком).</summary>
Task NotifyUsersNewsPublishedAsync(string title, CancellationToken cancellationToken);
}