Skip to content

Commit e25db01

Browse files
smendesjoliveros
authored andcommitted
Update twilio-node to 3.0.0-rc.16
1 parent 6e2d000 commit e25db01

File tree

33 files changed

+125
-129
lines changed

33 files changed

+125
-129
lines changed

client/response-twiml-client/response-twiml-client.3.x.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22
const http = require('http');
33
const express = require('express');
44
const bodyParser = require('body-parser');
5-
const twilio = require('twilio');
5+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
66

77
const app = express();
88
app.use(bodyParser.urlencoded({extended: false}));
99

1010
app.post('/voice', (req, res) => {
1111
// Create TwiML response
12-
const twiml = new twilio.TwimlResponse();
12+
const twiml = new VoiceResponse();
1313

1414
if (req.body.To) {
15-
twiml.dial({callerId: '+15017250604'}, function() {
16-
// wrap the phone number or client name in the appropriate TwiML verb
17-
// by checking if the number given has only digits and format symbols
18-
if (/^[\d\+\-\(\) ]+$/.test(req.body.To)) {
19-
this.number(req.body.To);
20-
} else {
21-
this.client(req.body.To);
22-
}
23-
});
15+
const dial = twiml.dial({callerId: '+15017250604'});
16+
// wrap the phone number or client name in the appropriate TwiML verb
17+
// by checking if the number given has only digits and format symbols
18+
if (/^[\d\+\-\(\) ]+$/.test(req.body.To)) {
19+
dial.number(req.body.To);
20+
} else {
21+
dial.client(req.body.To);
22+
}
2423
} else {
2524
twiml.say('Thanks for calling!');
2625
}

client/response-twiml-dial/response-twiml-dial.3.x.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
const http = require('http');
22
const express = require('express');
33
const bodyParser = require('body-parser');
4-
const twilio = require('twilio');
4+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
55

66
const app = express();
77
app.use(bodyParser.urlencoded({extended: false}));
88

99
app.post('/voice', (req, res) => {
1010
// Create TwiML response
11-
const twiml = new twilio.TwimlResponse();
11+
const twiml = new VoiceResponse();
1212

1313
if (req.body.To) {
14-
twiml.dial({callerId: '+15017250604'}, function() {
15-
this.number(req.body.To);
16-
});
14+
const dial = twiml.dial({callerId: '+15017250604'});
15+
dial.number(req.body.To);
1716
} else {
1817
twiml.say('Thanks for calling!');
1918
}

client/response-twiml/response-twiml.3.x.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const http = require('http');
22
const express = require('express');
3-
const twilio = require('twilio');
3+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
44

55
const app = express();
66

77
app.post('/voice', (req, res) => {
88
// Create TwiML response
9-
const twiml = new twilio.TwimlResponse(); // FIXME: hows the class now?
9+
const twiml = new VoiceResponse();
1010
twiml.say('Thanks for calling!');
1111

1212
res.set('Content-Type', 'text/xml');

guides/request-validation-express/example-1/example-1.3.x.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
const twilio = require('twilio');
99
const app = require('express')();
1010
const bodyParser = require('body-parser');
11-
const TwimlResponse = twilio.TwimlResponse;
11+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
12+
const MessagingResponse = require('twilio').twiml.MessagingResponse;
1213

1314
app.use(bodyParser.urlencoded({extended: false}));
1415

1516
app.post('/voice', twilio.webhook(), (req, res) => {
1617
// Twilio Voice URL - receives incoming calls from Twilio
17-
const response = new TwimlResponse();
18+
const response = new VoiceResponse();
1819

1920
response.say(
2021
`Thanks for calling!
@@ -28,7 +29,7 @@ app.post('/voice', twilio.webhook(), (req, res) => {
2829

2930
app.post('/message', twilio.webhook(), (req, res) => {
3031
// Twilio Messaging URL - receives incoming messages from Twilio
31-
const response = new TwimlResponse();
32+
const response = new MessagingResponse();
3233

3334
response.message(`Your text to me was ${req.body.Body.length} characters long.
3435
Webhooks are neat :)`);

guides/request-validation-express/example-2/example-2.3.x.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
const twilio = require('twilio');
99
const app = require('express')();
1010
const bodyParser = require('body-parser');
11-
const TwimlResponse = twilio.TwimlResponse;
11+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
12+
const MessagingResponse = require('twilio').twiml.MessagingResponse;
1213

1314
const shouldValidate = process.env.NODE_ENV !== 'test';
1415

1516
app.use(bodyParser.urlencoded({extended: false}));
1617

1718
app.post('/voice', twilio.webhook({validate: shouldValidate}), (req, res) => {
1819
// Twilio Voice URL - receives incoming calls from Twilio
19-
const response = new TwimlResponse();
20+
const response = new VoiceResponse();
2021

2122
response.say(
2223
`Thanks for calling!
@@ -30,7 +31,7 @@ app.post('/voice', twilio.webhook({validate: shouldValidate}), (req, res) => {
3031

3132
app.post('/message', twilio.webhook({validate: shouldValidate}), (req, res) => {
3233
// Twilio Messaging URL - receives incoming messages from Twilio
33-
const response = new TwimlResponse();
34+
const response = new MessagingResponse();
3435

3536
response.message(`Your text to me was ${req.body.Body.length} characters long.
3637
Webhooks are neat :)`);

guides/voice/conference-calls-guide/moderated-conference/moderated-conference.3.x.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
const express = require('express');
3-
const twilio = require('twilio');
4-
const VoiceResponse = twilio.twiml.VoiceResponse;
3+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
54
const urlencoded = require('body-parser').urlencoded;
65

76
// Update with your own phone number in E.164 format
@@ -19,21 +18,20 @@ app.post('/voice', (request, response) => {
1918
const twiml = new VoiceResponse();
2019

2120
// Start with a <Dial> verb
22-
twiml.dial((dialNode) => {
23-
// If the caller is our MODERATOR, then start the conference when they
24-
// join and end the conference when they leave
25-
if(request.body.From == MODERATOR) {
26-
dialNode.conference('My conference', {
27-
startConferenceOnEnter: true,
28-
endConferenceOnExit: true,
29-
});
30-
} else {
31-
// Otherwise have the caller join as a regular participant
32-
dialNode.conference('My conference', {
33-
startConferenceOnEnter: false,
34-
});
35-
}
36-
});
21+
const dial = twiml.dial();
22+
// If the caller is our MODERATOR, then start the conference when they
23+
// join and end the conference when they leave
24+
if(request.body.From == MODERATOR) {
25+
dial.conference('My conference', {
26+
startConferenceOnEnter: true,
27+
endConferenceOnExit: true,
28+
});
29+
} else {
30+
// Otherwise have the caller join as a regular participant
31+
dial.conference('My conference', {
32+
startConferenceOnEnter: false,
33+
});
34+
}
3735

3836
// Render the response as XML in reply to the webhook request
3937
response.type('text/xml');

guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.3.x.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
const express = require('express');
3-
const twilio = require('twilio');
3+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
44
const urlencoded = require('body-parser').urlencoded;
55

66
const app = express();
@@ -12,12 +12,11 @@ app.use(urlencoded({extended: false}));
1212
// HTTP POST to /voice in our application
1313
app.post('/voice', (request, response) => {
1414
// Use the Twilio Node.js SDK to build an XML response
15-
const twiml = new twilio.TwimlResponse();
15+
const twiml = new VoiceResponse();
1616

1717
// Use the <Gather> verb to collect user input
18-
twiml.gather({numDigits: 1}, (gatherNode) => {
19-
gatherNode.say('For sales, press 1. For support, press 2.');
20-
});
18+
const gather = twiml.gather({numDigits: 1});
19+
gather.say('For sales, press 1. For support, press 2.');
2120

2221
// If the user doesn't enter input, loop
2322
twiml.redirect('/voice');

guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.3.x.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
app.post('/voice', (request, response) => {
22
// Use the Twilio Node.js SDK to build an XML response
3-
const twiml = new twilio.TwimlResponse();
3+
const twiml = new VoiceResponse();
44

55
/** helper function to set up a <Gather> */
66
function gather() {
7-
twiml.gather({numDigits: 1}, (gatherNode) => {
8-
gatherNode.say('For sales, press 1. For support, press 2.');
9-
});
7+
const gatherNode = twiml.gather({numDigits: 1});
8+
gatherNode.say('For sales, press 1. For support, press 2.');
109

1110
// If the user doesn't enter input, loop
1211
twiml.redirect('/voice');

guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.3.x.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// HTTP POST to /voice in our application
33
app.post('/voice', (request, response) => {
44
// Use the Twilio Node.js SDK to build an XML response
5-
const twiml = new twilio.TwimlResponse();
5+
const twiml = new VoiceResponse();
66

7-
twiml.gather({
7+
const gather = twiml.gather({
88
numDigits: 1,
99
action: '/gather',
10-
}, (gatherNode) => {
11-
gatherNode.say('For sales, press 1. For support, press 2.');
1210
});
11+
gather.say('For sales, press 1. For support, press 2.');
1312

1413
// If the user doesn't enter input, loop
1514
twiml.redirect('/voice');
@@ -22,7 +21,7 @@ app.post('/voice', (request, response) => {
2221
// Create a route that will handle <Gather> input
2322
app.post('/gather', (request, response) => {
2423
// Use the Twilio Node.js SDK to build an XML response
25-
const twiml = new twilio.TwimlResponse();
24+
const twiml = new VoiceResponse();
2625

2726
// If the user entered digits, process their request
2827
if (request.body.Digits) {

guides/voice/record-calls-guide/record-twiml-transcribe/example.3.x.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
const express = require('express');
3-
const twilio = require('twilio');
3+
const VoiceResponse = require('twilio').twiml.VoiceResponse;
44

55
const app = express();
66

77
// Returns TwiML which prompts the caller to record a message
88
app.post('/record', (request, response) => {
99
// Use the Twilio Node.js SDK to build an XML response
10-
const twiml = new twilio.TwimlResponse();
10+
const twiml = new VoiceResponse();
1111
twiml.say('Hello. Please leave a message after the beep.');
1212

1313
// Use <Record> to record and transcribe the caller's message

0 commit comments

Comments
 (0)