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

Update Twilio to fa -icons - correct minor spelling

This commit is contained in:
Dave C-J 2014-07-27 20:09:19 +01:00
parent 434d9808a9
commit cef9e093e2
4 changed files with 98 additions and 97 deletions

View File

@ -17,22 +17,22 @@
<script type="text/x-red" data-template-name="twilio out"> <script type="text/x-red" data-template-name="twilio out">
<div class="form-row" id="node-input-credentials-row"> <div class="form-row" id="node-input-credentials-row">
<label for="node-input-creds"><i class="icon-folder-close"></i> Credentials</label> <label for="node-input-creds"><i class="fa fa-folder-o"></i> Credentials</label>
<select id="node-input-creds"> <select id="node-input-creds">
<option value="global">Use global credentials</option> <option value="global">Use global credentials</option>
<option value="local">Use local credentials</option> <option value="local">Use local credentials</option>
</select> </select>
</div> </div>
<div class="form-row" id="node-input-twilio-row"> <div class="form-row" id="node-input-twilio-row">
<label for="node-input-twilio"><i class="icon-user"></i> Twilio</label> <label for="node-input-twilio"><i class="fa fa-user"></i> Twilio</label>
<input type="text" id="node-input-twilio"> <input type="text" id="node-input-twilio">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-number"><i class="icon-envelope"></i> SMS to</label> <label for="node-input-number"><i class="fa fa-envelope-o"></i> SMS to</label>
<input type="text" id="node-input-number" placeholder="01234 5678901"> <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="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </div>
</script> </script>
@ -73,13 +73,13 @@
(function() { (function() {
var hasGlobal = false; var hasGlobal = false;
$.getJSON('twilio-api/global',function(data) { $.getJSON('twilio-api/global',function(data) {
hasGlobal = data.hasToken; hasGlobal = data.hasToken;
}); });
RED.nodes.registerType('twilio-api',{ RED.nodes.registerType('twilio-api',{
category: 'config', category: 'config',
defaults: { defaults: {
@ -98,7 +98,7 @@
} else { } else {
$('#node-config-input-token').val(''); $('#node-config-input-token').val('');
} }
}); });
}, },
oneditsave: function() { oneditsave: function() {
@ -122,7 +122,7 @@
}); });
} }
}); });
RED.nodes.registerType('twilio out',{ RED.nodes.registerType('twilio out',{
category: 'output', category: 'output',
defaults: { defaults: {

View File

@ -15,100 +15,101 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require('util'); "use strict";
var twilio = require('twilio'); var twilio = require('twilio');
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) {
}
var querystring = require('querystring');
RED.httpAdmin.get('/twilio-api/global',function(req,res) {
res.send(JSON.stringify({hasToken:!(twiliokey && twiliokey.account && twiliokey.authtoken)}));
});
RED.httpAdmin.get('/twilio-api/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({hasToken:(credentials.token&&credentials.token!="")}));
} else {
res.send(JSON.stringify({}));
} }
});
RED.httpAdmin.delete('/twilio-api/:id',function(req,res) { var querystring = require('querystring');
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/twilio-api/:id',function(req,res) { RED.httpAdmin.get('/twilio-api/global',function(req,res) {
var body = ""; res.send(JSON.stringify({hasToken:!(twiliokey && twiliokey.account && twiliokey.authtoken)}));
req.on('data', function(chunk) {
body+=chunk;
}); });
req.on('end', function(){ RED.httpAdmin.get('/twilio-api/:id',function(req,res) {
var newCreds = querystring.parse(body); var credentials = RED.nodes.getCredentials(req.params.id);
var credentials = RED.nodes.getCredentials(req.params.id)||{}; if (credentials) {
if (newCreds.token == "") { res.send(JSON.stringify({hasToken:(credentials.token&&credentials.token!=="")}));
delete credentials.token;
} else { } else {
credentials.token = newCreds.token; res.send(JSON.stringify({}));
} }
RED.nodes.addCredentials(req.params.id,credentials); });
RED.httpAdmin.delete('/twilio-api/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
});
function TwilioAPINode(n) { RED.httpAdmin.post('/twilio-api/:id',function(req,res) {
RED.nodes.createNode(this,n); var body = "";
this.sid = n.sid; req.on('data', function(chunk) {
this.from = n.from; body+=chunk;
this.name = n.name; });
var credentials = RED.nodes.getCredentials(n.id); req.on('end', function(){
if (credentials) { var newCreds = querystring.parse(body);
this.token = credentials.token; var credentials = RED.nodes.getCredentials(req.params.id)||{};
} if (newCreds.token == "") {
} delete credentials.token;
RED.nodes.registerType("twilio-api",TwilioAPINode); } else {
credentials.token = newCreds.token;
}
function TwilioOutNode(n) { RED.nodes.addCredentials(req.params.id,credentials);
RED.nodes.createNode(this,n); res.send(200);
this.number = n.number; });
this.api = RED.nodes.getNode(n.twilio);
if (this.api) {
this.twilioClient = twilio(this.api.sid,this.api.token);
this.fromNumber = this.api.from;
} else if (twiliokey) {
this.twilioClient = twilio(twiliokey.account, twiliokey.authtoken);
this.fromNumber = twiliokey.from;
} else {
this.error("missing twilio credentials");
return;
}
var node = this;
this.on("input",function(msg) {
if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload);
}
try {
// Send SMS
var tonum = node.number || msg.topic;
node.twilioClient.sendMessage( {to: tonum, from: node.fromNumber, body: msg.payload}, function(err, response) {
if (err) {
node.error(err);
}
//console.log(response);
});
} catch (err) {
node.error(err);
}
}); });
function TwilioAPINode(n) {
RED.nodes.createNode(this,n);
this.sid = n.sid;
this.from = n.from;
this.name = n.name;
var credentials = RED.nodes.getCredentials(n.id);
if (credentials) {
this.token = credentials.token;
}
}
RED.nodes.registerType("twilio-api",TwilioAPINode);
function TwilioOutNode(n) {
RED.nodes.createNode(this,n);
this.number = n.number;
this.api = RED.nodes.getNode(n.twilio);
if (this.api) {
this.twilioClient = twilio(this.api.sid,this.api.token);
this.fromNumber = this.api.from;
} else if (twiliokey) {
this.twilioClient = twilio(twiliokey.account, twiliokey.authtoken);
this.fromNumber = twiliokey.from;
} else {
this.error("missing twilio credentials");
return;
}
var node = this;
this.on("input",function(msg) {
if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload);
}
try {
// Send SMS
var tonum = node.number || msg.topic;
node.twilioClient.sendMessage( {to: tonum, from: node.fromNumber, body: msg.payload}, function(err, response) {
if (err) {
node.error(err);
}
//console.log(response);
});
} catch (err) {
node.error(err);
}
});
}
RED.nodes.registerType("twilio out",TwilioOutNode);
} }
RED.nodes.registerType("twilio out",TwilioOutNode);

View File

@ -1,5 +1,5 @@
node-red-node-pushbullet node-red-node-twilio
======================== ====================
A <a href="http://nodered.org" target="_new">Node-RED</a> node to send SMS messages via the <a href="http://twilio.com" target="_new">Twilio</a> service. A <a href="http://nodered.org" target="_new">Node-RED</a> node to send SMS messages via the <a href="http://twilio.com" target="_new">Twilio</a> service.

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-twilio", "name" : "node-red-node-twilio",
"version" : "0.0.3", "version" : "0.0.4",
"description" : "A Node-RED node to send SMS messages via the Twilio service.", "description" : "A Node-RED node to send SMS messages via the Twilio service.",
"dependencies" : { "dependencies" : {
"twilio" : "1.6.0" "twilio" : "1.6.0"