From 04e436ae22a6b38bf9266fe82c69966ca40136ce Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Thu, 24 Nov 2016 14:31:40 -0500 Subject: [PATCH 1/3] Bump up Twilio-node version and update code --- index.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 125faf1..8ba6204 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ app.use(urlencoded({ extended: false })); // Generate a Twilio Client capability token app.get('/token', (request, response) => { - let capability = new twilio.Capability( + let capability = new twilio.jwt.Capability( process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN ); diff --git a/package.json b/package.json index b8a5110..7812597 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "body-parser": "^1.15.2", "dotenv-safe": "^3.0.0", "express": "^4.14.0", - "twilio": "^2.11.0" + "twilio": "3.0.0-rc.13" }, "devDependencies": { "chai": "^3.5.0", From 93b675fc10bf8a150f55b65b399230f291dd1a8f Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Thu, 24 Nov 2016 14:36:14 -0500 Subject: [PATCH 2/3] Bump up Twilio.js version --- public/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index f4622d2..f6d3306 100644 --- a/public/index.html +++ b/public/index.html @@ -3,7 +3,7 @@ Browser Dialer UI with React - @@ -17,10 +17,10 @@ - + - + - \ No newline at end of file + From d6d7fdcb2d6cc93a8f6002898f06d4eff50af1ff Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Thu, 4 May 2017 06:16:03 -0500 Subject: [PATCH 3/3] Bump up Twilio version to 3.0.0 --- index.js | 25 ++++++++++++++++--------- package.json | 2 +- spec/index.spec.js | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 8ba6204..76faefb 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,8 @@ const http = require('http'); const express = require('express'); const { urlencoded } = require('body-parser'); const twilio = require('twilio'); +const ClientCapability = twilio.jwt.ClientCapability; +const VoiceResponse = twilio.twiml.VoiceResponse; let app = express(); app.use(express.static(__dirname + '/public')); @@ -12,12 +14,17 @@ app.use(urlencoded({ extended: false })); // Generate a Twilio Client capability token app.get('/token', (request, response) => { - let capability = new twilio.jwt.Capability( - process.env.TWILIO_ACCOUNT_SID, - process.env.TWILIO_AUTH_TOKEN + const capability = new ClientCapability({ + accountSid: process.env.TWILIO_ACCOUNT_SID, + authToken: process.env.TWILIO_AUTH_TOKEN + }); + + capability.addScope( + new ClientCapability.OutgoingClientScope({ + applicationSid: process.env.TWILIO_TWIML_APP_SID}) ); - capability.allowClientOutgoing(process.env.TWILIO_TWIML_APP_SID); - let token = capability.generate(); + + const token = capability.toJwt();; // Include token in a JSON response response.send({ @@ -27,12 +34,12 @@ app.get('/token', (request, response) => { // Create TwiML for outbound calls app.post('/voice', (request, response) => { - let twiml = new twilio.TwimlResponse(); - twiml.dial(request.body.number, { + let voiceResponse = new VoiceResponse(); + voiceResponse.dial({ callerId: process.env.TWILIO_NUMBER - }); + }, request.body.number); response.type('text/xml'); - response.send(twiml.toString()); + response.send(voiceResponse.toString()); }); let server = http.createServer(app); diff --git a/package.json b/package.json index 7812597..0e10e88 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "body-parser": "^1.15.2", "dotenv-safe": "^3.0.0", "express": "^4.14.0", - "twilio": "3.0.0-rc.13" + "twilio": "~3.0.0" }, "devDependencies": { "chai": "^3.5.0", diff --git a/spec/index.spec.js b/spec/index.spec.js index 4ca49d7..d6302a4 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -32,3 +32,19 @@ describe('index route', function () { }); }); }); + +describe('token route', function () { + describe('GET /token', function () { + it('responds with token', function (done) { + var testApp = supertest(app); + testApp + .get('/token') + .expect(200) + .end(function(err, res) { + const jsonResponse = JSON.parse(res.text); + expect(jsonResponse.token.length).to.be.above(0); + done(); + }); + }); + }); +});