示例#1
0
 private bool ValidateConfiguration(MattermostNotificationSettings settings)
 {
     if (!settings.Enabled)
     {
         return(false);
     }
     if (string.IsNullOrEmpty(settings.WebhookUrl))
     {
         return(false);
     }
     return(true);
 }
示例#2
0
        public bool Mattermost([FromBody] MattermostNotificationSettings settings)
        {
            try
            {
                settings.Enabled = true;
                MattermostNotification.NotifyAsync(
                    new NotificationOptions {
                    NotificationType = NotificationType.Test, RequestId = -1
                }, settings);

                return(true);
            }
            catch (Exception e)
            {
                Log.LogError(LoggingEvents.Api, e, "Could not test Mattermost");
                return(false);
            }
        }
示例#3
0
        private async Task Push(MattermostNotificationSettings config, string message)
        {
            try
            {
                var notification = new MattermostNotificationBody {
                    username = config.Username, channel = config.Channel ?? string.Empty, icon_url = config.IconUrl ?? string.Empty, text = message
                };

                var result = await Api.PushAsync(config.WebhookUrl, notification);

                if (!result.Equals("ok"))
                {
                    Log.Error("Mattermost returned a message that was not 'ok', the notification did not get pushed");
                    Log.Error($"Message that mattermost returned: {result}");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#4
0
        private async Task PushFaultQueue(NotificationModel model, MattermostNotificationSettings 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);
        }
示例#5
0
        private async Task PushTest(MattermostNotificationSettings settings)
        {
            var message = $"This is a test from Ombi, if you can see this then we have successfully pushed a notification!";

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

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

            await Push(settings, message);
        }