File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
rest/voice/generate-twiml-say Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change 1
- const http = require ( 'http ' ) ;
1
+ const express = require ( 'express ' ) ;
2
2
const VoiceResponse = require ( 'twilio' ) . twiml . VoiceResponse ;
3
3
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
7
10
const twiml = new VoiceResponse ( ) ;
8
11
9
12
twiml . say ( 'Hello from your pals at Twilio! Have fun.' ) ;
10
13
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
+ } ) ;
15
23
16
- console . log ( 'TwiML server running at http://127.0.0.1:1337/' ) ;
You can’t perform that action at this time.
0 commit comments