Refactor Slack notifier to use latest nlopes/slack

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
This commit is contained in:
Prasad Ghangal 2019-08-06 14:47:08 +05:30
parent ec65f308d1
commit ab813afe59
2 changed files with 4 additions and 15 deletions

View File

@ -126,10 +126,7 @@ func (sm slackMessage) Send() {
return
}
params := slack.PostMessageParameters{
AsUser: true,
}
if _, _, err := sm.RTM.PostMessage(sm.Event.Channel, "```"+sm.Response+"```", params); err != nil {
if _, _, err := sm.RTM.PostMessage(sm.Event.Channel, slack.MsgOptionText("```"+sm.Response+"```", false), slack.MsgOptionAsUser(true)); err != nil {
logging.Logger.Error("Error in sending message:", err)
}
}

View File

@ -44,9 +44,6 @@ func (s *Slack) SendEvent(event events.Event) error {
log.Logger.Debug(fmt.Sprintf(">> Sending to slack: %+v", event))
api := slack.New(s.Token)
params := slack.PostMessageParameters{
AsUser: true,
}
var attachment slack.Attachment
@ -141,13 +138,11 @@ func (s *Slack) SendEvent(event events.Event) error {
if ts > "0" {
attachment.Ts = ts
}
attachment.Color = attachmentColor[event.Level]
params.Attachments = []slack.Attachment{attachment}
// non empty value in event.channel demands redirection of events to a different channel
if event.Channel != "" {
channelID, timestamp, err := api.PostMessage(event.Channel, "", params)
channelID, timestamp, err := api.PostMessage(event.Channel, slack.MsgOptionAttachments(attachment), slack.MsgOptionAsUser(true))
if err != nil {
log.Logger.Errorf("Error in sending slack message %s", err.Error())
// send error message to default channel
@ -164,7 +159,7 @@ func (s *Slack) SendEvent(event events.Event) error {
log.Logger.Debugf("Event successfully sent to channel %s at %s", channelID, timestamp)
} else {
// empty value in event.channel sends notifications to default channel.
channelID, timestamp, err := api.PostMessage(s.Channel, "", params)
channelID, timestamp, err := api.PostMessage(s.Channel, slack.MsgOptionAttachments(attachment), slack.MsgOptionAsUser(true))
if err != nil {
log.Logger.Errorf("Error in sending slack message %s", err.Error())
return err
@ -179,11 +174,8 @@ func (s *Slack) SendMessage(msg string) error {
log.Logger.Debug(fmt.Sprintf(">> Sending to slack: %+v", msg))
api := slack.New(s.Token)
params := slack.PostMessageParameters{
AsUser: true,
}
channelID, timestamp, err := api.PostMessage(s.Channel, msg, params)
channelID, timestamp, err := api.PostMessage(s.Channel, slack.MsgOptionText(msg, false), slack.MsgOptionAsUser(true))
if err != nil {
log.Logger.Errorf("Error in sending slack message %s", err.Error())
return err