-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.js
More file actions
71 lines (59 loc) · 2.28 KB
/
Copy pathbot.js
File metadata and controls
71 lines (59 loc) · 2.28 KB
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
var env = require('node-env-file');
var path = require("path");
var fs = require("fs");
var botkit = require('botkit');
env(__dirname + '/.env');
if (!process.env.clientId || !process.env.clientSecret || !process.env.DB_PATH) {
usage_tip();
process.exit(1);
}
var bot_options = {
clientId: process.env.clientId,
clientSecret: process.env.clientSecret,
clientSigningSecret: process.env.clientSigningSecret,
debug: false,
scopes: ['bot']
};
var dbPath = __dirname + process.env.DB_PATH;
let dbDir = path.dirname(dbPath);
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir);
}
var sqliteStorage = require(__dirname + '/components/sqlite_storage.js')({
path: dbPath
});
bot_options.storage = sqliteStorage;
// Create the Botkit controller, which controls all instances of the bot.
var controller = botkit.slackbot(bot_options);
controller.startTicking();
// Set up an Express-powered webserver to expose oauth and webhook endpoints
var webserver = require(__dirname + '/components/express_webserver.js')(controller);
webserver.get('/', function (req, res) {
res.render('index', {
domain: req.get('host'),
protocol: req.protocol,
glitch_domain: process.env.PROJECT_DOMAIN,
layout: 'layouts/default'
});
})
// Start app domain
require(__dirname + '/app.js').default.instance.init(controller);
// Set up a simple storage backend for keeping a record of customers
// who sign up for the app via the oauth
require(__dirname + '/components/user_registration.js')(controller);
// 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);
var normalizedPath = path.join(__dirname, "skills");
fs.readdirSync(normalizedPath).forEach(function (file) {
require("./skills/" + file)(controller);
});
function usage_tip() {
console.log('~~~~~~~~~~');
console.log('Slack Translator Bot');
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('~~~~~~~~~~');
}