-
Notifications
You must be signed in to change notification settings - Fork 17
/
slack_notifier.go
51 lines (45 loc) · 1.09 KB
/
slack_notifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package notifier
import "github.com/lytics/slackhook"
// SlackNotifier is a notifier that send messages to Slack.
type SlackNotifier struct {
client *slackhook.Client
}
// NewSlackNotifier creates a new SlackNotifier.
func NewSlackNotifier(url string) Notifier {
return &SlackNotifier{slackhook.New(url)}
}
// NotifyStatusChange notifies a change in the status of a flag.
func (n *SlackNotifier) NotifyStatusChange(feature string, status bool, environment string) error {
text := "disabled"
color := "#e74c3c"
if status {
text = "enabled"
color = "#27ae60"
}
return n.client.Send(&slackhook.Message{
Text: "WOOF! WOFF! ARH-WOOOOOOOO!",
Attachments: []*slackhook.Attachment{
&slackhook.Attachment{
Title: "Laika Flag Update!",
Color: color,
Fields: []slackhook.Field{
slackhook.Field{
Title: "Flag",
Value: feature,
Short: false,
},
slackhook.Field{
Title: "Environment",
Value: environment,
Short: true,
},
slackhook.Field{
Title: "Status",
Value: text,
Short: true,
},
},
},
},
})
}