Skip to content

Commit

Permalink
Library update
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbond committed Nov 11, 2013
1 parent 5103b17 commit e60e55c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 24 deletions.
36 changes: 12 additions & 24 deletions lib/base.js
Expand Up @@ -57,12 +57,12 @@ Hangup = function() {};


JoinPrompt = function(value, voice){ JoinPrompt = function(value, voice){
this.value = value; this.value = value;
this.voice; this.voice = voice;
} }


LeavePrompt = function(value, voice){ LeavePrompt = function(value, voice){
this.value = value; this.value = value;
this.voice; this.voice = voice;
} }


MachineDetection = function(introduction, voice){ MachineDetection = function(introduction, voice){
Expand Down Expand Up @@ -134,28 +134,16 @@ Result = function(json) {
this.sequence = result.result.sequence; this.sequence = result.result.sequence;
this.complete = result.result.complete; this.complete = result.result.complete;
this.error = result.result.error; this.error = result.result.error;
this.actions = result.result.actions; this.userType = result.result.userType;
if (this.actions instanceof Array){ this.actions = result.result.actions;
this.name = result.result.actions[1].name; this.name = result.result.actions.name;
this.attempts = result.result.actions[1].attempts; this.attempts = result.result.actions.attempts;
this.disposition = result.result.actions[1].disposition; this.disposition = result.result.actions.disposition;
this.confidence = result.result.actions[1].confidence; this.confidence = result.result.actions.confidence;
this.interpretation = result.result.actions[1].interpretation; this.interpretation = result.result.actions.interpretation;
this.utterance = result.result.actions[1].utterance; this.utterance = result.result.actions.utterance;
this.value = result.result.actions[1].value; this.value = result.result.actions.value;
this.concept = result.result.actions[1].concept; this.concept = result.result.actions.concept;
this.userType = result.result.actions[1].userType;
}else{
this.name = result.result.actions.name;
this.attempts = result.result.actions.attempts;
this.disposition = result.result.actions.disposition;
this.confidence = result.result.actions.confidence;
this.interpretation = result.result.actions.interpretation;
this.utterance = result.result.actions.utterance;
this.value = result.result.actions.value;
this.concept = result.result.actions.concept;
this.userType = result.result.actions.userType;
}
return this; return this;
}; };


Expand Down
31 changes: 31 additions & 0 deletions samples/callMachineDetection.js
@@ -0,0 +1,31 @@
var express = require('express');
var app = express.createServer();
var sys = require('sys');
var tropowebapi = require('tropo-webapi');

// Required to process the HTTP body.
// req.body has the Object while req.rawBody has the JSON string.
app.configure(function(){
app.use(express.bodyParser());
});

app.post('/', function(req, res) {

var tropo = new tropowebapi.TropoWebAPI();

mc = new MachineDetection("This is a test. Please hold while I determine if you are a Machine or Human. Processing. Finished. THank you for your patience.", "Victor")
tropo.call("+14071234321", null, null, "14075559090", null, "call", null, null, true, 60, null, mc);
tropo.on("continue", null, "/call", true);

res.send(tropowebapi.TropoJSON(tropo));
});

app.post('/call', function(req, res){

var tropo = new tropowebapi.TropoWebAPI();

var userType = req.body['result']['userType'];
tropo.say("You are a " + userType);

res.send(tropowebapi.TropoJSON(tropo));
});
25 changes: 25 additions & 0 deletions samples/conferenceJoinLeave.js
@@ -0,0 +1,25 @@
var http = require('http');
var tropo_webapi = require('tropo-webapi');

var server = http.createServer(function (request, response) {

request.addListener('data', function(data){
json = data.toString();
});

request.addListener('end', function() {

var session = JSON.parse(json);
var tropo = new TropoWebAPI();
var callerID = session.session.from.id;

var join = new JoinPrompt("Please welcome " + callerID + " to the party!", null);
var leave = new LeavePrompt(callerID + " has just decided to depart.", null);

tropo.conference("1234", false, null, null, true, null, null, null, join, leave);

response.end(TropoJSON(tropo));
});

}).listen(8000);
console.log('Server running on port :8000');
48 changes: 48 additions & 0 deletions samples/transferWhisper.js
@@ -0,0 +1,48 @@
var express = require('express');
var app = express.createServer();
var sys = require('sys');
var tropowebapi = require('tropo-webapi');

// Required to process the HTTP body.
// req.body has the Object while req.rawBody has the JSON string.
app.configure(function(){
app.use(express.bodyParser());
});

app.post('/', function(req, res) {

console.log('In the first resource');
var tropo = new tropowebapi.TropoWebAPI();
console.log('1');

var say = new Say("Press 1 to accept this call or any other number to reject");
var choices = new Choices("1", "dtmf", null);

var whisper = new Array();
console.log('3');
//
var ask = new Ask(choices, null, null, null, "color", null, null, say, 60, null);
whisper[0] = new On("connect", null, null, null, null, ask, null, null);
console.log('4');

var say = new Say("You are now being connected");
whisper[1]= new On("connect", null, null, null, say, null, null, null);
console.log('5');

tropo.say("Please hold while you are being transferred");
tropo.transfer("+14071234321", null, null, null, null, "foo", whisper, true, "*", null, null, null, null);
console.log('6');

var incompleteSay = new Say("You are now being disconnected");
tropo.on("incomplete", null, "/hangup", null, incompleteSay, null, null, null);


res.send(tropowebapi.TropoJSON(tropo));


});
app.post('/hangup', function(req, res){
var tropo = new tropowebapi.TropoWebAPI();
tropo.hangup();
res.send(tropowebapi.TropoJSON(tropo));
});

0 comments on commit e60e55c

Please sign in to comment.