mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Updated to make calls
This commit is contained in:
parent
317aaa1b64
commit
d7cee30787
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
Copyright 2013 Andrew D Lindsay @AndrewDLindsay
|
||||
Copyright 2014 Andrew D Lindsay @AndrewDLindsay
|
||||
http://blog.thiseldo.co.uk
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -27,10 +27,25 @@
|
||||
<label for="node-input-twilio"><i class="fa fa-user"></i> Twilio</label>
|
||||
<input type="text" id="node-input-twilio">
|
||||
</div>
|
||||
<div class="form-row node-input-twiliotype-row">
|
||||
<label for="node-input-twilioType"><i class="fa fa-list-ul"></i> Output</label>
|
||||
<select id="node-input-twilioType" style="width:125px !important">
|
||||
<option value="sms">SMS</option>
|
||||
<option value="call">Call</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-number"><i class="fa fa-envelope-o"></i> SMS to</label>
|
||||
<label for="node-input-number">
|
||||
<i class="fa fa-envelope-o" id="node-input-number-icon-sms"></i>
|
||||
<i class="fa fa-phone hidden" id="node-input-number-icon-call"></i>
|
||||
To</label>
|
||||
<input type="text" id="node-input-number" placeholder="01234 5678901">
|
||||
</div>
|
||||
<div class="form-row hidden" id="node-input-twiliourl-row">
|
||||
<label for="node-input-url"><i class="fa fa-globe"></i> URL</label>
|
||||
<input type="text" id="node-input-url" placeholder="http://someurl.com/twiml.xml" >
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
@ -38,9 +53,9 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="twilio out">
|
||||
<p>Sends an SMS message using the Twilio service.</p>
|
||||
<p><code>msg.payload</code> is used as the body of the message. The node can be configured with the number
|
||||
to send the message to. Alternatively, if the number is left blank, it can be set using <code>msg.topic</code>.</p>
|
||||
<p>Sends an SMS message or makes a call using the Twilio service.</p>
|
||||
<p><code>msg.payload</code> is used as either the body of the SMS message or the URL of the TWiML to create the call. The node can be configured with the number
|
||||
to send the message to. Alternatively, if the number is left blank, it can be set using <code>msg.topic</code>. If the node is configured to make a call then the URL can be entered into the node or if left blank then the <code>msg.payload</code> is used.</p>
|
||||
<p>You must have an account with Twilio to use this node. You can register for one <a href="https://www.twilio.com/">here</a>.</p>
|
||||
<p>You can either set your account details within the node, or provide it globally using either the settings file or a file
|
||||
called 'twiliokey.js' located in the directory above node-red.</p>
|
||||
@ -129,6 +144,8 @@
|
||||
twilio:{type:"twilio-api",validate:function(v) {
|
||||
return hasGlobal || (v && v!="_ADD_");
|
||||
}},
|
||||
twilioType: {value:"sms"},
|
||||
url: {value:""},
|
||||
number: {value:""},
|
||||
name: {value:""}
|
||||
},
|
||||
@ -163,6 +180,29 @@
|
||||
} else {
|
||||
$("#node-input-credentials-row").hide();
|
||||
}
|
||||
|
||||
if (this.twilioType == null) {
|
||||
if (this.url == "") {
|
||||
this.twilioType = "call";
|
||||
} else {
|
||||
this.twilioType = "sms";
|
||||
}
|
||||
}
|
||||
|
||||
$("#node-input-twilioType").change(function() {
|
||||
var twilioType = $("#node-input-twilioType option:selected").val();
|
||||
if (twilioType == "call") {
|
||||
$("#node-input-twiliourl-row").show();
|
||||
$("#node-input-number-icon-call").show();
|
||||
$("#node-input-number-icon-sms").hide();
|
||||
} else {
|
||||
$("#node-input-twiliourl-row").hide();
|
||||
$("#node-input-number-icon-call").hide();
|
||||
$("#node-input-number-icon-sms").show();
|
||||
}
|
||||
});
|
||||
$("#node-input-twilioType").val(this.twilioType);
|
||||
$("#node-input-twilioType").change();
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2013 Andrew D Lindsay @AndrewDLindsay
|
||||
* Copyright 2014 Andrew D Lindsay @AndrewDLindsay
|
||||
* http://blog.thiseldo.co.uk
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -92,20 +92,38 @@ module.exports = function(RED) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.twilioType = n.twilioType;
|
||||
this.url = n.url;
|
||||
var node = this;
|
||||
this.on("input",function(msg) {
|
||||
if (typeof(msg.payload) == 'object') {
|
||||
msg.payload = JSON.stringify(msg.payload);
|
||||
}
|
||||
try {
|
||||
// Send SMS
|
||||
// console.log("Twilio SMS or Call");
|
||||
// console.log( this.twilioType);
|
||||
// console.log("-----");
|
||||
// decide if we are to 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);
|
||||
});
|
||||
if( this.twilioType == "call" ) {
|
||||
// Make a call
|
||||
var twimlurl = node.url || msg.payload;
|
||||
node.twilioClient.makeCall( {to: tonum, from: node.fromNumber, url: twimlurl}, function(err, response) {
|
||||
if (err) {
|
||||
node.error(err);
|
||||
}
|
||||
//console.log(response);
|
||||
});
|
||||
} else {
|
||||
// Send SMS
|
||||
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);
|
||||
}
|
||||
|
@ -14,10 +14,12 @@ Run the following command in the root directory of your Node-RED install
|
||||
Usage
|
||||
-----
|
||||
|
||||
Sends an SMS message using the Twilio service.
|
||||
Sends an SMS message or make a voice call using the Twilio service.
|
||||
|
||||
The Twilio out node is configured to send SMS or make call, depending on the option selected you enter the phone number or phone number and a URL to create the TWiML response file.
|
||||
|
||||
<b>msg.payload</b> is used as the body of the message. The node can be configured with the number
|
||||
to send the message to. Alternatively, if the number is left blank, it can be set using <b>msg.topic</b>.
|
||||
to send the message to. Alternatively, if the number is left blank, it can be set using <b>msg.topic</b>. The payload can also be the URL to create the TWiML response file.
|
||||
|
||||
You must have an account with Twilio to use this node. You can register for one <a href="https://www.twilio.com/">here</a>.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user