New: Channel setting for Slack notifications to override default channel

Closes #2311
This commit is contained in:
Mark McDowall 2017-11-30 22:48:00 -08:00
parent b45b2017a8
commit e11e8ad272
No known key found for this signature in database
GPG Key ID: D4CEFA9A718052E0
3 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace NzbDrone.Core.Notifications.Slack.Payloads namespace NzbDrone.Core.Notifications.Slack.Payloads
@ -15,6 +15,8 @@ namespace NzbDrone.Core.Notifications.Slack.Payloads
[JsonProperty("icon_url")] [JsonProperty("icon_url")]
public string IconUrl { get; set; } public string IconUrl { get; set; }
public string Channel { get; set; }
public List<Attachment> Attachments { get; set; } public List<Attachment> Attachments { get; set; }
} }
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation.Results; using FluentValidation.Results;
using NLog; using NLog;
@ -107,6 +107,7 @@ namespace NzbDrone.Core.Notifications.Slack
private SlackPayload CreatePayload(string message, List<Attachment> attachments = null) private SlackPayload CreatePayload(string message, List<Attachment> attachments = null)
{ {
var icon = Settings.Icon; var icon = Settings.Icon;
var channel = Settings.Channel;
var payload = new SlackPayload var payload = new SlackPayload
{ {
@ -128,6 +129,11 @@ namespace NzbDrone.Core.Notifications.Slack
} }
} }
if (channel.IsNotNullOrWhiteSpace())
{
payload.Channel = channel;
}
return payload; return payload;
} }
} }

View File

@ -1,4 +1,4 @@
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
@ -27,6 +27,9 @@ namespace NzbDrone.Core.Notifications.Slack
[FieldDefinition(2, Label = "Icon", HelpText = "Change the icon that is used for messages from this integration (Emoji or URL)", Type = FieldType.Textbox, HelpLink = "http://www.emoji-cheat-sheet.com/")] [FieldDefinition(2, Label = "Icon", HelpText = "Change the icon that is used for messages from this integration (Emoji or URL)", Type = FieldType.Textbox, HelpLink = "http://www.emoji-cheat-sheet.com/")]
public string Icon { get; set; } public string Icon { get; set; }
[FieldDefinition(3, Label = "Channel", HelpText = "Overrides the default channel for the incoming webhook (#other-channel)", Type = FieldType.Textbox)]
public string Channel { get; set; }
public NzbDroneValidationResult Validate() public NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));