Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added events to the Say method along with an example in samples

  • Loading branch information...
commit 991a9462c1df0f3f8b06be5d451949cddce93827 1 parent 92ef2b2
Kevin Bond authored
Showing with 50 additions and 11 deletions.
  1. +21 −9 lib/base.js
  2. +2 −2 lib/tropo-webapi.js
  3. +27 −0 samples/say-event-ask.js
View
30 lib/base.js
@@ -3,14 +3,14 @@
*
*/
Ask = function(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice, interdigitTimeout, sensitivity, speechCompleteTimeout, speechIncompleteTimeout) {
- this.choices = serializeProperty(choices);
+ this.choices = (say.event !== null) ? 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.say = (say.event !== null) ? say : serializeProperty(say);
this.timeout = timeout;
this.voice = voice;
this.interdigitTimeout = interdigitTimeout;
@@ -126,12 +126,23 @@ Result = function(json) {
return this;
};
-Say = function(value, as, name, required, voice) {
- this.value = value;
- this.as = as;
- this.name = name;
- this.required = required;
- this.voice = voice;
+Say = function(value, as, event, name, required, voice, allowSignals) {
+ if(event != null){
+ var say = new Array();
+ for (var i=0;i<event.length;i++){
+ say[i] = event[i];
+ }
+ say[event.length] = {"value":value};
+ return say;
+ }else{
+ this.value = value;
+ this.as = as;
+ this.name = name;
+ this.required = required;
+ this.voice = voice;
+ this.allowSignals = allowSignals;
+ return this;
+ }
};
//TODO: Complete Session object.
@@ -214,4 +225,5 @@ exports.Session = Session;
exports.StartRecording = StartRecording;
exports.StopRecording = StopRecording;
exports.Transfer = Transfer;
-exports.replaceNull = replaceNull;
+exports.replaceNull = replaceNull;
+exports.Wait = Wait;
View
4 lib/tropo-webapi.js
@@ -53,8 +53,8 @@ TropoWebAPI.prototype.reject = function() {
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);
+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));
};
View
27 samples/say-event-ask.js
@@ -0,0 +1,27 @@
+/**
+* A very simple node web server that will respond to requests
+* with a request to enter a 5 digit zip code.
+*/
+
+var http = require('http');
+var tropowebapi = require('tropo-webapi');
+
+var server = http.createServer(function (request, response) {
+
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new tropowebapi.TropoWebAPI();
+ tropo.say("Welcome to my Tropo Web API node demo.");
+
+ // Demonstrates how to use the base Tropo action classes.
+ var say = new Say("Please enter your 5 digit zip code.");
+ var choices = new Choices("[5 DIGITS]");
+
+ // Action classes can be passes as parameters to TropoWebAPI class methods.
+ tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null);
+ tropo.on("continue", null, "http://somefakehost.com:8000/", true);
+
+ // Render out the JSON for Tropo to consume.
+ response.writeHead(200, {'Content-Type': 'application/json'});
+ response.end(tropowebapi.TropoJSON(tropo));
+
+}).listen(8000); // Listen on port 8000 for requests.
Please sign in to comment.
Something went wrong with that request. Please try again.