File tree Expand file tree Collapse file tree 1 file changed +40
-24
lines changed
server/notification-providers Expand file tree Collapse file tree 1 file changed +40
-24
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,45 @@ class Slack extends NotificationProvider {
79
79
}
80
80
81
81
const textMsg = "Uptime Kuma Alert" ;
82
+
83
+ //create an array to dynamically add blocks
84
+ const blocks = [ ] ;
85
+
86
+ // the header block
87
+ blocks . push ( {
88
+ "type" : "header" ,
89
+ "text" : {
90
+ "type" : "plain_text" ,
91
+ "text" : textMsg ,
92
+ } ,
93
+ } ) ;
94
+
95
+ // the body block, containing the details
96
+ blocks . push ( {
97
+ "type" : "section" ,
98
+ "fields" : [
99
+ {
100
+ "type" : "mrkdwn" ,
101
+ "text" : "*Message*\n" + msg ,
102
+ } ,
103
+ {
104
+ "type" : "mrkdwn" ,
105
+ "text" : `*Time (${ heartbeatJSON [ "timezone" ] } )*\n${ heartbeatJSON [ "localDateTime" ] } ` ,
106
+ }
107
+ ] ,
108
+ } ) ;
109
+
110
+ //only add this block if we have actions
111
+ if ( actions . length > 0 ) {
112
+
113
+ //the actions block, containing buttons
114
+ blocks . push ( {
115
+ "type" : "actions" ,
116
+ "elements" : actions ,
117
+ } ) ;
118
+ }
119
+
120
+ //finally, build the entire slack request object
82
121
let data = {
83
122
"text" : `${ textMsg } \n${ msg } ` ,
84
123
"channel" : notification . slackchannel ,
@@ -87,30 +126,7 @@ class Slack extends NotificationProvider {
87
126
"attachments" : [
88
127
{
89
128
"color" : ( heartbeatJSON [ "status" ] === UP ) ? "#2eb886" : "#e01e5a" ,
90
- "blocks" : [
91
- {
92
- "type" : "header" ,
93
- "text" : {
94
- "type" : "plain_text" ,
95
- "text" : textMsg ,
96
- } ,
97
- } ,
98
- {
99
- "type" : "section" ,
100
- "fields" : [ {
101
- "type" : "mrkdwn" ,
102
- "text" : "*Message*\n" + msg ,
103
- } ,
104
- {
105
- "type" : "mrkdwn" ,
106
- "text" : `*Time (${ heartbeatJSON [ "timezone" ] } )*\n${ heartbeatJSON [ "localDateTime" ] } ` ,
107
- } ] ,
108
- } ,
109
- {
110
- "type" : "actions" ,
111
- "elements" : actions ,
112
- }
113
- ] ,
129
+ "blocks" : blocks ,
114
130
}
115
131
]
116
132
} ;
You can’t perform that action at this time.
0 commit comments