1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

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.
-->
<script type="text/x-red" data-template-name="twilio">
<script type="text/x-red" data-template-name="twilio out">
<div class="form-row">
<label for="node-input-title"><i class="icon-flag"></i> Title</label>
<input type="text" id="node-input-title" placeholder="Node-RED">
<label for="node-input-number"><i class="icon-envelope"></i> SMS to</label>
<input type="text" id="node-input-number" placeholder="01234 5678901">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips">Tip - leave Number blank to use <b>msg.topic</b> to set the number.</div>
</script>
<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 <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><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><pre>module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }</pre></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>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>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>
</script>
<script type="text/javascript">
RED.nodes.registerType('twilio out',{
category: 'output',
defaults: {
title: {value:""},
number: {value:""},
name: {value:""}
},
color:"#ed1c24",
@ -48,7 +49,7 @@
icon: "twilio.png",
align: "right",
label: function() {
return this.name||this.title||"twilio out";
return this.name||this.title||"twilio";
},
labelStyle: function() {
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' }
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) {
util.log("[56-twilio.js] Error: Failed to load Twilio credentials");
util.log("[56-twilio.js] Error: Failed to load Twilio credentials");
}
if (twiliokey) {
var twilioClient = require('twilio')(twiliokey.account, twiliokey.authtoken);
var fromNumber = twiliokey.from;
var twilioClient = require('twilio')(twiliokey.account, twiliokey.authtoken);
var fromNumber = twiliokey.from;
}
function TwilioOutNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var node = this;
this.on("input",function(msg) {
if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload);
}
if (twiliokey) {
try {
// Send SMS
twilioClient.sendMessage( {to: msg.topic, from: fromNumber, body: msg.payload}, function(err, response) {
if (err) node.error(err);
//console.log(response);
});
}
catch (err) {
node.error(err);
}
}
else {
node.warn("Twilio credentials not set/found. See node info.");
}
});
RED.nodes.createNode(this,n);
this.number = n.number;
var node = this;
this.on("input",function(msg) {
if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload);
}
if (twiliokey) {
try {
// Send SMS
var tonum = node.number || msg.topic;
twilioClient.sendMessage( {to: tonum, from: fromNumber, body: msg.payload}, function(err, response) {
if (err) node.error(err);
//console.log(response);
});
}
catch (err) {
node.error(err);
}
}
else {
node.warn("Twilio credentials not set/found. See node info.");
}
});
}
RED.nodes.registerType("twilio out",TwilioOutNode);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 553 B