require 'tropo-webapi-ruby'
require 'sinatra'
post '/index.json' do
t = Tropo::Generator.new
t.ask :name => 'digits',
:timeout => 60,
:say => {:value => "What's your four digit pin?"},
:choices => {:value => "[4 DIGITS]"}
t.on :event => 'continue', :next => '/spanish.json'
t.response
end
post '/spanish.json' do
t = Tropo::Generator.new
t.ask :name => 'digits',
:timeout => 60,
:say => {:value => "¿Cuál es su número de identificación?"},
:voice => "soledad",
:choices => {:value => "[4 DIGITS]"},
:recognizer => "es-mx"
t.on :event => 'continue', :next => '/continue.json'
t.response
end
post '/continue.json' do
t = Tropo::Generator.new
t.say "Gracias", :voice => "soledad"
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("What's your four digit pin?");
// (value, mode, terminator)
var choices = new Choices("[4 DIGITS]");
// (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
tropo.ask(choices, null, null, null, "digits", null, null, say, 60, null);
tropo.on("continue", null, "/spanish", true);
res.send(TropoJSON(tropo));
});
app.post('/spanish', function(req, res){
var tropo = new TropoWebAPI();
var say = new Say("¿Cuál es su número de identificación?");
var choices = new Choices("[4 DIGITS]");
// (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
tropo.ask(choices, null, null, null, "digits", null, "es-mx", say, 60, "soledad");
tropo.on("continue", null, "/continue", true);
res.send(TropoJSON(tropo));
});
app.post('/continue', function(req, res){
var tropo = new TropoWebAPI();
// (value, as, name, required, voice)
tropo.say("Gracias.", null, null, null, "soledad");
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" => "[4 DIGITS]", "name" => "digits", "timeout" => 60);
$tropo->ask("What's your four digit pin?", $options);
$tropo->on(array("event" => "continue", "next" => "hello_world.php?uri=spanish"));
$tropo->RenderJson();
}
dispatch_post('/spanish', 'app_spanish');
function app_spanish() {
$tropo = new Tropo();
$options = array("choices" => "[4 DIGITS]", "name" => "digits", "timeout" => 60, "recognizer" => "es-mx");
//PHP as a whole may have difficulty processing accented characters right now; omission of the accents may cause pronunciation to be off
$tropo->setVoice('soledad');
$tropo->ask("Cual es su numero de identificacion?", $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->getValue();
$tropo->say("Gracias.", array("voice" => "soledad"));
$tropo->say("You said " . $answer);
$tropo->RenderJson();
}
run();
?>
# -*- coding: utf-8 -*-
# The above is a special comment that sets utf-8 encoding in order to read the Spanish characters
from itty import *
from tropo import Tropo
@post('/index.json')
def index(request):
t = Tropo()
t.ask(choices = "[4 DIGITS]", timeout=60, name="digit", say = "What's your four digit pin?")
t.on(event = "continue", next ="/spanish")
return t.RenderJson()
@post('/spanish')
def index(request):
t = Tropo()
t.ask(choices = "[4 DIGITS]", timeout=60, name="digit", say = "¿Cuál es su número de identificación?", recognizer = "es-mx", voice = "soledad")
t.on(event = "continue", next ="/continue")
return t.RenderJson()
@post("/continue")
def index(request):
t = Tropo()
t.say("Gracias", voice = "soledad")
return t.RenderJson()
run_itty(server='wsgiref', host='0.0.0.0', port=8888)