Skip to content
Browse files

Merge pull request #22 from kevinbond/master

Updates to the webAPI node.js library
  • Loading branch information...
2 parents 33027e5 + 92ef2b2 commit 79696d31f806693bfb216a407545fa5f6c866829 @akalsey akalsey committed Apr 11, 2013
Showing with 179 additions and 154 deletions.
  1. +139 −119 lib/base.js
  2. +40 −35 lib/tropo-webapi.js
View
258 lib/base.js
@@ -2,119 +2,128 @@
* Tropo action classes.
*
*/
-Ask = function(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice) {
- this.choices = serializeProperty(choices);
- this.attempts = attempts;
- this.bargein = bargein;
- this.minConfidence = minConfidence;
- this.name = name;
- this.recognizer = recognizer;
- this.required = required;
- this.say = serializeProperty(say);
- this.timeout = timeout;
- this.voice = voice;
+Ask = function(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice, interdigitTimeout, sensitivity, speechCompleteTimeout, speechIncompleteTimeout) {
+ this.choices = serializeProperty(choices);
+ this.attempts = attempts;
+ this.bargein = bargein;
+ this.minConfidence = minConfidence;
+ this.name = name;
+ this.recognizer = recognizer;
+ this.required = required;
+ this.say = serializeProperty(say);
+ this.timeout = timeout;
+ this.voice = voice;
+ this.interdigitTimeout = interdigitTimeout;
+ this.sensitivity = sensitivity;
+ this.speechCompleteTimeout = speechCompleteTimeout;
+ this.speechIncompleteTimeout = speechIncompleteTimeout;
};
-Call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout) {
- this.to = to;
- this.answerOnMedia = answerOnMedia;
- this.channel = channel;
- this.from = from;
- this.headers = serializeProperty(headers);
- this.name = name;
- this.network = network;
- this.recording = (typeof(recording) == 'Object') ? serializeProperty(recording) : recording;
- this.required = required;
- this.timeout = timeout;
+Call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals) {
+ this.to = to;
+ this.answerOnMedia = answerOnMedia;
+ this.channel = channel;
+ this.from = from;
+ this.headers = serializeProperty(headers);
+ this.name = name;
+ this.network = network;
+ this.recording = (typeof(recording) == 'Object') ? serializeProperty(recording) : recording;
+ this.required = required;
+ this.timeout = timeout;
+ this.allowSignals = allowSignals;
};
Choices = function(value, mode, terminator) {
- this.value = value;
- this.mode = mode;
- this.terminator = terminator;
+ this.value = value;
+ this.mode = mode;
+ this.terminator = terminator;
};
-Conference = function(id, mute, name, playTones, required, terminator) {
- this.id = id;
- this.mute = mute;
- this.name = name;
- this.playTones = playTones;
- this.required = required;
- this.terminator = terminator;
+Conference = function(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout) {
+ this.id = id;
+ this.mute = mute;
+ this.name = name;
+ this.playTones = playTones;
+ this.required = required;
+ this.terminator = terminator;
+ this.allowSignals = allowSignals;
+ this.interdigitTimeout = interdigitTimeout;
};
Hangup = function() {};
Message = function(say, to, answerOnMedia, channel, from, name, network, required, timeout, voice) {
- this.say = serializeProperty(say);
- this.to = to;
- this.answerOnMedia = answerOnMedia;
- this.channel = channel;
- this.from = from;
- this.name = name;
- this.network = network;
- this.required = required;
- this.timeout = timeout;
- this.voice = voice;
+ this.say = serializeProperty(say);
+ this.to = to;
+ this.answerOnMedia = answerOnMedia;
+ this.channel = channel;
+ this.from = from;
+ this.name = name;
+ this.network = network;
+ this.required = required;
+ this.timeout = timeout;
+ this.voice = voice;
};
On = function(event, name, next, required, say) {
- this.event = event;
- this.name = name;
- this.next = next;
- this.required = required;
- this.say = serializeProperty(say);
+ this.event = event;
+ this.name = name;
+ this.next = next;
+ this.required = required;
+ this.say = serializeProperty(say);
};
-Record = function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice) {
- this.attempts = attempts;
- this.bargein = bargein;
- this.beep = beep;
- this.choices = serializeProperty(choices);
- this.format = format;
- this.maxSilence = maxSilence;
- this.maxTime = maxTime;
- this.method = method;
- this.minConfidence = minConfidence;
- this.name = name;
- this.required = required;
- this.say = serializeProperty(say);
- this.timeout = timeout;
- this.transcription = (typeof(transcription) == 'Object') ? serializeProperty(transcription) : transcription;
- this.url = url;
- this.password = password;
- this.username = username;
- this.voice = voice;
+Record = function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice, allowSignals, interdigitTimeout) {
+ this.attempts = attempts;
+ this.bargein = bargein;
+ this.beep = beep;
+ this.choices = serializeProperty(choices);
+ this.format = format;
+ this.maxSilence = maxSilence;
+ this.maxTime = maxTime;
+ this.method = method;
+ this.minConfidence = minConfidence;
+ this.name = name;
+ this.required = required;
+ this.say = serializeProperty(say);
+ this.timeout = timeout;
+ this.transcription = (typeof(transcription) == 'Object') ? serializeProperty(transcription) : transcription;
+ this.url = url;
+ this.password = password;
+ this.username = username;
+ this.voice = voice;
+ this.allowSignals = allowSignals;
+ this.interdigitTimeout = interdigitTimeout;
};
Redirect = function(to, name, required) {
- this.to = to;
- this.name = name;
- this.required = required;
+ this.to = to;
+ this.name = name;
+ this.required = required;
};
Reject = function() {};
Result = function(json) {
- var result = JSON.parse(json);
- this.sessionId = result.result.sessionId;
- this.callId = result.result.callId;
- this.state = result.result.state;
- this.sessionDuration = result.result.sessionDuration;
- this.sequence = result.result.sequence;
- this.complete = result.result.complete;
- this.error = result.result.error;
- 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;
+ var result = JSON.parse(json);
+ this.sessionId = result.result.sessionId;
+ this.callId = result.result.callId;
+ this.state = result.result.state;
+ this.sessionDuration = result.result.sessionDuration;
+ this.sequence = result.result.sequence;
+ this.complete = result.result.complete;
+ this.error = result.result.error;
+ 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;
};
Say = function(value, as, name, required, voice) {
@@ -127,53 +136,64 @@ Say = function(value, as, name, required, voice) {
//TODO: Complete Session object.
Session = function(json) {
- var session = JSON.parse(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;
- this.headers;
- this.parameters;
-
- return this;
+ var session = JSON.parse(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;
+ this.headers;
+ this.parameters;
+
+ return this;
};
-StartRecording = function(format, method, url, username, password) {
- this.format = format;
- this.method = method;
- this.url = url;
- this.username = username ;
- this.password = password;
+StartRecording = function(format, method, url, username, password, transcriptionID, transcriptionEmailFormat, transcriptionOutURI) {
+ this.format = format;
+ this.method = method;
+ this.url = url;
+ this.username = username ;
+ this.password = password;
+ this.transcriptionID = transcriptionID;
+ this.transcriptionEmailFormat = transcriptionEmailFormat;
+ this.transcriptionOutURI = transcriptionOutURI;
};
StopRecording = function() {};
-Transfer = function(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout) {
- this.to = to;
- this.answerOnMedia = answerOnMedia;
- this.choices = serializeProperty(choices);
- this.from = from;
- this.headers = serializeProperty(headers);
- this.name = name;
- this.on = (typeof(on) == 'Object') ? serializeProperty(on) : on;
- this.required = required;
- this.terminator = terminator;
- this.timeout = timeout;
+Transfer = function(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout, allowSignals, interdigitTimeout, ringRepeat) {
+ this.to = to;
+ this.answerOnMedia = answerOnMedia;
+ this.choices = serializeProperty(choices);
+ this.from = from;
+ this.headers = serializeProperty(headers);
+ this.name = name;
+ this.on = (typeof(on) == 'Object') ? serializeProperty(on) : on;
+ this.required = required;
+ this.terminator = terminator;
+ this.timeout = timeout;
+ this.allowSignals = allowSignals;
+ this.interdigitTimeout = interdigitTimeout;
+ this.ringRepeat = ringRepeat;
+};
+
+Wait = function(milliseconds, allowSignals){
+ this.milliseconds = milliseconds;
+ this.allowSignals = allowSignals;
};
// Helper method that serializes properties of Tropo action objects..
function serializeProperty(object) {
- return JSON.stringify(object, replaceNull);
+ return JSON.stringify(object, replaceNull);
}
// Helper method to remove null values from rendered JSON.
function replaceNull (key, value) {
if (value === null) {
return undefined;
- }
+ }
return value;
};
View
75 lib/tropo-webapi.js
@@ -5,72 +5,77 @@ var base = require('./base');
*
*/
TropoWebAPI = function() {
- this.tropo = new Array();
+ this.tropo = new Array();
};
-TropoWebAPI.prototype.ask = function(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice) {
- var ask = new base.Ask(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
- this.tropo.push(serializeObject("ask", ask));
+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));
};
-TropoWebAPI.prototype.call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout) {
- var call = new base.Call(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout);
- this.tropo.push(serializeObject("call", call));
+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.conference = function(id, mute, name, playTones, required, terminator) {
- var conference = new base.Conference(id, mute, name, playTones, required, terminator);
- this.tropo.push(serializeObject("conference", conference));
+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.hangup = function() {
- var hangup = new base.Hangup();
- this.tropo.push(serializeObject("hangup", hangup));
+ var hangup = new base.Hangup();
+ this.tropo.push(serializeObject("hangup", hangup));
};
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));
+ var message = new base.Message(say, to, answerOnMedia, channel, from, name, network, required, timeout, voice);
+ this.tropo.push(serializeObject("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));
+ var on = new base.On(event, name, next, required, say);
+ this.tropo.push(serializeObject("on", on));
};
-TropoWebAPI.prototype.record = function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice) {
- var record = new base.Record(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice);
- this.tropo.push(serializeObject("record", record));
+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));
};
TropoWebAPI.prototype.redirect = function(to, name, required) {
- var redirect = new base.Redirect(to, name, required);
- this.tropo.push(serializeObject("redirect", redirect));
+ var redirect = new base.Redirect(to, name, required);
+ this.tropo.push(serializeObject("redirect", redirect));
};
TropoWebAPI.prototype.reject = function() {
- var reject = new base.Reject();
- this.tropo.push(serializeObject("reject", reject));
+ var reject = new base.Reject();
+ this.tropo.push(serializeObject("reject", reject));
};
TropoWebAPI.prototype.say = function(value, as, name, required, voice) {
- var say = new base.Say(value, as, name, required, voice);
- this.tropo.push(serializeObject("say", say));
+ var say = new base.Say(value, as, name, required, voice);
+ this.tropo.push(serializeObject("say", say));
};
-TropoWebAPI.prototype.startRecording = function(format, method, url, username, password) {
- var startRecording = new base.StartRecording(format, method, url, username, password);
- this.tropo.push(serializeObject("startRecording", startRecording));
+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));
};
TropoWebAPI.prototype.stopRecording = function() {
- var stopRecording = new base.StopRecording();
- this.tropo.push(serializeObject("stopRecording", stopRecording));
+ var stopRecording = new base.StopRecording();
+ this.tropo.push(serializeObject("stopRecording", stopRecording));
};
-TropoWebAPI.prototype.transfer = function(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout) {
- var transfer = new base.Transfer(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout);
- this.tropo.push(serializeObject("transfer", transfer));
+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));
+};
+
+TropoWebAPI.prototype.wait = function(milliseconds, allowSignals){
+ var wait = new base.Wait(milliseconds, allowSignals);
+ this.tropo.push(serializeObject("wait", wait));
};
exports.TropoWebAPI = TropoWebAPI;
@@ -80,7 +85,7 @@ exports.TropoWebAPI = TropoWebAPI;
*
*/
TropoJSON = function(object) {
- return JSON.stringify(object).replace(/\\/g, "").replace(/"{/g, "{").replace(/}"/g, "}");
+ return JSON.stringify(object).replace(/\\/g, "").replace(/"{/g, "{").replace(/}"/g, "}");
};
exports.TropoJSON = TropoJSON;
@@ -92,7 +97,7 @@ 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) + "}";
+ return "{ \"" + name + "\":" + JSON.stringify(object, base.replaceNull) + "}";
}

0 comments on commit 79696d3

Please sign in to comment.
Something went wrong with that request. Please try again.