This repository has been archived by the owner on Jul 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
54 lines (44 loc) · 1.54 KB
/
index.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
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
'use strict';
import { slackbot } from 'botkit';
import { eq, trim } from 'lodash';
import * as configure from './src/configure';
import * as listener from './src/listener';
import * as pulls from './src/pulls';
// startup logs
console.log('Starting Botkit...');
if (process.env.SLACK_BOT_STORAGE) {
console.log('Using persistent storage location:', process.env.SLACK_BOT_STORAGE);
}
// create shared slack bot controller
const controller = slackbot({
debug: process.env.SLACK_BOT_DEBUG === 'true',
json_file_store: process.env.SLACK_BOT_STORAGE
});
// setup slack command webserver
const slashCommandPort = process.env.SLACK_BOT_PORT || 3000;
controller.setupWebserver(slashCommandPort, (err, webserver) => controller.createWebhookEndpoints(webserver));
// initialize help message listener
function joinCommands(commands) {
return commands
.map(command => `- \`${command.command || command.commands.join('` / `')}\` - ${command.message}`)
.join('\n');
}
const helpText = `*Summary*
- Set up a team with a list of snippets to filter open issues and pull requests.
*Usage*
- \`help\` - display this message
${joinCommands(configure.commands)}
${joinCommands(pulls.commands)}
`;
controller.on('slash_command', (bot, message) => {
if (eq(trim(message.text), 'help')) {
bot.replyPublic(message, helpText);
}
});
controller.hears('^help$', 'direct_message,direct_mention', (bot, message) => {
bot.reply(message, helpText);
});
// initialize other listeners
configure.messenger(controller);
pulls.messenger(controller);
listener.messenger(controller);