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.
This commit is contained in:
Dave C-J 2014-02-09 11:55:01 +00:00
parent e5af41ba2b
commit f64358262a
3 changed files with 40 additions and 39 deletions

View File

@ -15,31 +15,32 @@
limitations under the License. limitations under the License.
--> -->
<script type="text/x-red" data-template-name="twilio"> <script type="text/x-red" data-template-name="twilio out">
<div class="form-row"> <div class="form-row">
<label for="node-input-title"><i class="icon-flag"></i> Title</label> <label for="node-input-number"><i class="icon-envelope"></i> SMS to</label>
<input type="text" id="node-input-title" placeholder="Node-RED"> <input type="text" id="node-input-number" placeholder="01234 5678901">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label> <label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </div>
<div class="form-tips">Tip - leave Number blank to use <b>msg.topic</b> to set the number.</div>
</script> </script>
<script type="text/x-red" data-help-name="twilio out"> <script type="text/x-red" data-help-name="twilio out">
<p>Uses Twilio to send the <b>msg.payload</b> as a SMS to the configured number.</p> <p>Uses Twilio to send the <b>msg.payload</b> as a SMS to the configured number.</p>
<p>Uses <b>msg.topic</b> to set the phone number, if not already set in the properties.</p> <p>Uses <b>msg.topic</b> to set the phone number, if not already set in the properties.</p>
<p>You MUST configure both your Account SID and the Auth Token. Either into settings.js like this</p> <p>You MUST configure both your Account SID and the Auth Token. Either into settings.js like this</p>
<p><pre>twilio: { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN', from:'FROM-NUMBER' },</pre></p> <p><pre>twilio: { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN', from:'FROM-NUMBER' },</pre></p>
<p>Or as a twiliokey.js file in the directory <b>above</b> node-red.<p> <p>Or as a twiliokey.js file in the directory <b>above</b> node-red.<p>
<p><pre>module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }</pre></p> <p><pre>module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }</pre></p>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
RED.nodes.registerType('twilio out',{ RED.nodes.registerType('twilio out',{
category: 'output', category: 'output',
defaults: { defaults: {
title: {value:""}, number: {value:""},
name: {value:""} name: {value:""}
}, },
color:"#ed1c24", color:"#ed1c24",
@ -48,7 +49,7 @@
icon: "twilio.png", icon: "twilio.png",
align: "right", align: "right",
label: function() { label: function() {
return this.name||this.title||"twilio out"; return this.name||this.title||"twilio";
}, },
labelStyle: function() { labelStyle: function() {
return this.name?"node_label_italic":""; return this.name?"node_label_italic":"";

View File

@ -24,41 +24,41 @@ var util = require('util');
// module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' } // module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }
try { try {
var twiliokey = RED.settings.twilio || require(process.env.NODE_RED_HOME+"/../twiliokey.js"); var twiliokey = RED.settings.twilio || require(process.env.NODE_RED_HOME+"/../twiliokey.js");
} }
catch(err) { catch(err) {
util.log("[56-twilio.js] Error: Failed to load Twilio credentials"); util.log("[56-twilio.js] Error: Failed to load Twilio credentials");
} }
if (twiliokey) { if (twiliokey) {
var twilioClient = require('twilio')(twiliokey.account, twiliokey.authtoken); var twilioClient = require('twilio')(twiliokey.account, twiliokey.authtoken);
var fromNumber = twiliokey.from; var fromNumber = twiliokey.from;
} }
function TwilioOutNode(n) { function TwilioOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.title = n.title; this.number = n.number;
var node = this; var node = this;
this.on("input",function(msg) { this.on("input",function(msg) {
if (typeof(msg.payload) == 'object') { if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload); msg.payload = JSON.stringify(msg.payload);
} }
if (twiliokey) { if (twiliokey) {
try { try {
// Send SMS // Send SMS
twilioClient.sendMessage( {to: msg.topic, from: fromNumber, body: msg.payload}, function(err, response) { var tonum = node.number || msg.topic;
if (err) node.error(err); twilioClient.sendMessage( {to: tonum, from: fromNumber, body: msg.payload}, function(err, response) {
//console.log(response); if (err) node.error(err);
}); //console.log(response);
} });
catch (err) { }
node.error(err); catch (err) {
} node.error(err);
} }
else { }
node.warn("Twilio credentials not set/found. See node info."); else {
} node.warn("Twilio credentials not set/found. See node info.");
}); }
});
} }
RED.nodes.registerType("twilio out",TwilioOutNode); RED.nodes.registerType("twilio out",TwilioOutNode);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 553 B