forked from TwilioDevEd/client-quickstart-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
287 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
TWILIO_AUTH_TOKEN=your_auth_token | ||
TWILIO_TWIML_APP_SID=APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
TWILIO_CALLER_ID=+1XXXYYYZZZZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
public/**/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extends: google | ||
parserOptions: | ||
ecmaVersion: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
npm-debug.log | ||
config.js | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
node_js: | ||
- 'stable' | ||
env: | ||
global: | ||
- TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
- TWILIO_AUTH_TOKEN=your_auth_token | ||
- TWILIO_TWIML_APP_SID=APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
- TWILIO_CALLER_ID=+1XXXYYYZZZZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const dotenv = require('dotenv'); | ||
const cfg = {}; | ||
|
||
if (process.env.NODE_ENV !== 'test') { | ||
dotenv.config({path: '.env'}); | ||
} else { | ||
dotenv.config({path: '.env.example', silent: true}); | ||
} | ||
|
||
// HTTP Port to run our web application | ||
cfg.port = process.env.PORT || 3000; | ||
|
||
// Your Twilio account SID and auth token, both found at: | ||
// https://www.twilio.com/user/account | ||
// | ||
// A good practice is to store these string values as system environment | ||
// variables, and load them from there as we are doing below. Alternately, | ||
// you could hard code these values here as strings. | ||
cfg.accountSid = process.env.TWILIO_ACCOUNT_SID; | ||
cfg.authToken = process.env.TWILIO_AUTH_TOKEN; | ||
|
||
cfg.twimlAppSid = process.env.TWILIO_TWIML_APP_SID; | ||
cfg.callerId = process.env.TWILIO_CALLER_ID; | ||
|
||
// Export configuration object | ||
module.exports = cfg; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,21 @@ | ||
var http = require('http'); | ||
var path = require('path'); | ||
var ClientCapability = require('twilio').jwt.ClientCapability; | ||
var VoiceResponse = require('twilio').twiml.VoiceResponse; | ||
var express = require('express'); | ||
var bodyParser = require('body-parser'); | ||
var randomUsername = require('./randos'); | ||
var config = require('./config'); | ||
const http = require('http'); | ||
const path = require('path'); | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
|
||
const router = require('./src/router'); | ||
|
||
// Create Express webapp | ||
var app = express(); | ||
const app = express(); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
/* | ||
Generate a Capability Token for a Twilio Client user - it generates a random | ||
username for the client requesting a token. | ||
*/ | ||
app.get('/token', function(request, response) { | ||
var identity = randomUsername(); | ||
var capability = new ClientCapability({ | ||
accountSid: config.TWILIO_ACCOUNT_SID, | ||
authToken: config.TWILIO_AUTH_TOKEN | ||
}); | ||
|
||
capability.addScope(new ClientCapability.IncomingClientScope(identity)); | ||
capability.addScope(new ClientCapability.OutgoingClientScope({ | ||
applicationSid: config.TWILIO_TWIML_APP_SID, | ||
clientName: identity | ||
})); | ||
|
||
// Include identity and token in a JSON response | ||
response.send({ | ||
identity: identity, | ||
token: capability.toJwt() | ||
}); | ||
}); | ||
app.use(bodyParser.urlencoded({extended: false})); | ||
|
||
app.post('/voice', function (req, res) { | ||
// Create TwiML response | ||
var twiml = new VoiceResponse(); | ||
|
||
if(req.body.To) { | ||
twiml.dial({ callerId: config.TWILIO_CALLER_ID}, function() { | ||
// wrap the phone number or client name in the appropriate TwiML verb | ||
// by checking if the number given has only digits and format symbols | ||
if (/^[\d\+\-\(\) ]+$/.test(req.body.To)) { | ||
this.number(req.body.To); | ||
} else { | ||
this.client(req.body.To); | ||
} | ||
}); | ||
} else { | ||
twiml.say("Thanks for calling!"); | ||
} | ||
|
||
res.set('Content-Type', 'text/xml'); | ||
res.send(twiml.toString()); | ||
}); | ||
app.use(router); | ||
|
||
// Create http server and run it | ||
var server = http.createServer(app); | ||
var port = process.env.PORT || 3000; | ||
const server = http.createServer(app); | ||
const port = process.env.PORT || 3000; | ||
|
||
server.listen(port, function() { | ||
console.log('Express server running on *:' + port); | ||
console.log('Express server running on *:' + port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const ADJECTIVES = [ | ||
'Abrasive', 'Brash', 'Callous', 'Daft', 'Eccentric', 'Fiesty', 'Golden', | ||
'Holy', 'Ignominious', 'Joltin', 'Killer', 'Luscious', 'Mushy', 'Nasty', | ||
'OldSchool', 'Pompous', 'Quiet', 'Rowdy', 'Sneaky', 'Tawdry', | ||
'Unique', 'Vivacious', 'Wicked', 'Xenophobic', 'Yawning', 'Zesty', | ||
]; | ||
|
||
const FIRST_NAMES = [ | ||
'Anna', 'Bobby', 'Cameron', 'Danny', 'Emmett', 'Frida', 'Gracie', 'Hannah', | ||
'Isaac', 'Jenova', 'Kendra', 'Lando', 'Mufasa', 'Nate', 'Owen', 'Penny', | ||
'Quincy', 'Roddy', 'Samantha', 'Tammy', 'Ulysses', 'Victoria', 'Wendy', | ||
'Xander', 'Yolanda', 'Zelda', | ||
]; | ||
|
||
const LAST_NAMES = [ | ||
'Anchorage', 'Berlin', 'Cucamonga', 'Davenport', 'Essex', 'Fresno', | ||
'Gunsight', 'Hanover', 'Indianapolis', 'Jamestown', 'Kane', 'Liberty', | ||
'Minneapolis', 'Nevis', 'Oakland', 'Portland', 'Quantico', 'Raleigh', | ||
'SaintPaul', 'Tulsa', 'Utica', 'Vail', 'Warsaw', 'XiaoJin', 'Yale', | ||
'Zimmerman', | ||
]; | ||
|
||
const rand = (arr) => arr[Math.floor(Math.random() * arr.length)]; | ||
|
||
module.exports = () => rand(ADJECTIVES) + rand(FIRST_NAMES) + rand(LAST_NAMES); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.