Skip to content

Commit

Permalink
Switch to using onAnswer rather than a conference
Browse files Browse the repository at this point in the history
  • Loading branch information
lornajane committed Sep 12, 2018
1 parent 79d3d6d commit f43a981
Showing 1 changed file with 21 additions and 58 deletions.
79 changes: 21 additions & 58 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,31 @@ var conferenceID = 0;

module.exports = function(app){

// Process an inbound call from an inbound
// call made to one of the two numbers
// 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++;
app.get('/answer', function(req, res) {
var answer_url = 'http://'+process.env['DOMAIN']+'/on-answer?conference_id='+conferenceID
console.log(answer_url);

// 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://'+process.env['DOMAIN']+'/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"]
}
]);
}
});
res.json([
{
"action": "talk",
"text": "Thanks for calling. Please wait while we connect you"
},
{
"action": "connect",
"from": req.query.to,
"endpoint": [{
"type": "phone",
"number": process.env['CALL_CENTER_NUMBER'],
"onAnswer": {"url": answer_url}
}]
}
]);
});

// 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) {
// Handle the call center answering the phone, prompt them with information
app.get('/on-answer', function(req, res) {
// we determine the topic of the call
// based on the inbound call number
var topic = topics[req.query.from]
Expand All @@ -88,12 +57,6 @@ module.exports = function(app){
{
"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
}
]);
});
Expand Down

0 comments on commit f43a981

Please sign in to comment.