-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.js
85 lines (69 loc) · 2.86 KB
/
bot.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
const env = require('node-env-file');
env(__dirname + '/.env');
const Botkit = require('botkit');
const debug = require('debug')('botkit:main');
const bot_options = {
clientId: process.env.clientId,
clientSecret: process.env.clientSecret,
clientSigningSecret: process.env.clientSigningSecret,
// debug: true,
scopes: ['bot'],
studio_token: process.env.studio_token,
studio_command_uri: process.env.studio_command_uri,
json_file_store: __dirname + '/.data/db/'
};
// Create the Botkit controller, which controls all instances of the bot.
const controller = Botkit.slackbot(bot_options);
controller.startTicking();
// Set up an Express-powered webserver to expose oauth and webhook endpoints.
const webserver = require(__dirname + '/components/express_webserver.js')(controller);
if (!process.env.clientId || !process.env.clientSecret) {
// Load in some helpers that make running Botkit on Glitch.com better
require(__dirname + '/components/plugin_glitch.js')(controller);
webserver.get('/', function(req, res){
res.render('installation', {
domain: req.get('host'),
protocol: req.protocol,
glitch_domain: process.env.PROJECT_DOMAIN,
layout: 'layouts/default'
});
})
var where_its_at = 'http://' + (process.env.PROJECT_DOMAIN ? process.env.PROJECT_DOMAIN+ '.glitch.me/' : 'localhost:' + process.env.PORT || 3000);
console.log('WARNING: This application is not fully configured to work with Slack. Please see instructions at ' + where_its_at);
} else {
webserver.get('/', function(req, res){
res.render('index', {
domain: req.get('host'),
protocol: req.protocol,
glitch_domain: process.env.PROJECT_DOMAIN,
layout: 'layouts/default'
});
})
webserver.get('/coffeedebug', function (req, res) {
let DATA_PATH = './.data/coffee.json';
try {
let data = require('fs').readFileSync(DATA_PATH).toString('utf8');
res.json(JSON.parse(data));
} catch (e) {
res.status(404);
res.end('no coffee json found');
}
});
// Send an onboarding message when a new team joins
require(__dirname + '/components/onboarding.js')(controller);
// Load in some helpers that make running Botkit on Glitch.com better
require(__dirname + '/components/plugin_glitch.js')(controller);
// Load skills.
require('./skills/coffeetime.js')(controller);
require('./skills/block_actions/setup.js')(controller);
require('./skills/block_actions/help.js')(controller);
require('./skills/block_actions/admin.js')(controller);
}
function usage_tip() {
console.log('----~~~~~~');
console.log('Botkit Starter Kit');
console.log('Execute your bot application like this:');
console.log('clientId=<MY SLACK CLIENT ID> clientSecret=<MY CLIENT SECRET> PORT=3000 node bot.js');
console.log('Get Slack app credentials here: https://api.slack.com/apps')
console.log('~~~+++++---');
}