Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Replace node-env-file with dotenv #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .env

This file was deleted.

11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Environment variables
# 1. Make a copy of this file to .env file
# 2. Remove comments

# You can access all env variables from process.env.YOUR_ENV_SECRET

CLIENT_ID=
CLIENT_SECRET=
STUDIO_TOKEN=
PORT=3000

23 changes: 10 additions & 13 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This bot demonstrates many of the core features of Botkit:

Run your bot from the command line:

clientId=<MY SLACK TOKEN> clientSecret=<my client secret> PORT=<3000> studio_token=<MY BOTKIT STUDIO TOKEN> node bot.js
CLIENT_ID=<MY SLACK TOKEN> CLIENT_SECRET=<MY CLIENT SECRET> PORT=<3000> STUDIO_TOKEN=<MY BOTKIT STUDIO TOKEN> node bot.js

# USE THE BOT:

Expand All @@ -51,24 +51,21 @@ This bot demonstrates many of the core features of Botkit:
-> http://howdy.ai/botkit

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
var env = require('node-env-file');
env(__dirname + '/.env');


if (!process.env.clientId || !process.env.clientSecret || !process.env.PORT) {
var env = require('dotenv').config().parsed;
if (env.error || Object.values(env).some((x) => x === '')) {
usage_tip();
// process.exit(1);
process.exit(1);
}

var Botkit = require('botkit');
var debug = require('debug')('botkit:main');

var bot_options = {
clientId: process.env.clientId,
clientSecret: process.env.clientSecret,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
// debug: true,
scopes: ['bot'],
studio_token: process.env.studio_token,
studio_token: process.env.STUDIO_TOKEN,
studio_command_uri: process.env.studio_command_uri
};

Expand All @@ -89,7 +86,7 @@ controller.startTicking();
// Set up an Express-powered webserver to expose oauth and webhook endpoints
var webserver = require(__dirname + '/components/express_webserver.js')(controller);

if (!process.env.clientId || !process.env.clientSecret) {
if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET) {

// Load in some helpers that make running Botkit on Glitch.com better
require(__dirname + '/components/plugin_glitch.js')(controller);
Expand Down Expand Up @@ -140,7 +137,7 @@ if (!process.env.clientId || !process.env.clientSecret) {
// If a trigger is matched, the conversation will automatically fire!
// You can tie into the execution of the script using the functions
// controller.studio.before, controller.studio.after and controller.studio.validate
if (process.env.studio_token) {
if (process.env.STUDIO_TOKEN) {
controller.on('direct_message,direct_mention,mention', function(bot, message) {
controller.studio.runTrigger(bot, message.text, message.user, message.channel, message).then(function(convo) {
if (!convo) {
Expand Down Expand Up @@ -174,7 +171,7 @@ 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 studio_token=<MY BOTKIT STUDIO TOKEN> node bot.js');
console.log('CLIENT_ID=<MY SLACK CLIENT ID> CLIENT_SECRET=<MY CLIENT SECRET> PORT=3000 STUDIO_TOKEN=<MY BOTKIT STUDIO TOKEN> node bot.js');
console.log('Get Slack app credentials here: https://api.slack.com/apps')
console.log('Get a Botkit Studio token here: https://studio.botkit.ai/')
console.log('~~~~~~~~~~');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"botkit-studio-metrics": "^0.0.2",
"cookie-parser": "^1.4.3",
"debug": "^2.3.3",
"dotenv": "^4.0.0",
"express": "^4.14.0",
"express-hbs": "^1.0.4",
"node-env-file": "^0.1.8",
"querystring": "^0.2.0",
"request": "^2.79.0",
"wordfilter": "^0.2.6"
Expand Down