Skip to content

Commit

Permalink
Add final build
Browse files Browse the repository at this point in the history
  • Loading branch information
cbetta committed Feb 22, 2017
1 parent 45a10ae commit a2b3773
Show file tree
Hide file tree
Showing 622 changed files with 152 additions and 98,359 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NEXMO_API_KEY=
NEXMO_API_SECRET=
NEXMO_APP_ID=
NEXMO_APP_FILE_NAME=
CALL_CENTER_NUMBER=
INBOUND_NUMBER_1=
INBOUND_NUMBER_2=
3 changes: 2 additions & 1 deletion node_modules/jsonwebtoken/.npmignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
*.key
node_modules
.DS_Store
14 changes: 14 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var express = require('express');
// var bodyParser = require('body-parser');

// create a new express server
var app = express();
app.set('port', (process.env.PORT || 5000));
// app.use(bodyParser.urlencoded({ extended: false }));

// start the app and listen on port 5000
app.listen(app.get('port'), '127.0.0.1', function() {
console.log('SMS Proxy App listening on port', app.get('port'));
});

module.exports = app;
100 changes: 100 additions & 0 deletions lib/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// load environment variables
require('dotenv').config();

// initialize Nexmo with App credentials
var Nexmo = require('nexmo');
var nexmo = new Nexmo({
apiKey: process.env['NEXMO_API_KEY'],
apiSecret: process.env['NEXMO_API_SECRET'],
applicationId: process.env['NEXMO_APP_ID'],
privateKey: process.env['NEXMO_APP_FILE_NAME']
});

// Define the topics for the inbound numbers
var topics = {}
topics[process.env['INBOUND_NUMBER_1']] = 'the summer offer';
topics[process.env['INBOUND_NUMBER_2']] = 'the winter offer';

// Set an index for the current conference ID
var conferenceID = 0;

module.exports = function(app){

// Process an inbound call from an inbound
// call made to one of the two numbers
// we've set up
app.get('/answer_inbound', function(req, res) {
// increment the conference ID so
// that every call has a unique conference
conferenceID++;

// create a new call from the number called
// to the call center
nexmo.calls.create({
to: [{
type: 'phone',
number: process.env['CALL_CENTER_NUMBER']
}],
from: {
type: 'phone',
number: req.query.to
},
// when the second leg of this call is
// set up we make sure to pass along the
// conference ID
answer_url: [
'http://c.betta.io/answer_outbound?conference_id='+conferenceID
]
}, function(err, suc) {
console.log("Error:", err);
console.log("Success:", suc);

// When the call has been set up successfully
// we connect the inbound call to a new
// conference with the ID specified
if (suc) {
res.json([
{
"action": "talk",
"text": "Please wait while we connect you"
},
// When we connect the inbound call to a conference
// we keep them on hold and play a ringing sound
// until the operator is connected
{
"action": "conversation",
"name": "conversation-"+conferenceID,
"startOnEnter": "false",
"musicOnHoldUrl": ["https://nexmo-community.github.io/ncco-examples/assets/phone-ringing.mp3"]
}
]);
}
});
});

// Process an outbound call to the call center,
// playing a message to the call center operator
// before connecting them to the conference ID
app.get('/answer_outbound', function(req, res) {
// we determine the topic of the call
// based on the inbound call number
var topic = topics[req.query.from]

res.json([
// We first play back a little message
// telling the call center operator what
// the call regards to. This "whisper" can
// only be heard by the call center operator
{
"action": "talk",
"text": "Incoming call regarding "+topic
},
// Next we connect the call to the same conference,
// connecting the 2 parties
{
"action": "conversation",
"name": "conversation-"+req.query.conference_id
}
]);
});
};
9 changes: 9 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// load environment variable
// from .env file
require('dotenv').config();

// start a new app
var app = require('./app')

// handle all routes
require('./routes')(app);
Empty file.
11 changes: 0 additions & 11 deletions node_modules/base64url/dist/base64url.d.ts

This file was deleted.

37 changes: 0 additions & 37 deletions node_modules/base64url/dist/base64url.js

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/base64url/dist/pad-string.d.ts

This file was deleted.

20 changes: 0 additions & 20 deletions node_modules/base64url/dist/pad-string.js

This file was deleted.

2 changes: 0 additions & 2 deletions node_modules/base64url/index.js

This file was deleted.

101 changes: 0 additions & 101 deletions node_modules/base64url/package.json

This file was deleted.

Loading

0 comments on commit a2b3773

Please sign in to comment.