Update to now include a seperate config file
This commit is contained in:
		
							
								
								
									
										4
									
								
								lib/config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								lib/config.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| module.exports = { | ||||
| 	fromAddress:  'foo@bar.com', | ||||
| 	debugEnabled: false | ||||
| }; | ||||
							
								
								
									
										46
									
								
								lib/text.js
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								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,25 @@ 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) { | ||||
|   for (var prop in obj) { | ||||
|     if (obj.hasOwnProperty(prop)) { | ||||
|       config[prop] = obj[prop]; | ||||
|     }  | ||||
|   } | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
|   send:       sendText,     // Send a text message | ||||
|   debug:      debug         // Enable or disable debug output | ||||
|   // debug:      debug,     No longer needed, see setConfig and config.js | ||||
|   config:     setConfig     // Override default config | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user