-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
88 lines (83 loc) · 2.35 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
const SlackBot = require('slack-quick-bots');
const path = require('path');
const fs = require('fs');
const template = fs.readFileSync(path.join(__dirname, 'template/oncall-template.hbs'), 'utf8');
const service = require('./lib/service');
const winston = require('winston');
const args = process.argv.slice(2);
const apikey = args[1];
const proxy = args[2];
var logger = new winston.Logger({
level: 'info',
transports: [
new winston.transports.File({
filename: 'log/pagerdutybot.log',
timestamp: true
})
]
});
var config = {
bots: [{
botCommand: {
team: {
commandType: 'DATA',
allowedParam: ['*'],
helpText: ' → _team <team-name>_ (full or part of team name)',
template: template,
data: function(input, options, callback) {
service.getTeams(input.params, apikey, function(err, data) {
callback({ result: data });
});
}
},
escalation: {
commandType: 'DATA',
allowedParam: ['*'],
helpText: ' → _escalation <escalation-name>_ (full or part of escalation name)',
template: template,
data: function(input, options, callback) {
service.getEscalations(input.params, apikey, function(err, data) {
callback({ result: data });
});
}
},
oncall: {
commandType: 'DATA',
allowedParam: ['primary', 'secondary', 'all'],
helpText: ' → _oncall primary <escalation-name>_ (full or part of escalation name)',
template: template,
data: function(input, options, callback) {
service.getOnCall(input.params, apikey, function(err, data) {
callback({ result: data });
});
}
},
user: {
commandType: 'DATA',
allowedParam: ['*'],
helpText: ' → _user <name or email>_',
template: template,
data: function(input, options, callback) {
service.getUserFromName(input.params, apikey, function(err, data) {
callback({ result: data });
});
}
}
},
slackApi: {
user: {
presence: true,
limit: 999
}
},
schedule: true,
botToken: args[0] || ''
}],
proxy: {
url: proxy || ''
},
logger: logger
};
var slackBot = new SlackBot(config);
slackBot.start();