Skip to content
This repository was archived by the owner on Apr 7, 2024. It is now read-only.

Commit eb275c8

Browse files
logs link + buttons support (#36)
1 parent 5b90a82 commit eb275c8

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

notify/slackv2/blocks.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
)
1313

1414
type Text struct {
15-
Type string `json:"type"`
16-
Text string `json:"text"`
15+
Type string `json:"type"`
16+
Text string `json:"text"`
17+
Emoji bool `json:"emoji,omitempty"`
18+
Verbatim bool `json:"verbatim,omitempty"`
1719
}
1820
type Element struct {
1921
Type string `json:"type"`
@@ -24,13 +26,22 @@ type Field struct {
2426
Text string `json:"text"`
2527
}
2628

29+
type Accessory struct {
30+
Type slack.MessageElementType `json:"type"`
31+
Text *Text `json:"text"`
32+
Value string `json:"value,omitempty"`
33+
URL string `json:"url"`
34+
ActionID string `json:"action_id,omitempty"`
35+
}
36+
2737
type Block struct {
28-
Type slack.MessageBlockType `json:"type"`
29-
Text *Text `json:"text,omitempty"`
30-
Fields []*Field `json:"fields,omitempty"`
31-
Elements []*Element `json:"elements,omitempty"`
32-
ImageURL string `json:"image_url,omitempty"`
33-
AltText string `json:"alt_text,omitempty"`
38+
Type slack.MessageBlockType `json:"type"`
39+
Text *Text `json:"text,omitempty"`
40+
Fields []*Field `json:"fields,omitempty"`
41+
Elements []*Element `json:"elements,omitempty"`
42+
ImageURL string `json:"image_url,omitempty"`
43+
AltText string `json:"alt_text,omitempty"`
44+
Accessory *Accessory `json:"accessory,omitempty"`
3445
}
3546

3647
func (b Block) BlockType() slack.MessageBlockType {
@@ -69,6 +80,7 @@ func (n *Notifier) formatMessage(data *template.Data) slack.Blocks {
6980
envs = UniqStr(envs)
7081

7182
blocks = append(blocks, Block{Type: slack.MBTHeader, Text: &Text{Type: slack.PlainTextType, Text: getMapValue(data.CommonLabels, "alertname")}})
83+
// Divider
7284
blocks = append(blocks, Block{Type: slack.MBTDivider})
7385

7486
{
@@ -111,7 +123,9 @@ func (n *Notifier) formatMessage(data *template.Data) slack.Blocks {
111123
} else {
112124
fields = append(fields, &Field{Type: slack.MarkdownType, Text: fmt.Sprintf("*:no_bell:~Silence~")})
113125
}
114-
126+
if val := getMapValue(data.CommonAnnotations, "log_link"); len(val) > 0 {
127+
fields = append(fields, &Field{Type: slack.MarkdownType, Text: fmt.Sprintf("*<%s|:scroll:Logs>*", val)})
128+
}
115129
blocks = append(blocks, Block{Type: slack.MBTSection, Fields: fields})
116130
}
117131

@@ -132,7 +146,6 @@ func (n *Notifier) formatMessage(data *template.Data) slack.Blocks {
132146

133147
{
134148
block := Block{Type: slack.MBTContext, Elements: make([]*Element, 0)}
135-
136149
if val := getMapValue(data.CommonAnnotations, "summary"); len(val) > 0 {
137150
block.Elements = append(block.Elements, &Element{Type: slack.MarkdownType, Text: fmt.Sprintf("*Summary:* %s", val)})
138151
} else {
@@ -158,13 +171,11 @@ func (n *Notifier) formatMessage(data *template.Data) slack.Blocks {
158171
}
159172
}
160173
}
161-
162174
if len(block.Elements) > 0 {
163175
blocks = append(blocks, block)
164176
}
165177
}
166178

167179
result := slack.Blocks{BlockSet: blocks}
168-
169180
return result
170181
}

0 commit comments

Comments
 (0)