Skip to content

Commit 2d47bdc

Browse files
authored
Merge pull request #9 from twilio-samples/DEVED-12087
[DEVED-12087] Update TwiML Say Node.js to use Express.js
2 parents 4fd7569 + 4bc0b17 commit 2d47bdc

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

rest/voice/generate-twiml-say/generate-twiml-say.5.x.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
const http = require('http');
1+
const express = require('express');
22
const VoiceResponse = require('twilio').twiml.VoiceResponse;
33

4-
http
5-
.createServer((req, res) => {
6-
// Create TwiML response
4+
const app = express();
5+
6+
// Create a route that will handle Twilio webhook requests, sent as an
7+
// HTTP POST to /voice in our application
8+
app.post('/voice', (request, response) => {
9+
// Use the Twilio Node.js SDK to build an XML response
710
const twiml = new VoiceResponse();
811

912
twiml.say('Hello from your pals at Twilio! Have fun.');
1013

11-
res.writeHead(200, { 'Content-Type': 'text/xml' });
12-
res.end(twiml.toString());
13-
})
14-
.listen(1337, '127.0.0.1');
14+
// Render the response as XML in reply to the webhook request
15+
response.type('text/xml');
16+
response.send(twiml.toString());
17+
});
18+
19+
// Create an HTTP server and listen for requests on port 1337
20+
app.listen(1337, () => {
21+
console.log('TwiML server running at http://127.0.0.1:1337/');
22+
});
1523

16-
console.log('TwiML server running at http://127.0.0.1:1337/');

0 commit comments

Comments
 (0)