diff --git a/pkg/livenote/options.go b/pkg/livenote/options.go index f3ce1736d..ce5713d2c 100644 --- a/pkg/livenote/options.go +++ b/pkg/livenote/options.go @@ -4,6 +4,16 @@ import "time" type Option interface{} +type OptionChannel struct { + Channel string +} + +func Channel(channel string) *OptionChannel { + return &OptionChannel{ + Channel: channel, + } +} + type OptionCompare struct { Value bool } diff --git a/pkg/notifier/slacknotifier/slack.go b/pkg/notifier/slacknotifier/slack.go index f8f17492c..ba5f9d06c 100644 --- a/pkg/notifier/slacknotifier/slack.go +++ b/pkg/notifier/slacknotifier/slack.go @@ -241,6 +241,9 @@ func (n *Notifier) PostLiveNote(obj livenote.Object, opts ...livenote.Option) er var shouldPin bool var ttl time.Duration = 0 + // load the default channel + channel := n.channel + for _, opt := range opts { switch val := opt.(type) { case *livenote.OptionOneTimeMention: @@ -254,6 +257,10 @@ func (n *Notifier) PostLiveNote(obj livenote.Object, opts ...livenote.Option) er shouldPin = val.Value case *livenote.OptionTimeToLive: ttl = val.Duration + case *livenote.OptionChannel: + if val.Channel != "" { + channel = val.Channel + } } } @@ -265,7 +272,6 @@ func (n *Notifier) PostLiveNote(obj livenote.Object, opts ...livenote.Option) er } } - channel := n.channel note := n.liveNotePool.Update(obj) curObj = note.Object