Permalink
Browse files

Fixed bug in Result class. Added Result class usage example.

  • Loading branch information...
1 parent e0674b6 commit 767abbb92ce91f2596854e31eb70c14c04514038 @mheadd mheadd committed Sep 29, 2010
Showing with 37 additions and 1 deletion.
  1. +1 −1 lib/base.js
  2. +36 −0 samples/sample-5.js
View
2 lib/base.js
@@ -110,7 +110,7 @@ Result = function(json) {
this.interpretation = result.result.actions.interpretation;
this.utterance = result.result.actions.utterance;
this.value = result.result.actions.value;
- this.concept = result.result.concept.value;
+ this.concept = result.result.actions.concept;
return this;
};
View
36 samples/sample-5.js
@@ -0,0 +1,36 @@
+/**
+* A very simple node web server that demonstrates how to use
+* the Tropo Result object.
+*/
+
+
+var http = require('http');
+var tropo = require('../lib/tropo-webapi');
+
+var server = http.createServer(function (request, response) {
+
+ // Add a listener for the data event (incoming data from the HTTP request)
+ request.addListener('data', function(data){
+ json = data.toString();
+ });
+
+ // Add a listener for the EOF event on the incoming stream.
+ request.addListener('end', function() {
+
+ // Create a new instance of the Session object and give it the JSON delivered from Tropo.
+ var result = Result(json);
+
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new TropoWebAPI();
+
+ // Build the response.
+ tropo.say("Your select was, " + result.interpretation);
+ tropo.hangup();
+
+ // Render out the JSON for Tropo to consume.
+ response.writeHead(200, {'Content-Type': 'application/json'});
+ response.end(TropoJSON(tropo));
+
+ })
+
+}).listen(8000); // Listen on port 8000 for requests.

0 comments on commit 767abbb

Please sign in to comment.