Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions server/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -267,6 +268,8 @@ func (p *Plugin) handleNotification(body io.Reader, channel *TeamChannel) {
p.sendPostNotification(p.createSNSMessageNotificationAttachment(notification.Subject, messageNotification), channel)
return
}

p.sendPostNotification(p.createSNSUnknownTypeMessage(notification.Subject, notification.Message), channel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this behavior should be configurable in a plugin setting

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mickmister I'm not sure if I described this option correctly in Settings. Check, please

}

func (p *Plugin) sendPostNotification(attachment model.SlackAttachment, channel *TeamChannel) {
Expand Down Expand Up @@ -372,6 +375,26 @@ func (p *Plugin) createSNSCloudformationEventAttachment(subject string, messageN
return attachment
}

func (p *Plugin) createSNSUnknownTypeMessage(subject string, message string) model.SlackAttachment {
p.API.LogDebug("AWSSNS HandleNotification Unknown Type Message", "SUBJECT", subject)

text := message

jsonBytes := []byte(message)
prettyJSON := &bytes.Buffer{}
err := json.Indent(prettyJSON, jsonBytes, "", " ")
if err == nil {
text = "```json\n" + prettyJSON.String() + "\n```"
}

post := model.SlackAttachment{
Title: subject,
Text: text,
}

return post
}

func (p *Plugin) createSNSMessageNotificationAttachment(subject string, messageNotification SNSMessageNotification) model.SlackAttachment {
p.API.LogDebug("AWSSNS HandleNotification", "MESSAGE", subject)
var fields []*model.SlackAttachmentField
Expand Down