Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
smendes committed Aug 2, 2019
1 parent 7139c84 commit ea62fc9
Show file tree
Hide file tree
Showing 702 changed files with 1,128 additions and 60,945 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
node_modules

lib-cov
*.seed
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
> # :warning: Important :warning:
> This repository is deprecated at the moment.
> Please check out the [Twilio Docs](https://www.twilio.com/docs/tutorials?order_by=-popularity_rank&filter-language=node) for a set of getting started guides for now.
>
> :books: https://www.twilio.com/docs/tutorials?order_by=-popularity_rank&filter-language=node
# Welcome to the JavaScript Guild!

As members of the JavaScript guild, you will be working through the challenges of TwilioQuest using server-side JavaScript, specifically [node.js](http://www.nodejs.org). This project is pre-configured to do some interesting Twilio stuff using node.js and the [Express](http://expressjs.com/) web framework.
Expand All @@ -12,23 +6,23 @@ As members of the JavaScript guild, you will be working through the challenges o

We assume that before you begin, you will have [node.js and npm](http://www.nodejs.org) and installed on your system. Before you can run this project, you will need to set three system environment variables. These are:

* `TWILIO_ACCOUNT_SID` : Your Twilio "account SID" - it's like your username for the Twilio API. This and the auth token (below) can be found [on your account dashboard](https://www.twilio.com/user/account).
* `TWILIO_AUTH_TOKEN` : Your Twilio "auth token" - it's your password for the Twilio API. This and the account SID (above) can be found [on your account dashboard](https://www.twilio.com/user/account).
* `TWILIO_NUMBER` : A Twilio number that you own, that can be used for making calls and sending messages. You can find a list of phone numbers you control (and buy another one, if necessary) [in the account portal](https://www.twilio.com/user/account/phone-numbers/incoming).
* `TWILIO_ACCOUNT_SID` : Your Twilio "account SID" - it's like your username for the Twilio API. This and the auth token (below) can be found [on the console](https://www.twilio.com/console).
* `TWILIO_AUTH_TOKEN` : Your Twilio "auth token" - it's your password for the Twilio API. This and the account SID (above) can be found [on the console](https://www.twilio.com/console).
* `TWILIO_PHONE_NUMBER` : A Twilio number that you own, that can be used for making calls and sending messages. You can find a list of phone numbers you control (and buy another one, if necessary) [in the console](https://www.twilio.com/console/phone-numbers/incoming).

For Mac and Linux, environment variables can be set by opening a terminal window and typing the following three commands - replace all the characters after the `=` with values from your Twilio account:

export TWILIO_ACCOUNT_SID=ACXXXXXXXXX
export TWILIO_AUTH_TOKEN=XXXXXXXXX
export TWILIO_NUMBER=+16518675309
export TWILIO_PHONE_NUMBER=+16518675309

To make these changes persist for every new terminal (on OS X), you can edit the file `~/.bash_profile` to contain the three commands above. This will set these environment variables for every subsequent session. Once you have edited the file to contain these commands, run `source ~/.bash_profile` in the terminal to set up these variables.

On Windows, the easiest way to set permanent environment variables (as of Windows 8) is using the `setx` command. Note that there is no `=`, just the key and value separated by a space:

setx TWILIO_ACCOUNT_SID ACXXXXXXXXX
setx TWILIO_AUTH_TOKEN XXXXXXXXX
setx TWILIO_NUMBER +16518675309
setx TWILIO_PHONE_NUMBER +16518675309

## Running the application

Expand All @@ -38,7 +32,7 @@ You will first need to install the application's dependencies. You can do this

npm install

Now, you should be able to launch the application. From your terminal, run `node app.js`. This should launch your Express application on port 3000 - [visit that URL on your local host](http://localhost:3000/). Enter your mobile number in the fields provided, and test both SMS text messages and phone calls being sent to the mobile number you provide.
Now, you should be able to launch the application. From your terminal, run `npm start`. This should launch your Express application on port 3000 - [visit that URL on your local host](http://localhost:3000/). Enter your mobile number in the fields provided, and test both SMS text messages and phone calls being sent to the mobile number you provide.



Expand Down
130 changes: 69 additions & 61 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,92 @@
// Load app dependencies
var http = require('http'),
path = require('path'),
express = require('express'),
twilio = require('twilio');
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var twilio = require('twilio');

// Load configuration information from system environment variables.
var TWILIO_ACCOUNT_SID = process.env.TWILIO_ACCOUNT_SID,
TWILIO_AUTH_TOKEN = process.env.TWILIO_AUTH_TOKEN,
TWILIO_NUMBER = process.env.TWILIO_NUMBER;
TWILIO_PHONE_NUMBER = process.env.TWILIO_PHONE_NUMBER;

// Create an authenticated client to access the Twilio REST API
var client = twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);

// Create an Express web application with some basic configuration
var app = express();

app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.configure('development', function(){
app.use(express.errorHandler());
});
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// render our home page
app.get('/', function(request, response) {
response.render('index');
app.get('/', function(req, res, next) {
res.render('index');
});

// handle a POST request to send a text message. This is sent via ajax on our
// home page
app.post('/message', function(request, response) {
// Use the REST client to send a text message
client.sendSms({
to: request.param('to'),
from: TWILIO_NUMBER,
body: 'Good luck on your Twilio quest!'
}, function(err, data) {
// When we get a response from Twilio, respond to the HTTP POST request
response.send('Message is inbound!');
});
// handle a POST request to send a text message.
// This is sent via ajax on our home page
app.post('/message', function(req, res, next) {
// Use the REST client to send a text message
client.messages.create({
to: req.body.to,
from: TWILIO_PHONE_NUMBER,
body: 'Good luck on your Twilio quest!'
}).then(function(message) {
// When we get a response from Twilio, respond to the HTTP POST request
res.send('Message is inbound!');
});
});

// handle a POST request to make an outbound call. This is sent via ajax on our
// home page
app.post('/call', function(request, response) {
// Use the REST client to send a text message
client.makeCall({
to: request.param('to'),
from: TWILIO_NUMBER,
url: 'http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3'
}, function(err, data) {
// When we get a response from Twilio, respond to the HTTP POST request
response.send('Call incoming!');
});
// handle a POST request to make an outbound call.
// This is sent via ajax on our home page
app.post('/call', function(req, res, next) {
// Use the REST client to send a text message
client.calls.create({
to: req.body.to,
from: TWILIO_PHONE_NUMBER,
url: 'http://demo.twilio.com/docs/voice.xml'
}).then(function(message) {
// When we get a response from Twilio, respond to the HTTP POST request
res.send('Call incoming!');
});
});

// Create a TwiML document to provide instructions for an outbound call
app.get('/hello', function(request, response) {
// Create a TwiML generator
var twiml = new twilio.TwimlResponse();
twiml.say('Hello there! You have successfully configured a web hook.');
twiml.say('Good luck on your Twilio quest!', {
voice:'woman'
});
app.get('/hello', function(req, res, next) {
// Create a TwiML generator
var twiml = new twilio.twiml.VoiceResponse();
// var twiml = new twilio.TwimlResponse();
twiml.say('Hello there! You have successfully configured a web hook.');
twiml.say('Good luck on your Twilio quest!', {
voice:'woman'
});

// Return an XML response to this request
res.set('Content-Type','text/xml');
res.send(twiml.toString());
});

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// Return an XML response to this request
response.set('Content-Type','text/xml');
response.send(twiml.toString());
// render the error page
res.status(err.status || 500);
res.render('error');
});

// Start our express app, by default on port 3000
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('starter-node:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
1 change: 0 additions & 1 deletion node_modules/.bin/express

This file was deleted.

Empty file removed node_modules/ejs/.gitmodules
Empty file.
4 changes: 0 additions & 4 deletions node_modules/ejs/.npmignore

This file was deleted.

7 changes: 0 additions & 7 deletions node_modules/ejs/.travis.yml

This file was deleted.

Loading

0 comments on commit ea62fc9

Please sign in to comment.