diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..b9a1610 --- /dev/null +++ b/lib/config.js @@ -0,0 +1,4 @@ +module.exports = { + fromAddress: 'foo@bar.com', + debugEnabled: false +}; \ No newline at end of file diff --git a/lib/text.js b/lib/text.js index 8af7eb1..a22334a 100644 --- a/lib/text.js +++ b/lib/text.js @@ -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 };