60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
namespace ROLAC.API.Services.Notifications;
|
|
|
|
/// <summary>Canonical channel discriminators stored in NotificationLog.Channel.</summary>
|
|
public static class NotificationChannels
|
|
{
|
|
public const string Email = "email";
|
|
public const string Line = "line";
|
|
}
|
|
|
|
/// <summary>Canonical target-type discriminators stored in NotificationLog.TargetType.</summary>
|
|
public static class NotificationTargetTypes
|
|
{
|
|
public const string Email = "email";
|
|
public const string User = "user";
|
|
public const string Group = "group";
|
|
}
|
|
|
|
/// <summary>Canonical send statuses stored in NotificationLog.Status.</summary>
|
|
public static class NotificationStatuses
|
|
{
|
|
public const string Sent = "sent";
|
|
public const string Failed = "failed";
|
|
}
|
|
|
|
/// <summary>One failed delivery within a send batch.</summary>
|
|
public sealed record NotificationFailure(string Target, string Error);
|
|
|
|
/// <summary>Aggregated outcome of a send call.</summary>
|
|
public sealed record NotificationResult(
|
|
int SentCount, int FailedCount, IReadOnlyList<NotificationFailure> Failures)
|
|
{
|
|
public static NotificationResult Empty { get; } =
|
|
new(0, 0, Array.Empty<NotificationFailure>());
|
|
}
|
|
|
|
/// <summary>A file attached to an outbound email.</summary>
|
|
public sealed record EmailAttachment(string FileName, string ContentType, byte[] Content);
|
|
|
|
/// <summary>
|
|
/// A request to send one email to a set of members (resolved via Member.Email) and/or raw
|
|
/// addresses. The caller supplies the final HTML body — no templating in this phase.
|
|
/// </summary>
|
|
public sealed record EmailMessage(
|
|
IReadOnlyList<int> MemberIds,
|
|
IReadOnlyList<string> Addresses,
|
|
string Subject,
|
|
string HtmlBody,
|
|
IReadOnlyList<EmailAttachment>? Attachments = null,
|
|
string? SentByUserId = null);
|
|
|
|
/// <summary>Helpers for building NotificationLog rows consistently across channels.</summary>
|
|
public static class NotificationLogText
|
|
{
|
|
public const int BodyMaxLength = 8000;
|
|
|
|
/// <summary>Caps a body string so an oversized message can't bloat the log table.</summary>
|
|
public static string Truncate(string body) =>
|
|
body.Length <= BodyMaxLength ? body : body[..BodyMaxLength] + "…[truncated]";
|
|
}
|