-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.slack.js
54 lines (45 loc) · 1.33 KB
/
notify.slack.js
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
52
53
54
// Requirements
const Config = require("./config");
const Redis = require("ioredis");
const request = require("request");
// Redis Client Connection
const redisClient = new Redis({
port: Config.port,
host: Config.host,
family: 4, // 4 (IPv4) or 6 (IPv6)
db: 0
});
const subscriberClient = redisClient();
// Channel Subscribe
// squeue: sync-queue-worker's redis-prefix argument
const slackNotifyChannelKey = Config.prefix + ':notify:slack';
// Event Listener
subscriberClient.on('ready', function () {
console.log('im ready');
});
subscriberClient.subscribe(slackNotifyChannelKey, function (err, count) {
console.log('subscribe', slackNotifyChannelKey, err, count);
if(err) {
} else {
}
});
subscriberClient.on('message', function (channel, message) {
console.log('subscribe message', channel, message);
const webhookUrl = 'https://hooks.slack.com/services' + Config.slackHookUrl; // your slack hook url
request.post(webhookUrl, {
form: {
payload: message
}
}, function(err, response) {
if (err) {
console.log(err);
return false;
} else if (response.body !== 'ok') {
console.log(response.body);
return false;
} else {
console.log(response.body);
return true;
}
});
});