Added the request queue to the notifications UI so you can turn it off per notification agent #2747

This commit is contained in:
TidusJar 2019-01-21 13:16:35 +00:00
parent 47f3240c73
commit f1bca13586
9 changed files with 169 additions and 661 deletions

View file

@ -56,148 +56,42 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task NewRequest(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.NewRequest, model); await Run(model, settings, NotificationType.NewRequest);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task NewIssue(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task NewIssue(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.Issue, model); await Run(model, settings, NotificationType.Issue);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task IssueComment(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task IssueComment(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.IssueComment, model); await Run(model, settings, NotificationType.IssueComment);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueComment} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task IssueResolved(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.IssueResolved, model); await Run(model, settings, NotificationType.IssueResolved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task AddedToRequestQueue(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var user = string.Empty; await Run(model, settings, NotificationType.ItemAddedToFaultQueue);
var title = string.Empty;
var image = string.Empty;
if (model.RequestType == RequestType.Movie)
{
user = MovieRequest.RequestedUser.UserAlias;
title = MovieRequest.Title;
image = MovieRequest.PosterPath;
}
else if (model.RequestType == RequestType.TvShow)
{
user = TvRequest.RequestedUser.UserAlias;
title = TvRequest.ParentRequest.Title;
image = TvRequest.ParentRequest.PosterPath;
}
else if (model.RequestType == RequestType.Album)
{
user = AlbumRequest.RequestedUser.UserAlias;
title = AlbumRequest.Title;
image = AlbumRequest.Cover;
}
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
var notification = new NotificationMessage
{
Message = message
};
notification.Other.Add("image", image);
await Send(notification, settings);
} }
protected override async Task RequestDeclined(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task RequestDeclined(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestDeclined, model); await Run(model, settings, NotificationType.RequestDeclined);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task RequestApproved(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task RequestApproved(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestApproved, model); await Run(model, settings, NotificationType.RequestApproved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task AvailableRequest(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task AvailableRequest(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestAvailable, model); await Run(model, settings, NotificationType.RequestAvailable);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task Send(NotificationMessage model, DiscordNotificationSettings settings) protected override async Task Send(NotificationMessage model, DiscordNotificationSettings settings)
@ -242,5 +136,21 @@ namespace Ombi.Notifications.Agents
}; };
await Send(notification, settings); await Send(notification, settings);
} }
private async Task Run(NotificationOptions model, DiscordNotificationSettings settings, NotificationType type)
{
var parsed = await LoadTemplate(NotificationAgent.Discord, type, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
}
} }
} }

View file

@ -89,7 +89,6 @@ namespace Ombi.Notifications.Agents
} }
else else
{ {
// Send to admin // Send to admin
message.To = settings.AdminEmail; message.To = settings.AdminEmail;
} }
@ -183,37 +182,21 @@ namespace Ombi.Notifications.Agents
protected override async Task AddedToRequestQueue(NotificationOptions model, EmailNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, EmailNotificationSettings settings)
{ {
var email = new EmailBasicTemplate(); if (!model.Recipient.HasValue())
var user = string.Empty;
var title = string.Empty;
var img = string.Empty;
if (model.RequestType == RequestType.Movie)
{ {
user = MovieRequest.RequestedUser.UserAlias; return;
title = MovieRequest.Title;
img = $"https://image.tmdb.org/t/p/w300/{MovieRequest.PosterPath}";
} }
else var message = await LoadTemplate(NotificationType.ItemAddedToFaultQueue, model, settings);
if (message == null)
{ {
user = TvRequest.RequestedUser.UserAlias; return;
title = TvRequest.ParentRequest.Title;
img = TvRequest.ParentRequest.PosterPath;
} }
var html = email.LoadTemplate( var plaintext = await LoadPlainTextMessage(NotificationType.ItemAddedToFaultQueue, model, settings);
$"{Customization.ApplicationName}: A request could not be added.",
$"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying", img, Customization.Logo);
var message = new NotificationMessage
{
Message = html,
Subject = $"{Customization.ApplicationName}: A request could not be added",
To = settings.AdminEmail,
};
var plaintext = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
message.Other.Add("PlainTextBody", plaintext); message.Other.Add("PlainTextBody", plaintext);
// Issues resolved should be sent to the user
message.To = settings.AdminEmail;
await Send(message, settings); await Send(message, settings);
} }

View file

@ -46,20 +46,7 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task NewRequest(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.NewRequest, model); await Run(model, settings, NotificationType.NewRequest);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
//notification.Other.Add("overview", model.RequestType == RequestType.Movie ? base.MovieRequest.Overview : TvRequest.);
await Send(notification, settings);
} }
private void AddOtherInformation(NotificationOptions model, NotificationMessage notification, private void AddOtherInformation(NotificationOptions model, NotificationMessage notification,
@ -71,125 +58,37 @@ namespace Ombi.Notifications.Agents
protected override async Task NewIssue(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task NewIssue(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.Issue, model); await Run(model, settings, NotificationType.Issue);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
await Send(notification, settings);
} }
protected override async Task IssueComment(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task IssueComment(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.IssueComment, model); await Run(model, settings, NotificationType.IssueComment);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueComment} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task IssueResolved(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.IssueResolved, model); await Run(model, settings, NotificationType.IssueResolved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
await Send(notification, settings);
} }
protected override async Task AddedToRequestQueue(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var user = string.Empty; await Run(model, settings, NotificationType.ItemAddedToFaultQueue);
var title = string.Empty;
var image = string.Empty;
if (model.RequestType == RequestType.Movie)
{
user = MovieRequest.RequestedUser.UserAlias;
title = MovieRequest.Title;
image = MovieRequest.PosterPath;
}
else
{
user = TvRequest.RequestedUser.UserAlias;
title = TvRequest.ParentRequest.Title;
image = TvRequest.ParentRequest.PosterPath;
}
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
var notification = new NotificationMessage
{
Message = message
};
notification.Other.Add("image", image);
await Send(notification, settings);
} }
protected override async Task RequestDeclined(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task RequestDeclined(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.RequestDeclined, model); await Run(model, settings, NotificationType.RequestDeclined);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
await Send(notification, settings);
} }
protected override async Task RequestApproved(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task RequestApproved(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.RequestApproved, model); await Run(model, settings, NotificationType.RequestApproved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
await Send(notification, settings);
} }
protected override async Task AvailableRequest(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task AvailableRequest(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.RequestAvailable, model); await Run(model, settings, NotificationType.RequestAvailable);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
await Send(notification, settings);
} }
protected override async Task Send(NotificationMessage model, MattermostNotificationSettings settings) protected override async Task Send(NotificationMessage model, MattermostNotificationSettings settings)
@ -228,5 +127,21 @@ namespace Ombi.Notifications.Agents
}; };
await Send(notification, settings); await Send(notification, settings);
} }
private async Task Run(NotificationOptions model, MattermostNotificationSettings settings, NotificationType type)
{
var parsed = await LoadTemplate(NotificationAgent.Mattermost, type, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
AddOtherInformation(model, notification, parsed);
await Send(notification, settings);
}
} }
} }

View file

@ -130,23 +130,18 @@ namespace Ombi.Notifications.Agents
protected override async Task AddedToRequestQueue(NotificationOptions model, MobileNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, MobileNotificationSettings settings)
{ {
string user;
string title; var parsed = await LoadTemplate(NotificationAgent.Mobile, NotificationType.ItemAddedToFaultQueue, model);
if (model.RequestType == RequestType.Movie) if (parsed.Disabled)
{ {
user = MovieRequest.RequestedUser.UserAlias; _logger.LogInformation($"Template {NotificationType.ItemAddedToFaultQueue} is disabled for {NotificationAgent.Mobile}");
title = MovieRequest.Title; return;
} }
else
{
user = TvRequest.RequestedUser.UserAlias;
title = TvRequest.ParentRequest.Title;
}
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
var notification = new NotificationMessage var notification = new NotificationMessage
{ {
Message = message Message = parsed.Message,
}; };
// Get admin devices // Get admin devices
var playerIds = await GetAdmins(NotificationType.Test); var playerIds = await GetAdmins(NotificationType.Test);
await Send(playerIds, notification, settings, model); await Send(playerIds, notification, settings, model);
@ -294,6 +289,5 @@ namespace Ombi.Notifications.Agents
} }
} }
} }
} }
} }

View file

@ -44,131 +44,43 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, PushbulletSettings settings) protected override async Task NewRequest(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.NewRequest, model); await Run(model, settings, NotificationType.NewRequest);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task NewIssue(NotificationOptions model, PushbulletSettings settings) protected override async Task NewIssue(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.Issue, model); await Run(model, settings, NotificationType.Issue);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task IssueComment(NotificationOptions model, PushbulletSettings settings) protected override async Task IssueComment(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.IssueComment, model); await Run(model, settings, NotificationType.IssueComment);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueComment} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, PushbulletSettings settings) protected override async Task IssueResolved(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.IssueResolved, model); await Run(model, settings, NotificationType.IssueResolved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task AddedToRequestQueue(NotificationOptions model, PushbulletSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, PushbulletSettings settings)
{ {
string user; await Run(model, settings, NotificationType.ItemAddedToFaultQueue);
string title;
if (model.RequestType == RequestType.Movie)
{
user = MovieRequest.RequestedUser.UserAlias;
title = MovieRequest.Title;
}
else
{
user = TvRequest.RequestedUser.UserAlias;
title = TvRequest.ParentRequest.Title;
}
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
var notification = new NotificationMessage
{
Message = message
};
await Send(notification, settings);
} }
protected override async Task RequestDeclined(NotificationOptions model, PushbulletSettings settings) protected override async Task RequestDeclined(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.RequestDeclined, model); await Run(model, settings, NotificationType.RequestDeclined);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task RequestApproved(NotificationOptions model, PushbulletSettings settings) protected override async Task RequestApproved(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.RequestApproved, model); await Run(model, settings, NotificationType.RequestApproved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task AvailableRequest(NotificationOptions model, PushbulletSettings settings) protected override async Task AvailableRequest(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.RequestAvailable, model); await Run(model, settings, NotificationType.RequestAvailable);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task Send(NotificationMessage model, PushbulletSettings settings) protected override async Task Send(NotificationMessage model, PushbulletSettings settings)
@ -192,5 +104,22 @@ namespace Ombi.Notifications.Agents
}; };
await Send(notification, settings); await Send(notification, settings);
} }
private async Task Run(NotificationOptions model, PushbulletSettings settings, NotificationType type)
{
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, type, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
}
} }
} }

View file

@ -45,132 +45,42 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, PushoverSettings settings) protected override async Task NewRequest(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.NewRequest, model); await Run(model, settings, NotificationType.NewRequest);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task NewIssue(NotificationOptions model, PushoverSettings settings) protected override async Task NewIssue(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.Issue, model); await Run(model, settings, NotificationType.Issue);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task IssueComment(NotificationOptions model, PushoverSettings settings) protected override async Task IssueComment(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.IssueComment, model); await Run(model, settings, NotificationType.IssueComment);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueComment} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, PushoverSettings settings) protected override async Task IssueResolved(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.IssueResolved, model); await Run(model, settings, NotificationType.IssueResolved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task AddedToRequestQueue(NotificationOptions model, PushoverSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, PushoverSettings settings)
{ {
string user; await Run(model, settings, NotificationType.ItemAddedToFaultQueue);
string title;
if (model.RequestType == RequestType.Movie)
{
user = MovieRequest.RequestedUser.UserAlias;
title = MovieRequest.Title;
}
else
{
user = TvRequest.RequestedUser.UserAlias;
title = TvRequest.ParentRequest.Title;
}
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
var notification = new NotificationMessage
{
Message = message
};
await Send(notification, settings);
} }
protected override async Task RequestDeclined(NotificationOptions model, PushoverSettings settings) protected override async Task RequestDeclined(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.RequestDeclined, model); await Run(model, settings, NotificationType.RequestDeclined);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task RequestApproved(NotificationOptions model, PushoverSettings settings) protected override async Task RequestApproved(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.RequestApproved, model); await Run(model, settings, NotificationType.RequestApproved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task AvailableRequest(NotificationOptions model, PushoverSettings settings) protected override async Task AvailableRequest(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.RequestAvailable, model); await Run(model, settings, NotificationType.RequestAvailable);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task Send(NotificationMessage model, PushoverSettings settings) protected override async Task Send(NotificationMessage model, PushoverSettings settings)
@ -195,5 +105,21 @@ namespace Ombi.Notifications.Agents
}; };
await Send(notification, settings); await Send(notification, settings);
} }
private async Task Run(NotificationOptions model, PushoverSettings settings, NotificationType type)
{
var parsed = await LoadTemplate(NotificationAgent.Pushover, type, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
}
} }
} }

View file

@ -54,138 +54,42 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, SlackNotificationSettings settings) protected override async Task NewRequest(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.NewRequest, model); await Run(model, settings, NotificationType.NewRequest);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task NewIssue(NotificationOptions model, SlackNotificationSettings settings) protected override async Task NewIssue(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.Issue, model); await Run(model, settings, NotificationType.Issue);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task IssueComment(NotificationOptions model, SlackNotificationSettings settings) protected override async Task IssueComment(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.IssueComment, model); await Run(model, settings, NotificationType.IssueComment);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueComment} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, SlackNotificationSettings settings) protected override async Task IssueResolved(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.IssueResolved, model); await Run(model, settings, NotificationType.IssueResolved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task AddedToRequestQueue(NotificationOptions model, SlackNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, SlackNotificationSettings settings)
{ {
var user = string.Empty; await Run(model, settings, NotificationType.ItemAddedToFaultQueue);
var title = string.Empty;
if (model.RequestType == RequestType.Movie)
{
user = MovieRequest.RequestedUser.UserAlias;
title = MovieRequest.Title;
}
else
{
user = TvRequest.RequestedUser.UserAlias;
title = TvRequest.ParentRequest.Title;
}
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
var notification = new NotificationMessage
{
Message = message
};
await Send(notification, settings);
} }
protected override async Task RequestDeclined(NotificationOptions model, SlackNotificationSettings settings) protected override async Task RequestDeclined(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.RequestDeclined, model); await Run(model, settings, NotificationType.RequestAvailable);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task RequestApproved(NotificationOptions model, SlackNotificationSettings settings) protected override async Task RequestApproved(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.RequestApproved, model); await Run(model, settings, NotificationType.RequestApproved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task AvailableRequest(NotificationOptions model, SlackNotificationSettings settings) protected override async Task AvailableRequest(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.RequestAvailable, model); await Run(model, settings, NotificationType.RequestAvailable);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
} }
protected override async Task Send(NotificationMessage model, SlackNotificationSettings settings) protected override async Task Send(NotificationMessage model, SlackNotificationSettings settings)
@ -218,5 +122,21 @@ namespace Ombi.Notifications.Agents
}; };
await Send(notification, settings); await Send(notification, settings);
} }
private async Task Run(NotificationOptions model, SlackNotificationSettings settings, NotificationType type)
{
var parsed = await LoadTemplate(NotificationAgent.Slack, type, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
}
} }
} }

View file

@ -41,134 +41,42 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, TelegramSettings settings) protected override async Task NewRequest(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.NewRequest, model); await Run(model, settings, NotificationType.NewRequest);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task NewIssue(NotificationOptions model, TelegramSettings settings) protected override async Task NewIssue(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.Issue, model); await Run(model, settings, NotificationType.Issue);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task IssueComment(NotificationOptions model, TelegramSettings settings) protected override async Task IssueComment(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.IssueComment, model); await Run(model, settings, NotificationType.IssueComment);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueComment} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, TelegramSettings settings) protected override async Task IssueResolved(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.IssueResolved, model); await Run(model, settings, NotificationType.IssueResolved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task AddedToRequestQueue(NotificationOptions model, TelegramSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, TelegramSettings settings)
{ {
var user = string.Empty; await Run(model, settings, NotificationType.ItemAddedToFaultQueue);
var title = string.Empty;
var image = string.Empty;
if (model.RequestType == RequestType.Movie)
{
user = MovieRequest.RequestedUser.UserAlias;
title = MovieRequest.Title;
image = MovieRequest.PosterPath;
}
else
{
user = TvRequest.RequestedUser.UserAlias;
title = TvRequest.ParentRequest.Title;
image = TvRequest.ParentRequest.PosterPath;
}
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
var notification = new NotificationMessage
{
Message = message
};
await Send(notification, settings);
} }
protected override async Task RequestDeclined(NotificationOptions model, TelegramSettings settings) protected override async Task RequestDeclined(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.RequestDeclined, model); await Run(model, settings, NotificationType.RequestDeclined);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task RequestApproved(NotificationOptions model, TelegramSettings settings) protected override async Task RequestApproved(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.RequestApproved, model); await Run(model, settings, NotificationType.RequestApproved);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message ?? string.Empty,
};
await Send(notification, settings);
} }
protected override async Task AvailableRequest(NotificationOptions model, TelegramSettings settings) protected override async Task AvailableRequest(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.RequestAvailable, model); await Run(model, settings, NotificationType.RequestAvailable);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
} }
protected override async Task Send(NotificationMessage model, TelegramSettings settings) protected override async Task Send(NotificationMessage model, TelegramSettings settings)
@ -192,5 +100,20 @@ namespace Ombi.Notifications.Agents
}; };
await Send(notification, settings); await Send(notification, settings);
} }
private async Task Run(NotificationOptions model, TelegramSettings settings, NotificationType type)
{
var parsed = await LoadTemplate(NotificationAgent.Telegram, type, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
}
} }
} }

View file

@ -209,7 +209,15 @@ namespace Ombi.Store.Context
}; };
break; break;
case NotificationType.ItemAddedToFaultQueue: case NotificationType.ItemAddedToFaultQueue:
continue; notificationToAdd = new NotificationTemplates
{
NotificationType = notificationType,
Message = "Hello! The user '{UserName}' has requested {Title} but it could not be added. This has been added into the requests queue and will keep retrying",
Subject = "Item Added To Retry Queue",
Agent = agent,
Enabled = true,
};
break;
case NotificationType.WelcomeEmail: case NotificationType.WelcomeEmail:
notificationToAdd = new NotificationTemplates notificationToAdd = new NotificationTemplates
{ {