-
Notifications
You must be signed in to change notification settings - Fork 24
/
slack.ts
27 lines (23 loc) · 863 Bytes
/
slack.ts
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
var WebClient = require('@slack/client').WebClient;
var fs = require('fs');
// Class to post messaages with image to slack
export class Slack {
static web = null;
static setKey = (key) => {
Slack.web = new WebClient(key);
}
send = (slackGroup, url, title, message, ts, callback) => {
if(Slack.web) {
Slack.web.chat.postMessage(slackGroup, '',{attachments: [{"title": title, image_url: url, text:message}], as_user: true, reply_broadcast: true, thread_ts: ts}, function(err, res) {
if (err) {
console.log('Error:', err);
} else {
if(res.message.thread_ts)
callback(res.message.thread_ts);
else
callback(res.ts);
}
});
}
}
}