@@ -24,41 +24,41 @@ var util = require('util');
24
24
// module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }
25
25
26
26
try {
27
- var twiliokey = RED . settings . twilio || require ( process . env . NODE_RED_HOME + "/../twiliokey.js" ) ;
27
+ var twiliokey = RED . settings . twilio || require ( process . env . NODE_RED_HOME + "/../twiliokey.js" ) ;
28
28
}
29
29
catch ( err ) {
30
- util . log ( "[56-twilio.js] Error: Failed to load Twilio credentials" ) ;
30
+ util . log ( "[56-twilio.js] Error: Failed to load Twilio credentials" ) ;
31
31
}
32
32
33
33
if ( twiliokey ) {
34
- var twilioClient = require ( 'twilio' ) ( twiliokey . account , twiliokey . authtoken ) ;
35
- var fromNumber = twiliokey . from ;
34
+ var twilioClient = require ( 'twilio' ) ( twiliokey . account , twiliokey . authtoken ) ;
35
+ var fromNumber = twiliokey . from ;
36
36
}
37
37
38
38
function TwilioOutNode ( n ) {
39
- RED . nodes . createNode ( this , n ) ;
40
- this . title = n . title ;
41
- var node = this ;
42
- this . on ( "input" , function ( msg ) {
43
- if ( typeof ( msg . payload ) == 'object' ) {
44
- msg . payload = JSON . stringify ( msg . payload ) ;
45
- }
46
- if ( twiliokey ) {
47
- try {
48
- // Send SMS
49
- twilioClient . sendMessage ( { to : msg . topic , from : fromNumber , body : msg . payload } , function ( err , response ) {
50
- if ( err ) node . error ( err ) ;
51
- //console.log(response);
52
- } ) ;
53
- }
54
- catch ( err ) {
55
- node . error ( err ) ;
56
- }
57
- }
58
- else {
59
- node . warn ( "Twilio credentials not set/found. See node info." ) ;
60
- }
61
- } ) ;
39
+ RED . nodes . createNode ( this , n ) ;
40
+ this . number = n . number ;
41
+ var node = this ;
42
+ this . on ( "input" , function ( msg ) {
43
+ if ( typeof ( msg . payload ) == 'object' ) {
44
+ msg . payload = JSON . stringify ( msg . payload ) ;
45
+ }
46
+ if ( twiliokey ) {
47
+ try {
48
+ // Send SMS
49
+ var tonum = node . number || msg . topic ;
50
+ twilioClient . sendMessage ( { to : tonum , from : fromNumber , body : msg . payload } , function ( err , response ) {
51
+ if ( err ) node . error ( err ) ;
52
+ //console.log(response);
53
+ } ) ;
54
+ }
55
+ catch ( err ) {
56
+ node . error ( err ) ;
57
+ }
58
+ }
59
+ else {
60
+ node . warn ( "Twilio credentials not set/found. See node info." ) ;
61
+ }
62
+ } ) ;
62
63
}
63
-
64
64
RED . nodes . registerType ( "twilio out" , TwilioOutNode ) ;
0 commit comments