-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (43 loc) · 1.36 KB
/
Copy pathapp.js
File metadata and controls
56 lines (43 loc) · 1.36 KB
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
51
52
53
54
55
56
var bodyParser = require('body-parser');
var twilio = require('twilio');
var express = require('express');
var request = require('request');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/testing', function(req, res) {
if (twilio.validateExpressRequest(req, '004590a64e03f78e2d70d05aa2c3b847')) {
var twiml = new twilio.TwimlResponse();
var charArray = req.body.Digits.match(/.{1,3}/g);
for(var i=0; i<charArray.length; i++) {
charArray[i] = String.fromCharCode(charArray[i]);
}
var url = 'http://' + charArray.join('');
request(url, function (error, response, body) {
var str = body;
for (var i = 0; i < str.length; ++i) {
var v = str.charCodeAt(i);
if(v < 100) {
v = "0" + v;
}
twiml.play({digits: v});
}
res.type('text/xml');
res.send(twiml.toString());
});
}
});
app.post('/respondToVoiceCall', function(req, res) {
if (twilio.validateExpressRequest(req, '004590a64e03f78e2d70d05aa2c3b847')) {
var twiml = new twilio.TwimlResponse();
twiml.gather({
action: "http://severn.me:3464/testing",
timeout: 7,
finishOnKey:'*'
}, function(node) {
});
res.type('text/xml');
res.send(twiml.toString());
}
});
app.listen(3464);