require 'rubygems'
require 'tropo-webapi-ruby'
require 'sinatra'
post '/index.json' do
t = Tropo::Generator.new
t.ask :name => 'catch',
:say => {:value => ""},
:timeout => 60,
:choices => {:value => "[ANY]"}
t.on :event => 'continue', :next => '/continue.json'
t.response
end
post '/continue.json' do
t = Tropo::Generator.new
t.ask :name => 'status',
:say => {:value => "What's your status?"},
:timeout => 60,
:choices => {:value => "[ANY]"}
t.response
t.on :event => 'continue', :next => '/finish.json'
end
post '/finish.json' do
v = Tropo::Generator.parse request.env["rack.input"].read
t = Tropo::Generator.new
value = v[:result][:actions][:status][:value]
t.say(:value => "Status returned: " + value)
t.response
end
var http = require('http');
var express = require('express');
var app = express.createServer();
var tropo_webapi = 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();
var say = new Say("");
var choices = new Choices(null, null, "[ANY]");
var say2 = new Say("What's your status?");
var choices2 = new Choices(null, null, "[ANY]");
// (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
tropo.ask(choices, null, null, null, "the_ask", null, null, say, 60, null);
tropo.ask(choices2, null, null, null, "the_ask2", null, null, say2, 60, null);
tropo.on("continue", null, "/continue", true);
res.send(TropoJSON(tropo));
});
app.post('/continue', function(req, res){
var tropo = new TropoWebAPI();
var value = req.body['result']['actions'][1]['value'];
tropo.say("Status returned: " + value);
res.send(TropoJSON(tropo));
});
app.listen(8000);
console.log('Server running on port :8000');
<?php
require 'tropo.class.php';
require 'lib/limonade.php';
dispatch_post('/start', 'app_start');
function app_start() {
$tropo = new Tropo();
// Set up options for input.
$options = array("choices" => "[ANY]", "name" => "catch", "timeout" => 60);
$tropo->ask("", $options);
$tropo->on(array("event" => "continue", "next" => "hello_world.php?uri=continue"));
$tropo->RenderJson();
}
dispatch_post('/continue', 'app_continue');
function app_continue() {
$tropo = new Tropo();
$options2 = array("choices" => "[ANY]", "name" => "status", "timeout" => 60);
$tropo->ask("What's your status?", $options2);
$tropo->on(array("event" => "continue", "next" => "hello_world.php?uri=finish"));
$tropo->RenderJson();
}
dispatch_post('/finish', 'app_finish');
function app_finish() {
$tropo = new Tropo();
@$result = new Result();
$value = $result->getValue();
$tropo->say("You said " . $value);
$tropo->RenderJson();
}
run();
?>
from itty import *
from tropo import Tropo, Result
@post('/index.json')
def index(request):
t = Tropo()
t.ask(choices = "[ANY]", timeout = 60, name = "catch", say = "")
t.on(event = "continue", next ="/continue")
return t.RenderJson()
@post('/continue')
def index(request):
t = Tropo()
t.ask(choices = "[ANY]", timeout = 60, name = "status", say = "What's your status?")
t.on(event = "continue", next ="/finish")
return t.RenderJson()
@post("/finish")
def index(request):
r = Result(request.body)
t = Tropo()
value = r.getValue()
t.say("Status returned: " + value)
return t.RenderJson()
run_itty(server='wsgiref', host='0.0.0.0', port=8888)