-
Notifications
You must be signed in to change notification settings - Fork 1
/
twilio-record.js
50 lines (31 loc) · 1.09 KB
/
twilio-record.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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.record(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);
};