-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jaume Miralles
committed
Jul 20, 2016
1 parent
406e05b
commit 52ca668
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!-- Sample html file that corresponds to the 99-sample.js file --> | ||
<!-- This creates and configures the onscreen elements of the node --> | ||
|
||
<!-- If you use this as a template, update the copyright with your own name. --> | ||
|
||
<!-- First, the content of the edit dialog is defined. --> | ||
|
||
<script type="text/x-red" data-template-name="twilio-record"> | ||
|
||
<div class="form-row"> | ||
<label for="node-input-creds"> Credentials</label> | ||
<input type="text" id="node-input-creds"> | ||
</div> | ||
|
||
|
||
<!-- By convention, most nodes have a 'name' property. The following div --> | ||
<!-- provides the necessary field. Should always be the last option --> | ||
<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 of this Event"> | ||
</div> | ||
|
||
|
||
</script> | ||
|
||
|
||
<!-- Next, some simple help text is provided for the node. --> | ||
<script type="text/x-red" data-help-name="twilio-record"> | ||
|
||
|
||
</script> | ||
|
||
<!-- Finally, the node type is registered along with all of its properties --> | ||
<!-- The example below shows a small subset of the properties that can be set--> | ||
<script type="text/javascript"> | ||
RED.nodes.registerType('twilio-record',{ | ||
category: 'Twilio', | ||
defaults: { | ||
creds: {value:"", type:"twilio-connection"}, | ||
name: {value:""} | ||
|
||
}, | ||
inputs:1, // set the number of inputs - only 0 or 1 | ||
outputs:1, // set the number of outputs - 0 to n | ||
icon: "twilio.png", // saved in icons/myicon.png | ||
color: "#FF595F", | ||
label: function() { | ||
return this.name || "Record"; | ||
}, | ||
paletteLabel: "Record" | ||
|
||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var twilio = require('twilio'); | ||
|
||
var _internals = {}; | ||
|
||
_internals.record = function (payload, creds, cb) { | ||
|
||
var resp = new twilio.TwimlResponse(); | ||
|
||
resp.record(); | ||
|
||
cb(null, resp.toString()); | ||
|
||
}; | ||
|
||
|
||
module.exports = function(RED) { | ||
'use strict'; | ||
|
||
function Node(n) { | ||
|
||
RED.nodes.createNode(this,n); | ||
|
||
var node = this; | ||
|
||
this.on('input', function (msg) { | ||
|
||
var creds = RED.nodes.getNode(n.creds); | ||
|
||
var payload = typeof msg.payload === 'object' ? msg.payload : {}; | ||
|
||
var attrs = []; | ||
for (var attr of attrs) { | ||
if (n[attr]) { | ||
payload[attr] = n[attr]; | ||
} | ||
} | ||
|
||
_internals.say(payload, creds, function(err, result){ | ||
|
||
msg.payload = result; | ||
node.log(JSON.stringify(err)); | ||
node.log(JSON.stringify(result)); | ||
node.send(msg); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
RED.nodes.registerType('twilio-record', Node); | ||
}; |