Merge pull request #94 from TimothyWillard/master

Seperate Config File
This commit is contained in:
Timothy Willard 2016-12-02 21:23:05 -05:00 committed by GitHub
commit 69945a63fe
2 changed files with 22 additions and 23 deletions

4
lib/config.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
fromAddress: 'foo@bar.com',
debugEnabled: false
};

View File

@ -1,12 +1,8 @@
var providers = require('./providers.js'),
carriers = require('./carriers.js'),
spawn = require('child_process').spawn,
StringDecoder = require('string_decoder').StringDecoder;
var debugEnabled = false;
// NOTE: Change this if you are self-hosting!
var fromAddress = 'foo@bar.com';
StringDecoder = require('string_decoder').StringDecoder,
config = require('./config.js');
//----------------------------------------------------------------
/*
@ -14,25 +10,11 @@ var fromAddress = 'foo@bar.com';
value.
*/
function output() {
if (debugEnabled) {
if (config.debugEnabled) {
return console.log.apply(this, arguments);
}
}
//----------------------------------------------------------------
/* Enable verbosity for the text module.
If enabled, logging functions will
print to stdout.
Params:
enable - bool
*/
function debug(enable) {
debugEnabled = enable;
return debugEnabled;
}
//----------------------------------------------------------------
/* Sends a text message
@ -61,7 +43,7 @@ function sendText(phone, message, carrier, region, cb) {
var emails = providers_list.map(function(provider) {
return provider.replace('%s', phone);
}).join(',');
var args = ['-s', 'txt', '-e', 'set from=' + fromAddress,
var args = ['-s', 'txt', '-e', 'set from=' + config.fromAddress,
'-e', 'set use_from=yes', '-e', 'set envelope_from=yes', '-b', emails];
var child = spawn('mutt', args);
var decoder = new StringDecoder('utf8');
@ -83,7 +65,20 @@ function sendText(phone, message, carrier, region, cb) {
child.stdin.end();
}
//----------------------------------------------------------------
/* Overrides default config
Takes a new configuration object, which is
used to override the defaults
Params:
obj - object of config properties to be overriden
*/
function setConfig(obj) {
config = Object.assign(config, obj);
}
module.exports = {
send: sendText, // Send a text message
debug: debug // Enable or disable debug output
config: setConfig // Override default config
};