8bcd16fbc9
PR Checks / test-and-build (pull_request) Successful in 12m35s
Introduce platform-neutral PlatformKind, PlatformUser, PlatformGroup, and IPlatformMessenger contracts in GmRelay.Shared. Route Telegram session schedule updates, direct notifications, interaction replies, and calendar export through TelegramPlatformMessenger while preserving existing Telegram behavior. Bump version -> 2.0.1
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using GmRelay.Bot.Infrastructure.Telegram;
|
|
using GmRelay.Shared.Platform;
|
|
|
|
namespace GmRelay.Bot.Features.Notifications;
|
|
|
|
public sealed record DirectNotificationRecipient(long TelegramId, string DisplayName);
|
|
|
|
public sealed class DirectSessionNotificationSender(
|
|
IPlatformMessenger messenger,
|
|
ILogger<DirectSessionNotificationSender> logger)
|
|
{
|
|
public async Task SendAsync(
|
|
IEnumerable<DirectNotificationRecipient> recipients,
|
|
string htmlText,
|
|
string notificationKind,
|
|
Guid sessionId,
|
|
CancellationToken ct)
|
|
{
|
|
foreach (var recipient in recipients)
|
|
{
|
|
try
|
|
{
|
|
await messenger.SendPrivateMessageAsync(
|
|
new PlatformPrivateMessage(
|
|
TelegramPlatformIds.User(recipient.TelegramId, recipient.DisplayName),
|
|
htmlText),
|
|
ct);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogWarning(
|
|
ex,
|
|
"Failed to send {NotificationKind} DM for session {SessionId} to player {TelegramId} ({DisplayName})",
|
|
notificationKind,
|
|
sessionId,
|
|
recipient.TelegramId,
|
|
recipient.DisplayName);
|
|
}
|
|
}
|
|
}
|
|
}
|