-
Notifications
You must be signed in to change notification settings - Fork 2
/
receive-call-webhook-failover.js
55 lines (49 loc) · 1.21 KB
/
receive-call-webhook-failover.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
51
52
53
54
55
'use strict';
const app = require('express')();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const server = app.listen(process.env.PORT || 4001, () => {
console.log('Express server listening on port %d in %s mode', server.address().port, app.settings.env);
});
app.get('/answer', (req, res) => {
let from = req.query.from;
let to = req.query.to;
const ncco = [
{
"action": "connect",
"timeout": 5,
"from": from,
"eventType": "synchronous",
"endpoint": [
{
"type": "sip",
"uri": "sip:[email protected]"
}
]
}
];
res.json(ncco);
});
app.post('/event', (req, res) => {
console.log(req.body);
var fallbackEvents=['timeout','failed','unanswered','busy','rejected'];
if (fallbackEvents.indexOf(req.body.status)>-1) {
const ncco = [
{
"action": "connect",
"timeout": 60,
"from": req.body.from,
"eventType": "synchronous",
"endpoint": [
{
"type": "phone",
"number": "+12065551212"
}
]
}
];
res.json(ncco);
}
else res.status(204).end();
});