mirror of https://github.com/Ombi-app/Ombi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
5.3 KiB
145 lines
5.3 KiB
using System;
|
|
using Hangfire;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Ombi.Attributes;
|
|
using Ombi.Core.Notifications;
|
|
using Ombi.Helpers;
|
|
using Ombi.Notifications.Agents;
|
|
using Ombi.Notifications.Models;
|
|
using Ombi.Settings.Settings.Models.Notifications;
|
|
|
|
namespace Ombi.Controllers.External
|
|
{
|
|
/// <summary>
|
|
/// The Tester Controller
|
|
/// </summary>
|
|
/// <seealso cref="Ombi.Controllers.BaseV1ApiController" />
|
|
[Admin]
|
|
[ApiV1]
|
|
public class TesterController : Controller
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="TesterController" /> class.
|
|
/// </summary>
|
|
/// <param name="service">The service.</param>
|
|
/// <param name="notification">The notification.</param>
|
|
/// <param name="emailN">The notification.</param>
|
|
/// <param name="pushbullet">The pushbullet.</param>
|
|
/// <param name="slack">The slack.</param>
|
|
public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN,
|
|
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm)
|
|
{
|
|
Service = service;
|
|
DiscordNotification = notification;
|
|
EmailNotification = emailN;
|
|
PushbulletNotification = pushbullet;
|
|
SlackNotification = slack;
|
|
PushoverNotification = po;
|
|
MattermostNotification = mm;
|
|
}
|
|
|
|
private INotificationService Service { get; }
|
|
private IDiscordNotification DiscordNotification { get; }
|
|
private IEmailNotification EmailNotification { get; }
|
|
private IPushbulletNotification PushbulletNotification { get; }
|
|
private ISlackNotification SlackNotification { get; }
|
|
private IPushoverNotification PushoverNotification { get; }
|
|
private IMattermostNotification MattermostNotification { get; }
|
|
|
|
|
|
/// <summary>
|
|
/// Sends a test message to discord using the provided settings
|
|
/// </summary>
|
|
/// <param name="settings">The settings.</param>
|
|
/// <returns></returns>
|
|
[HttpPost("discord")]
|
|
public bool Discord([FromBody] DiscordNotificationSettings settings)
|
|
{
|
|
settings.Enabled = true;
|
|
DiscordNotification.NotifyAsync(
|
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a test message to Pushbullet using the provided settings
|
|
/// </summary>
|
|
/// <param name="settings">The settings.</param>
|
|
/// <returns></returns>
|
|
[HttpPost("pushbullet")]
|
|
public bool Pushbullet([FromBody] PushbulletSettings settings)
|
|
{
|
|
settings.Enabled = true;
|
|
PushbulletNotification.NotifyAsync(
|
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a test message to Pushover using the provided settings
|
|
/// </summary>
|
|
/// <param name="settings">The settings.</param>
|
|
/// <returns></returns>
|
|
[HttpPost("pushover")]
|
|
public bool Pushover([FromBody] PushoverSettings settings)
|
|
{
|
|
settings.Enabled = true;
|
|
PushoverNotification.NotifyAsync(
|
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a test message to mattermost using the provided settings
|
|
/// </summary>
|
|
/// <param name="settings">The settings.</param>
|
|
/// <returns></returns>
|
|
[HttpPost("mattermost")]
|
|
public bool Mattermost([FromBody] MattermostNotificationSettings settings)
|
|
{
|
|
settings.Enabled = true;
|
|
MattermostNotification.NotifyAsync(
|
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Sends a test message to Slack using the provided settings
|
|
/// </summary>
|
|
/// <param name="settings">The settings.</param>
|
|
/// <returns></returns>
|
|
[HttpPost("slack")]
|
|
public bool Slack([FromBody] SlackNotificationSettings settings)
|
|
{
|
|
settings.Enabled = true;
|
|
SlackNotification.NotifyAsync(
|
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a test message via email to the admin email using the provided settings
|
|
/// </summary>
|
|
/// <param name="settings">The settings.</param>
|
|
/// <returns></returns>
|
|
[HttpPost("email")]
|
|
public bool Email([FromBody] EmailNotificationSettings settings)
|
|
{
|
|
settings.Enabled = true;
|
|
var notificationModel = new NotificationOptions
|
|
{
|
|
NotificationType = NotificationType.Test,
|
|
RequestId = -1
|
|
};
|
|
EmailNotification.NotifyAsync(notificationModel, settings);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |