Permalink
Browse files

Library update

  • Loading branch information...
1 parent 5103b17 commit e60e55c74cdea46d4439de2953e569f290b2e6f5 @kevinbond kevinbond committed Nov 11, 2013
Showing with 116 additions and 24 deletions.
  1. +12 −24 lib/base.js
  2. +31 −0 samples/callMachineDetection.js
  3. +25 −0 samples/conferenceJoinLeave.js
  4. +48 −0 samples/transferWhisper.js
View
@@ -57,12 +57,12 @@ Hangup = function() {};
JoinPrompt = function(value, voice){
this.value = value;
- this.voice;
+ this.voice = voice;
}
LeavePrompt = function(value, voice){
this.value = value;
- this.voice;
+ this.voice = voice;
}
MachineDetection = function(introduction, voice){
@@ -134,28 +134,16 @@ Result = function(json) {
this.sequence = result.result.sequence;
this.complete = result.result.complete;
this.error = result.result.error;
- this.actions = result.result.actions;
- if (this.actions instanceof Array){
- this.name = result.result.actions[1].name;
- this.attempts = result.result.actions[1].attempts;
- this.disposition = result.result.actions[1].disposition;
- this.confidence = result.result.actions[1].confidence;
- this.interpretation = result.result.actions[1].interpretation;
- this.utterance = result.result.actions[1].utterance;
- this.value = result.result.actions[1].value;
- this.concept = result.result.actions[1].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;
- }
+ this.userType = result.result.userType;
+ this.actions = result.result.actions;
+ 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;
return this;
};
@@ -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));
+});
@@ -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');
View
@@ -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.