-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.js
executable file
·43 lines (38 loc) · 1.1 KB
/
app.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
const config = require('./config.json');
const Adapters = require('./adapters');
const _ = require('lodash');
const request = require('request');
module.exports = {
talkToSlack: function(review, query) {
const adapter = Adapters[review.dataType];
if (_.isUndefined(adapter)) {
console.log(`No adapter has been registered for the event ${review.dataType}`);
return;
}
var adapted = adapter(review);
var channel;
if(!_.isUndefined(query.channel)) {
// be compatible with parameters without a prefix. In which case we default to a general channel
var prefix = '';
const firstCharacter = query.channel.charAt(0);
if(firstCharacter != '#' && firstCharacter != '@') {
prefix = '#';
}
channel = prefix+query.channel;
}
Promise.resolve(adapted).then(function(value) {
if(!_.isUndefined(channel)) {
value.channel = channel;
}
request.post(config.slackWebhookUrl, {
json: true,
body: value
}, function(err, res, body) {
console.log(body);
});
})
.catch(function(err) {
console.log(`Adapter resolved with error: ${err}`);
})
}
};