From 8c09c0cb5c8801bb9dac699315d9a2ffa4e177e6 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 9 Apr 2024 16:12:20 -0700 Subject: [PATCH] New: Option to prefix app name on Telegram notification titles (cherry picked from commit 37863a8deb339ef730b2dd5be61e1da1311fdd23) Closes #4739 --- src/NzbDrone.Core/Localization/Core/en.json | 2 + .../Notifications/Telegram/Telegram.cs | 40 ++++++++++++++----- .../Notifications/Telegram/TelegramService.cs | 3 +- .../Telegram/TelegramSettings.cs | 3 ++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index b7b6227d9..503e96643 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -798,6 +798,8 @@ "NotificationsSettingsUpdateMapPathsTo": "Map Paths To", "NotificationsSettingsUpdateMapPathsToHelpText": "{serviceName} path, used to modify series paths when {serviceName} sees library path location differently from {appName} (Requires 'Update Library')", "NotificationsSettingsUseSslHelpText": "Connect to {serviceName} over HTTPS instead of HTTP", + "NotificationsTelegramSettingsIncludeAppName": "Include {appName} in Title", + "NotificationsTelegramSettingsIncludeAppNameHelpText": "Optionally prefix message title with {appName} to differentiate notifications from different applications", "Ok": "Ok", "OnAlbumDelete": "On Album Delete", "OnApplicationUpdate": "On Application Update", diff --git a/src/NzbDrone.Core/Notifications/Telegram/Telegram.cs b/src/NzbDrone.Core/Notifications/Telegram/Telegram.cs index 96b0d4bb6..012694520 100644 --- a/src/NzbDrone.Core/Notifications/Telegram/Telegram.cs +++ b/src/NzbDrone.Core/Notifications/Telegram/Telegram.cs @@ -18,52 +18,72 @@ namespace NzbDrone.Core.Notifications.Telegram public override void OnGrab(GrabMessage grabMessage) { - _proxy.SendNotification(ALBUM_GRABBED_TITLE, grabMessage.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? ALBUM_GRABBED_TITLE_BRANDED : ALBUM_GRABBED_TITLE; + + _proxy.SendNotification(title, grabMessage.Message, Settings); } public override void OnReleaseImport(AlbumDownloadMessage message) { - _proxy.SendNotification(ALBUM_DOWNLOADED_TITLE, message.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? ALBUM_DOWNLOADED_TITLE_BRANDED : ALBUM_DOWNLOADED_TITLE; + + _proxy.SendNotification(title, message.Message, Settings); } public override void OnArtistAdd(ArtistAddMessage message) { - _proxy.SendNotification(ARTIST_ADDED_TITLE, message.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? ARTIST_ADDED_TITLE_BRANDED : ARTIST_ADDED_TITLE; + + _proxy.SendNotification(title, message.Message, Settings); } public override void OnArtistDelete(ArtistDeleteMessage deleteMessage) { - _proxy.SendNotification(ARTIST_DELETED_TITLE, deleteMessage.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? ARTIST_DELETED_TITLE_BRANDED : ARTIST_DELETED_TITLE; + + _proxy.SendNotification(title, deleteMessage.Message, Settings); } public override void OnAlbumDelete(AlbumDeleteMessage deleteMessage) { - _proxy.SendNotification(ALBUM_DELETED_TITLE, deleteMessage.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? ALBUM_DELETED_TITLE_BRANDED : ALBUM_DELETED_TITLE; + + _proxy.SendNotification(title, deleteMessage.Message, Settings); } public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) { - _proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? HEALTH_ISSUE_TITLE_BRANDED : HEALTH_ISSUE_TITLE; + + _proxy.SendNotification(title, healthCheck.Message, Settings); } public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck) { - _proxy.SendNotification(HEALTH_RESTORED_TITLE, $"The following issue is now resolved: {previousCheck.Message}", Settings); + var title = Settings.IncludeAppNameInTitle ? HEALTH_RESTORED_TITLE_BRANDED : HEALTH_RESTORED_TITLE; + + _proxy.SendNotification(title, $"The following issue is now resolved: {previousCheck.Message}", Settings); } public override void OnDownloadFailure(DownloadFailedMessage message) { - _proxy.SendNotification(DOWNLOAD_FAILURE_TITLE, message.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? DOWNLOAD_FAILURE_TITLE_BRANDED : DOWNLOAD_FAILURE_TITLE; + + _proxy.SendNotification(title, message.Message, Settings); } public override void OnImportFailure(AlbumDownloadMessage message) { - _proxy.SendNotification(IMPORT_FAILURE_TITLE, message.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? IMPORT_FAILURE_TITLE_BRANDED : IMPORT_FAILURE_TITLE; + + _proxy.SendNotification(title, message.Message, Settings); } public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) { - _proxy.SendNotification(APPLICATION_UPDATE_TITLE, updateMessage.Message, Settings); + var title = Settings.IncludeAppNameInTitle ? APPLICATION_UPDATE_TITLE_BRANDED : APPLICATION_UPDATE_TITLE; + + _proxy.SendNotification(title, updateMessage.Message, Settings); } public override ValidationResult Test() diff --git a/src/NzbDrone.Core/Notifications/Telegram/TelegramService.cs b/src/NzbDrone.Core/Notifications/Telegram/TelegramService.cs index 9bd2fd7d7..d261a77ad 100644 --- a/src/NzbDrone.Core/Notifications/Telegram/TelegramService.cs +++ b/src/NzbDrone.Core/Notifications/Telegram/TelegramService.cs @@ -49,10 +49,11 @@ namespace NzbDrone.Core.Notifications.Telegram { try { + const string brandedTitle = "Lidarr - Test Notification"; const string title = "Test Notification"; const string body = "This is a test message from Lidarr"; - SendNotification(title, body, settings); + SendNotification(settings.IncludeAppNameInTitle ? brandedTitle : title, body, settings); } catch (Exception ex) { diff --git a/src/NzbDrone.Core/Notifications/Telegram/TelegramSettings.cs b/src/NzbDrone.Core/Notifications/Telegram/TelegramSettings.cs index 774fd4ca0..4ff40ae93 100644 --- a/src/NzbDrone.Core/Notifications/Telegram/TelegramSettings.cs +++ b/src/NzbDrone.Core/Notifications/Telegram/TelegramSettings.cs @@ -32,6 +32,9 @@ namespace NzbDrone.Core.Notifications.Telegram [FieldDefinition(3, Label = "Send Silently", Type = FieldType.Checkbox, HelpText = "Sends the message silently. Users will receive a notification with no sound")] public bool SendSilently { get; set; } + [FieldDefinition(4, Label = "NotificationsTelegramSettingsIncludeAppName", Type = FieldType.Checkbox, HelpText = "NotificationsTelegramSettingsIncludeAppNameHelpText")] + public bool IncludeAppNameInTitle { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this));