1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-21 23:42:23 +00:00

New: Optionally as Instance Name to Telegram notifications

(cherry picked from commit 36633b5d08c19158f185c0fa5faabbaec607fcb5)

Closes #10757
This commit is contained in:
Stevie Robinson 2024-12-09 04:37:51 +01:00 committed by Bogdan
parent 8c6ba9a543
commit b2b5aa1f79
4 changed files with 33 additions and 9 deletions

View file

@ -1234,6 +1234,8 @@
"NotificationsTelegramSettingsChatIdHelpText": "You must start a conversation with the bot or add it to your group to receive messages",
"NotificationsTelegramSettingsIncludeAppName": "Include {appName} in Title",
"NotificationsTelegramSettingsIncludeAppNameHelpText": "Optionally prefix message title with {appName} to differentiate notifications from different applications",
"NotificationsTelegramSettingsIncludeInstanceName": "Include Instance Name in Title",
"NotificationsTelegramSettingsIncludeInstanceNameHelpText": "Optionally include Instance name in notification",
"NotificationsTelegramSettingsSendSilently": "Send Silently",
"NotificationsTelegramSettingsSendSilentlyHelpText": "Sends the message silently. Users will receive a notification with no sound",
"NotificationsTelegramSettingsTopicId": "Topic ID",

View file

@ -2,6 +2,7 @@
using System.Linq;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.Notifications.Telegram
@ -9,41 +10,48 @@ namespace NzbDrone.Core.Notifications.Telegram
public class Telegram : NotificationBase<TelegramSettings>
{
private readonly ITelegramProxy _proxy;
private readonly IConfigFileProvider _configFileProvider;
public Telegram(ITelegramProxy proxy)
public Telegram(ITelegramProxy proxy, IConfigFileProvider configFileProvider)
{
_proxy = proxy;
_configFileProvider = configFileProvider;
}
public override string Name => "Telegram";
public override string Link => "https://telegram.org/";
private string InstanceName => _configFileProvider.InstanceName;
public override void OnGrab(GrabMessage grabMessage)
{
var title = Settings.IncludeAppNameInTitle ? MOVIE_GRABBED_TITLE_BRANDED : MOVIE_GRABBED_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, grabMessage.Message, Settings);
}
public override void OnDownload(DownloadMessage message)
{
string title;
if (message.OldMovieFiles.Any())
{
var title = Settings.IncludeAppNameInTitle ? MOVIE_UPGRADED_TITLE_BRANDED : MOVIE_UPGRADED_TITLE;
_proxy.SendNotification(title, message.Message, Settings);
title = Settings.IncludeAppNameInTitle ? MOVIE_UPGRADED_TITLE_BRANDED : MOVIE_UPGRADED_TITLE;
}
else
{
var title = Settings.IncludeAppNameInTitle ? MOVIE_DOWNLOADED_TITLE_BRANDED : MOVIE_DOWNLOADED_TITLE;
_proxy.SendNotification(title, message.Message, Settings);
title = Settings.IncludeAppNameInTitle ? MOVIE_DOWNLOADED_TITLE_BRANDED : MOVIE_DOWNLOADED_TITLE;
}
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, message.Message, Settings);
}
public override void OnMovieAdded(Movie movie)
{
var title = Settings.IncludeAppNameInTitle ? MOVIE_ADDED_TITLE_BRANDED : MOVIE_ADDED_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, $"{movie.Title} added to library", Settings);
}
@ -51,6 +59,7 @@ public override void OnMovieAdded(Movie movie)
public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage)
{
var title = Settings.IncludeAppNameInTitle ? MOVIE_FILE_DELETED_TITLE_BRANDED : MOVIE_FILE_DELETED_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, deleteMessage.Message, Settings);
}
@ -58,6 +67,7 @@ public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage)
public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
{
var title = Settings.IncludeAppNameInTitle ? MOVIE_DELETED_TITLE_BRANDED : MOVIE_DELETED_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, deleteMessage.Message, Settings);
}
@ -65,6 +75,7 @@ public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
var title = Settings.IncludeAppNameInTitle ? HEALTH_ISSUE_TITLE_BRANDED : HEALTH_ISSUE_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, healthCheck.Message, Settings);
}
@ -72,6 +83,7 @@ public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
{
var title = Settings.IncludeAppNameInTitle ? HEALTH_RESTORED_TITLE_BRANDED : HEALTH_RESTORED_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, $"The following issue is now resolved: {previousCheck.Message}", Settings);
}
@ -79,6 +91,7 @@ public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
var title = Settings.IncludeAppNameInTitle ? APPLICATION_UPDATE_TITLE_BRANDED : APPLICATION_UPDATE_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, updateMessage.Message, Settings);
}
@ -86,6 +99,7 @@ public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
public override void OnManualInteractionRequired(ManualInteractionRequiredMessage message)
{
var title = Settings.IncludeAppNameInTitle ? MANUAL_INTERACTION_REQUIRED_TITLE_BRANDED : MANUAL_INTERACTION_REQUIRED_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, message.Message, Settings);
}

View file

@ -7,6 +7,7 @@
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Localization;
namespace NzbDrone.Core.Notifications.Telegram
@ -21,12 +22,14 @@ public class TelegramProxy : ITelegramProxy
{
private const string URL = "https://api.telegram.org";
private readonly IHttpClient _httpClient;
private readonly IConfigFileProvider _configFileProvider;
private readonly ILocalizationService _localizationService;
private readonly Logger _logger;
public TelegramProxy(IHttpClient httpClient, ILocalizationService localizationService, Logger logger)
public TelegramProxy(IHttpClient httpClient, IConfigFileProvider configFileProvider, ILocalizationService localizationService, Logger logger)
{
_httpClient = httpClient;
_configFileProvider = configFileProvider;
_localizationService = localizationService;
_logger = logger;
}
@ -57,7 +60,9 @@ public ValidationFailure Test(TelegramSettings settings)
const string title = "Test Notification";
const string body = "This is a test message from Radarr";
SendNotification(settings.IncludeAppNameInTitle ? brandedTitle : title, body, settings);
var testMessageTitle = settings.IncludeAppNameInTitle ? brandedTitle : title;
testMessageTitle = settings.IncludeInstanceNameInTitle ? $"{testMessageTitle} - {_configFileProvider.InstanceName}" : testMessageTitle;
SendNotification(testMessageTitle, body, settings);
}
catch (Exception ex)
{

View file

@ -34,6 +34,9 @@ public class TelegramSettings : NotificationSettingsBase<TelegramSettings>
[FieldDefinition(4, Label = "NotificationsTelegramSettingsIncludeAppName", Type = FieldType.Checkbox, HelpText = "NotificationsTelegramSettingsIncludeAppNameHelpText")]
public bool IncludeAppNameInTitle { get; set; }
[FieldDefinition(5, Label = "NotificationsTelegramSettingsIncludeInstanceName", Type = FieldType.Checkbox, HelpText = "NotificationsTelegramSettingsIncludeInstanceNameHelpText", Advanced = true)]
public bool IncludeInstanceNameInTitle { get; set; }
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));