require 'tropo-webapi-ruby'
require 'sinatra'
post '/index.json' do
t = Tropo::Generator.new
t.ask :name => 'directory',
:timeout => 15,
:say => {:value => "Welcome to the Tropo company directory. Who are you trying to reach?"},
:choices => {:value => "department(support, engineering, sales), person(jose, jason, adam)"}
t.on :event => 'continue', :next => '/continue.json'
t.response
end
post '/continue.json' do
v = Tropo::Generator.parse request.env["rack.input"].read
t = Tropo::Generator.new
answer = v[:result][:actions][:directory][:interpretation]
value = v[:result][:actions][:directory][:value]
t.say(:value => "You said " + answer + ", which is a " + 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("Welcome to the Tropo company directory. Who are you trying to reach?");
// (value, mode, terminator)
var choices = new Choices("department(support, engineering, sales), person(jose, jason, adam)");
// (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
tropo.ask(choices, null, null, null, "directory", null, null, say, 15, null);
tropo.on("continue", null, "/continue", true);
res.send(TropoJSON(tropo));
});
app.post('/continue', function(req, res){
var tropo = new TropoWebAPI();
var answer = req.body['result']['actions']['interpretation'];
var value = req.body['result']['actions']['value'];
tropo.say("You said " + answer + ", which is a " + 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();
$options = array("choices" => "department(support, engineering, sales), person(jose, jason, adam)", "name" => "directory", "timeout" => 15);
$tropo->ask("Welcome to the Tropo company directory. Who are you trying to reach?", $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();
@$result = new Result();
$answer = $result->getInterpretation();
$value = $result->getValue();
$tropo->say("You said " . $answer . ", which is a " . $value);
$tropo->RenderJson();
}
run();
?>
from itty import *
from tropo import Tropo, Result
@post('/index.json')
def index(request):
t = Tropo()
t.ask(choices = "department(support, engineering, sales), person(jose, jason, adam)", timeout = 15, name = "directory", say = "Welcome to the Tropo company directory. Who are you trying to reach?")
t.on(event = "continue", next ="/continue")
return t.RenderJson()
@post("/continue")
def index(request):
r = Result(request.body)
t = Tropo()
answer = r.getInterpretation()
value = r.getValue()
t.say("You said " + answer + ", which is a " + value)
return t.RenderJson()
run_itty(server='wsgiref', host='0.0.0.0', port=8888)