New: add TTL setting for pushover notifications

(cherry picked from commit 317cdf15582746bd4e713d6b99e17a21dcb8abeb)
This commit is contained in:
Stevie Robinson 2025-11-12 20:14:09 +01:00 committed by Auggie
parent 1b9662d588
commit 949922b9a1
3 changed files with 13 additions and 2 deletions

View file

@ -1340,11 +1340,13 @@
"NotificationsPushoverSettingsDevices": "Devices", "NotificationsPushoverSettingsDevices": "Devices",
"NotificationsPushoverSettingsDevicesHelpText": "List of device names (leave blank to send to all devices)", "NotificationsPushoverSettingsDevicesHelpText": "List of device names (leave blank to send to all devices)",
"NotificationsPushoverSettingsExpire": "Expire", "NotificationsPushoverSettingsExpire": "Expire",
"NotificationsPushoverSettingsExpireHelpText": "Maximum time to retry Emergency alerts, maximum 86400 seconds\"", "NotificationsPushoverSettingsExpireHelpText": "Maximum time to retry Emergency alerts, maximum 86400 seconds",
"NotificationsPushoverSettingsRetry": "Retry", "NotificationsPushoverSettingsRetry": "Retry",
"NotificationsPushoverSettingsRetryHelpText": "Interval to retry Emergency alerts, minimum 30 seconds", "NotificationsPushoverSettingsRetryHelpText": "Interval to retry Emergency alerts, minimum 30 seconds",
"NotificationsPushoverSettingsSound": "Sound", "NotificationsPushoverSettingsSound": "Sound",
"NotificationsPushoverSettingsSoundHelpText": "Notification sound, leave blank to use the default", "NotificationsPushoverSettingsSoundHelpText": "Notification sound, leave blank to use the default",
"NotificationsPushoverSettingsTtl": "Time To Live",
"NotificationsPushoverSettingsTtlHelpText": "Time in seconds before the message expires. Set to 0 for unlimited duration",
"NotificationsPushoverSettingsUserKey": "User Key", "NotificationsPushoverSettingsUserKey": "User Key",
"NotificationsSendGridSettingsApiKeyHelpText": "The API Key generated by SendGrid", "NotificationsSendGridSettingsApiKeyHelpText": "The API Key generated by SendGrid",
"NotificationsSettingsUpdateLibrary": "Update Library", "NotificationsSettingsUpdateLibrary": "Update Library",

View file

@ -45,6 +45,11 @@ public void SendNotification(string title, string message, PushoverSettings sett
requestBuilder.AddFormParameter("expire", settings.Expire); requestBuilder.AddFormParameter("expire", settings.Expire);
} }
if (settings.Ttl > 0)
{
requestBuilder.AddFormParameter("ttl", settings.Ttl);
}
if (!settings.Sound.IsNullOrWhiteSpace()) if (!settings.Sound.IsNullOrWhiteSpace())
{ {
requestBuilder.AddFormParameter("sound", settings.Sound); requestBuilder.AddFormParameter("sound", settings.Sound);

View file

@ -13,6 +13,7 @@ public PushoverSettingsValidator()
RuleFor(c => c.UserKey).NotEmpty(); RuleFor(c => c.UserKey).NotEmpty();
RuleFor(c => c.Retry).GreaterThanOrEqualTo(30).LessThanOrEqualTo(86400).When(c => (PushoverPriority)c.Priority == PushoverPriority.Emergency); RuleFor(c => c.Retry).GreaterThanOrEqualTo(30).LessThanOrEqualTo(86400).When(c => (PushoverPriority)c.Priority == PushoverPriority.Emergency);
RuleFor(c => c.Retry).GreaterThanOrEqualTo(0).LessThanOrEqualTo(86400).When(c => (PushoverPriority)c.Priority == PushoverPriority.Emergency); RuleFor(c => c.Retry).GreaterThanOrEqualTo(0).LessThanOrEqualTo(86400).When(c => (PushoverPriority)c.Priority == PushoverPriority.Emergency);
RuleFor(c => c.Ttl).GreaterThanOrEqualTo(0);
} }
} }
@ -44,7 +45,10 @@ public PushoverSettings()
[FieldDefinition(5, Label = "NotificationsPushoverSettingsExpire", Type = FieldType.Textbox, HelpText = "NotificationsPushoverSettingsExpireHelpText")] [FieldDefinition(5, Label = "NotificationsPushoverSettingsExpire", Type = FieldType.Textbox, HelpText = "NotificationsPushoverSettingsExpireHelpText")]
public int Expire { get; set; } public int Expire { get; set; }
[FieldDefinition(6, Label = "NotificationsPushoverSettingsSound", Type = FieldType.Textbox, HelpText = "NotificationsPushoverSettingsSoundHelpText", HelpLink = "https://pushover.net/api#sounds")] [FieldDefinition(6, Label = "NotificationsPushoverSettingsTtl", Type = FieldType.Textbox, HelpText = "NotificationsPushoverSettingsTtlHelpText", Advanced = true)]
public int Ttl { get; set; }
[FieldDefinition(7, Label = "NotificationsPushoverSettingsSound", Type = FieldType.Textbox, HelpText = "NotificationsPushoverSettingsSoundHelpText", HelpLink = "https://pushover.net/api#sounds")]
public string Sound { get; set; } public string Sound { get; set; }
public bool IsValid => !string.IsNullOrWhiteSpace(UserKey) && Priority >= -1 && Priority <= 2; public bool IsValid => !string.IsNullOrWhiteSpace(UserKey) && Priority >= -1 && Priority <= 2;