-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (41 loc) · 1.31 KB
/
index.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
56
57
58
59
60
const express = require('express');
const bodyParser = require('body-parser');
const env = require('./env');
const app = express();
var twilio = require('twilio');
var client = new twilio(env.sid, env.auth);
const VoiceResponse = twilio.twiml.VoiceResponse;
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.post('/welcome/voice', (req, res) => {
console.log('welcome');
console.log(req.body);
const voiceResponse = new VoiceResponse();
const gather = voiceResponse.gather({
action: '/ivr/menu',
numDigits: '1',
method: 'POST',
});
gather.say(
'Thanks for calling twillio test service. ' +
'Please press 1 for directions. ' +
'Press 2 for a list of planets to call.',
{ loop: 3 }
);
res.send(voiceResponse.toString());
});
app.post('/ivr/menu', (req, res) => {
console.log('menu');
console.log(req.body);
const voiceResponse = new VoiceResponse();
voiceResponse.say(
'Your Testing Code is 1214. Thank you for calling this service. Bye '
);
voiceResponse.hangup();
res.send(voiceResponse.toString());
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))