Files
hrynco-notification-service/HrynCo.NotificationService.Worker.Services/Push/PushChannelTestMessage.cs
T
agrynco aba4173827 feat(templates): add localized push templates and actions
Share template keys across email and push with independent editors and revisions. Render localized actions and preserve version-one delivery.

Ref: IT-1627
2026-10-31 09:38:05 +02:00

32 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using HrynCo.NotificationService.DAL.Abstract.Templates;
namespace HrynCo.NotificationService.Worker.Services.Push;
public sealed record PushChannelTestMessage
{
public required string Token { get; init; }
public int Version { get; init; } = 1;
public Guid? BindingId { get; init; }
public string? ActionKey { get; init; }
public string? ButtonLabel { get; init; }
public string? Validate()
{
if (!PushMessageValidator.IsSupportedVersion(Version)) return "Unsupported push payload version. Supported versions are 1 and 2.";
if (string.IsNullOrWhiteSpace(Token) || Token.Length > 4096 || Token.Any(char.IsWhiteSpace))
return "Enter a valid recipient FCM token.";
if (Version == 1) return null;
if (BindingId is null || BindingId == Guid.Empty) return "Enter the device's current binding ID for the button-format test.";
try
{
PushTemplateActionValidation.Validate(new PushTemplateActions
{
DefaultAction = ActionKey,
Buttons = [new PushTemplateButton { Action = ActionKey!, Label = ButtonLabel! }]
});
return null;
}
catch (EmailTemplateWriteException) { return "Enter a valid action key and a button label (1–100 characters)."; }
}
}