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
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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)."; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user