Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Library Update #29

Merged
merged 5 commits into from

1 participant

@kevinbond
Owner

Added the following to this library:

 1)Removed userType from Session and fixed the Result object
 2)Added CPA methods
 3)Added join/leave Prompt to conference
 4)Added whisper functionality to transfer
@kevinbond kevinbond merged commit 4a75137 into tropo:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
49 lib/base.js
@@ -19,7 +19,7 @@ Ask = function(choices, attempts, bargein, minConfidence, name, recognizer, requ
this.speechIncompleteTimeout = speechIncompleteTimeout;
};
-Call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals) {
+Call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals, machineDetection) {
this.to = to;
this.answerOnMedia = answerOnMedia;
this.channel = channel;
@@ -31,6 +31,7 @@ Call = function(to, answerOnMedia, channel, from, headers, name, network, record
this.required = required;
this.timeout = timeout;
this.allowSignals = allowSignals;
+ this.machineDetection = machineDetection;
};
Choices = function(value, mode, terminator) {
@@ -39,7 +40,7 @@ Choices = function(value, mode, terminator) {
this.terminator = terminator;
};
-Conference = function(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout) {
+Conference = function(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout, joinPrompt, leavePrompt) {
this.id = id;
this.mute = mute;
this.name = name;
@@ -48,10 +49,27 @@ Conference = function(id, mute, name, playTones, required, terminator, allowSign
this.terminator = terminator;
this.allowSignals = allowSignals;
this.interdigitTimeout = interdigitTimeout;
+ this.joinPrompt = joinPrompt;
+ this.leavePrompt = leavePrompt;
};
Hangup = function() {};
+JoinPrompt = function(value, voice){
+ this.value = value;
+ this.voice = voice;
+}
+
+LeavePrompt = function(value, voice){
+ this.value = value;
+ this.voice = voice;
+}
+
+MachineDetection = function(introduction, voice){
+ this.introduction = introduction;
+ this.voice = voice;
+}
+
Message = function(say, to, answerOnMedia, channel, from, name, network, required, timeout, voice) {
this.say = serializeProperty(say);
this.to = to;
@@ -65,12 +83,15 @@ Message = function(say, to, answerOnMedia, channel, from, name, network, require
this.voice = voice;
};
-On = function(event, name, next, required, say) {
+On = function(event, name, next, required, say, ask, message, wait) {
this.event = event;
this.name = name;
this.next = next;
this.required = required;
- this.say = serializeProperty(say);
+ this.say = (typeof(say) == 'Object') ? serializeProperty(say) : say;
+ this.ask = ask;
+ this.message = message;
+ this.wait = wait;
};
Record = function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice, allowSignals, interdigitTimeout) {
@@ -113,7 +134,8 @@ Result = function(json) {
this.sequence = result.result.sequence;
this.complete = result.result.complete;
this.error = result.result.error;
- this.actions = result.result.actions;
+ 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;
@@ -122,7 +144,6 @@ Result = function(json) {
this.utterance = result.result.actions.utterance;
this.value = result.result.actions.value;
this.concept = result.result.actions.concept;
-
return this;
};
@@ -151,7 +172,6 @@ Session = function(json) {
this.id = session.session.id;
this.accountId = session.session.accountId;
this.timestamp = session.session.timestamp;
- this.userType = session.session.userType;
this.initialText = session.session.initialText;
this.to;
this.from;
@@ -181,7 +201,17 @@ Transfer = function(to, answerOnMedia, choices, from, headers, name, on, require
this.from = from;
this.headers = serializeProperty(headers);
this.name = name;
- this.on = (typeof(on) == 'Object') ? serializeProperty(on) : on;
+ if(typeof(on) == "Array"){
+ this.on = "";
+ var comma = "";
+ for (var i=0;i<on.length;i++){
+ this.on += comma + on[i];
+ comma = ",";
+ }
+
+ }else{
+ this.on = (typeof(on) == 'Object') ? serializeProperty(on) : on;
+ }
this.required = required;
this.terminator = terminator;
this.timeout = timeout;
@@ -214,6 +244,9 @@ exports.Call = Call;
exports.Choices = Choices;
exports.Conference = Conference;
exports.Hangup = Hangup;
+exports.JoinPrompt = JoinPrompt;
+exports.LeavePrompt = LeavePrompt;
+exports.MachineDetection = MachineDetection;
exports.Message = Message;
exports.On = On;
exports.Record = Record;
View
66 lib/tropo-webapi.js
@@ -10,72 +10,87 @@ TropoWebAPI = function() {
TropoWebAPI.prototype.ask = function(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice, interdigitTimeout, sensitivity, speechCompleteTimeout, speechIncompleteTimeout) {
var ask = new base.Ask(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice, interdigitTimeout, sensitivity, speechCompleteTimeout, speechIncompleteTimeout);
- this.tropo.push(serializeObject("ask", ask));
+ this.tropo.push({"ask": ask});
};
-TropoWebAPI.prototype.call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals) {
- var call = new base.Call(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals);
- this.tropo.push(serializeObject("call", call));
+TropoWebAPI.prototype.call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals, machineDetection) {
+ var call = new base.Call(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals, machineDetection);
+ this.tropo.push({"call": call});
};
-TropoWebAPI.prototype.conference = function(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout) {
- var conference = new base.Conference(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout);
- this.tropo.push(serializeObject("conference", conference));
+TropoWebAPI.prototype.conference = function(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout, joinPrompt, leavePrompt) {
+ var conference = new base.Conference(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout, joinPrompt, leavePrompt);
+ this.tropo.push({"conference": conference});
};
TropoWebAPI.prototype.hangup = function() {
var hangup = new base.Hangup();
- this.tropo.push(serializeObject("hangup", hangup));
+ this.tropo.push({"hangup": hangup});
+};
+
+TropoWebAPI.prototype.joinPrompt = function(value, voice) {
+ var joinPrompt = new base.JoinPrompt(value, voice);
+ this.tropo.push({"joinPrompt": joinPrompt});
+};
+
+TropoWebAPI.prototype.leavePrompt = function(value, voice) {
+ var leavePrompt = new base.LeavePrompt(value, voice);
+ this.tropo.push({"leavePrompt": leavePrompt});
+};
+
+TropoWebAPI.prototype.machineDetection = function(introduction, voice) {
+ var machineDetection = new base.machineDetection(introduction, voice);
+ this.tropo.push({"machineDetection": machineDetection});
};
TropoWebAPI.prototype.message = function(say, to, answerOnMedia, channel, from, name, network, required, timeout, voice) {
var message = new base.Message(say, to, answerOnMedia, channel, from, name, network, required, timeout, voice);
- this.tropo.push(serializeObject("message", message));
+ this.tropo.push({"message": message});
};
-TropoWebAPI.prototype.on = function(event, name, next, required, say) {
- var on = new base.On(event, name, next, required, say);
- this.tropo.push(serializeObject("on", on));
+TropoWebAPI.prototype.on = function(event, name, next, required, say, ask, message, wait) {
+ var on = new base.On(event, name, next, required, say, ask, message, wait);
+ this.tropo.push({"on": on});
};
TropoWebAPI.prototype.record = function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice, allowSignals, interdigitTimeout) {
var record = new base.Record(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice, allowSignals, interdigitTimeout);
- this.tropo.push(serializeObject("record", record));
+ this.tropo.push({"record": record});
};
TropoWebAPI.prototype.redirect = function(to, name, required) {
var redirect = new base.Redirect(to, name, required);
- this.tropo.push(serializeObject("redirect", redirect));
+ this.tropo.push({"redirect": redirect});
};
TropoWebAPI.prototype.reject = function() {
var reject = new base.Reject();
- this.tropo.push(serializeObject("reject", reject));
+ this.tropo.push({"reject": reject});
};
TropoWebAPI.prototype.say = function(value, as, event, name, required, voice, allowSignals) {
var say = new base.Say(value, as, event, name, required, voice, allowSignals);
- this.tropo.push(serializeObject("say", say));
+ this.tropo.push({"say": say});
};
TropoWebAPI.prototype.startRecording = function(format, method, url, username, password, transcriptionID, transcriptionEmailFormat, transcriptionOutURI) {
var startRecording = new base.StartRecording(format, method, url, username, password, transcriptionID, transcriptionEmailFormat, transcriptionOutURI);
- this.tropo.push(serializeObject("startRecording", startRecording));
+ this.tropo.push({"startRecording": startRecording});
};
TropoWebAPI.prototype.stopRecording = function() {
var stopRecording = new base.StopRecording();
- this.tropo.push(serializeObject("stopRecording", stopRecording));
+ this.tropo.push({"stopRecording": stopRecording});
};
TropoWebAPI.prototype.transfer = function(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout, allowSignals, interdigitTimeout, ringRepeat) {
var transfer = new base.Transfer(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout, allowSignals, interdigitTimeout, ringRepeat);
- this.tropo.push(serializeObject("transfer", transfer));
+ this.tropo.push({"transfer": transfer});
};
TropoWebAPI.prototype.wait = function(milliseconds, allowSignals){
var wait = new base.Wait(milliseconds, allowSignals);
- this.tropo.push(serializeObject("wait", wait));
+ this.tropo.push({"wait": wait});
};
exports.TropoWebAPI = TropoWebAPI;
@@ -85,7 +100,7 @@ exports.TropoWebAPI = TropoWebAPI;
*
*/
TropoJSON = function(object) {
- return JSON.stringify(object).replace(/\\/g, "").replace(/"{/g, "{").replace(/}"/g, "}");
+ return JSON.stringify(object, base.replaceNull);
};
exports.TropoJSON = TropoJSON;
@@ -93,11 +108,4 @@ exports.TropoJSON = TropoJSON;
Headers = function() {
};
-exports.Headers = Headers;
-
-// Helper method that serializes objects that are properties of the primary Tropo object.
-function serializeObject(name, object) {
- return "{ \"" + name + "\":" + JSON.stringify(object, base.replaceNull) + "}";
-}
-
-
+exports.Headers = Headers;
View
31 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));
+});
View
25 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');
View
48 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));
+});
View
2  tests/tests.js
@@ -38,7 +38,7 @@ util.puts('***** Test Run Complete ************');
function sayTest(expected) {
var tropo = new TropoWebAPI();
- tropo.say("Hello, World.", null, null, true, "carmen");
+ tropo.say("Hello, World.", null, null, null, true, "carmen", null);
return runTest(TropoJSON(tropo), expected);
}
Something went wrong with that request. Please try again.