Skip to content

Commit 1149805

Browse files
committed
support rich message Slack fromat
1 parent 911fe34 commit 1149805

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/common/tcApiHelper.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,18 @@ function* sendMessageToBus(data) {
208208
/**
209209
* Notify slack channel.
210210
* @param {string} channel the slack channel name
211-
* @param {string} text the message
211+
* @param {string} text the message
212+
* @param {string} blocks rich formatted message as per https://api.slack.com/block-kit
212213
*/
213-
function* notifySlackChannel(channel, text) {
214+
function* notifySlackChannel(channel, text, blocks) {
214215
if (config.SLACK.NOTIFY) {
215216
const token = config.SLACK.BOT_TOKEN;
216217
const url = config.SLACK.URL;
217218
const res = yield request
218219
.post(url)
219220
.set('Content-Type', 'application/json')
220221
.set('Authorization', `Bearer ${token}`)
221-
.send({ channel, text })
222+
.send({ channel, text, blocks })
222223
.catch((err) => {
223224
const errorDetails = _.get(err, 'message');
224225
throw new Error(

src/services/UniversalNotificationService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function* handle(message) {
186186
break;
187187
case constants.SETTINGS_SLACK_SERVICE_ID:
188188
if (validator(data, slackSchema)) {
189-
yield tcApiHelper.notifySlackChannel(data.details.channel, data.details.text);
189+
yield tcApiHelper.notifySlackChannel(data.details.channel, data.details.text, data.details.blocks);
190190
}
191191
break;
192192
case constants.SETTINGS_WEB_SERVICE_ID:

0 commit comments

Comments
 (0)