Skip to content

Commit cfbc5cd

Browse files
author
Dakota Smith
committed
Update to use mongodb if MONGODB_URI available in env. Move file based store to .data/db to hide during glitch remixes.
1 parent eb11490 commit cfbc5cd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

bot.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,24 @@ if (!process.env.clientId || !process.env.clientSecret || !process.env.PORT) {
6464
var Botkit = require('botkit');
6565
var debug = require('debug')('botkit:main');
6666

67-
// Create the Botkit controller, which controls all instances of the bot.
68-
var controller = Botkit.slackbot({
67+
var bot_options = {
6968
clientId: process.env.clientId,
7069
clientSecret: process.env.clientSecret,
7170
// debug: true,
7271
scopes: ['bot'],
7372
studio_token: process.env.studio_token,
74-
studio_command_uri: process.env.studio_command_uri,
75-
json_file_store: __dirname + '/.db/' // store user data in a simple JSON format
76-
});
73+
studio_command_uri: process.env.studio_command_uri
74+
};
75+
76+
if (process.env.MONGO_URI) {
77+
var mongoStorage = require('botkit-storage-mongo')({mongoUri: process.env.MONGO_URI});
78+
bot_options.storage = mongoStorage;
79+
} else {
80+
bot_options.json_file_store = __dirname + '/.data/db/'; // store user data in a simple JSON format
81+
}
82+
83+
// Create the Botkit controller, which controls all instances of the bot.
84+
var controller = Botkit.slackbot(bot_options);
7785

7886
controller.startTicking();
7987

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"body-parser": "^1.15.2",
1111
"botkit": "^0.5",
12+
"botkit-storage-mongo": "^1.0.6",
1213
"dashbot": "0.7.4",
1314
"debug": "^2.3.3",
1415
"express": "^4.14.0",

0 commit comments

Comments
 (0)