Exemplo n.º 1
0
        public bool Slack([FromBody] SlackNotificationSettings settings)
        {
            try
            {
                settings.Enabled = true;
                SlackNotification.NotifyAsync(
                    new NotificationOptions {
                    NotificationType = NotificationType.Test, RequestId = -1
                }, settings);

                return(true);
            }
            catch (Exception e)
            {
                Log.LogError(LoggingEvents.Api, e, "Could not test Slack");
                return(false);
            }
        }
        private async Task Push(SlackNotificationSettings config, string message)
        {
            try
            {
                var notification = new SlackNotificationBody {
                    username = config.Username, channel = config.Channel ?? string.Empty, text = message
                };

                var result = await Api.PushAsync(config.Team, config.Token, config.Service, notification);

                if (!result.Equals("ok"))
                {
                    Log.Error("Slack returned a message that was not 'ok', the notification did not get pushed");
                    Log.Error($"Message that slack returned: {result}");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
 private bool ValidateConfiguration(SlackNotificationSettings settings)
 {
     if (!settings.Enabled)
     {
         return(false);
     }
     if (string.IsNullOrEmpty(settings.WebhookUrl))
     {
         return(false);
     }
     try
     {
         var a = settings.Team;
         var b = settings.Service;
         var c = settings.Token;
     }
     catch (IndexOutOfRangeException)
     {
         return(false);
     }
     return(true);
 }
        private async Task PushTest(SlackNotificationSettings settings)
        {
            var message = $"This is a test from Plex Requests, if you can see this then we have successfully pushed a notification!";

            await Push(settings, message);
        }
        private async Task PushIssueAsync(NotificationModel model, SlackNotificationSettings settings)
        {
            var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";

            await Push(settings, message);
        }
        private async Task PushNewRequestAsync(NotificationModel model, SlackNotificationSettings settings)
        {
            var message = $"{model.Title} has been requested by user: {model.User}";

            await Push(settings, message);
        }
Exemplo n.º 7
0
        private async Task PushFaultQueue(NotificationModel model, SlackNotificationSettings settings)
        {
            var message = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";

            await Push(settings, message);
        }