Skip to content

Commit f643582

Browse files
committed
Updates to Twilio Node
Fixes #28 Make edit panel work, and then fix it so the things edited do what they say. Slight tweak to shrink icon to similar size as others.
1 parent e5af41b commit f643582

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

social/twilio/56-twilio.html

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,32 @@
1515
limitations under the License.
1616
-->
1717

18-
<script type="text/x-red" data-template-name="twilio">
18+
<script type="text/x-red" data-template-name="twilio out">
1919
<div class="form-row">
20-
<label for="node-input-title"><i class="icon-flag"></i> Title</label>
21-
<input type="text" id="node-input-title" placeholder="Node-RED">
20+
<label for="node-input-number"><i class="icon-envelope"></i> SMS to</label>
21+
<input type="text" id="node-input-number" placeholder="01234 5678901">
2222
</div>
2323
<div class="form-row">
2424
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
2525
<input type="text" id="node-input-name" placeholder="Name">
2626
</div>
27+
<div class="form-tips">Tip - leave Number blank to use <b>msg.topic</b> to set the number.</div>
2728
</script>
2829

2930
<script type="text/x-red" data-help-name="twilio out">
30-
<p>Uses Twilio to send the <b>msg.payload</b> as a SMS to the configured number.</p>
31-
<p>Uses <b>msg.topic</b> to set the phone number, if not already set in the properties.</p>
32-
<p>You MUST configure both your Account SID and the Auth Token. Either into settings.js like this</p>
33-
<p><pre>twilio: { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN', from:'FROM-NUMBER' },</pre></p>
34-
<p>Or as a twiliokey.js file in the directory <b>above</b> node-red.<p>
35-
<p><pre>module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }</pre></p>
31+
<p>Uses Twilio to send the <b>msg.payload</b> as a SMS to the configured number.</p>
32+
<p>Uses <b>msg.topic</b> to set the phone number, if not already set in the properties.</p>
33+
<p>You MUST configure both your Account SID and the Auth Token. Either into settings.js like this</p>
34+
<p><pre>twilio: { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN', from:'FROM-NUMBER' },</pre></p>
35+
<p>Or as a twiliokey.js file in the directory <b>above</b> node-red.<p>
36+
<p><pre>module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }</pre></p>
3637
</script>
3738

3839
<script type="text/javascript">
3940
RED.nodes.registerType('twilio out',{
4041
category: 'output',
4142
defaults: {
42-
title: {value:""},
43+
number: {value:""},
4344
name: {value:""}
4445
},
4546
color:"#ed1c24",
@@ -48,7 +49,7 @@
4849
icon: "twilio.png",
4950
align: "right",
5051
label: function() {
51-
return this.name||this.title||"twilio out";
52+
return this.name||this.title||"twilio";
5253
},
5354
labelStyle: function() {
5455
return this.name?"node_label_italic":"";

social/twilio/56-twilio.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,41 @@ var util = require('util');
2424
// module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }
2525

2626
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");
2828
}
2929
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");
3131
}
3232

3333
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;
3636
}
3737

3838
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+
});
6263
}
63-
6464
RED.nodes.registerType("twilio out",TwilioOutNode);

social/twilio/icons/twilio.png

-164 Bytes
Loading

0 commit comments

Comments
 (0)