require 'tropo-webapi-ruby'
require 'sinatra'
post '/index.json' do
t = Tropo::Generator.new
t.call(:to => "+14075550100", :network => "SMS")
t.ask :name => 'reminder',
:timeout => 60,
:say => {:value => "Hey, did you remember to take your pills?"},
:choices => {:value => "yes(yes,y,1), no(no,n,2)"}
t.on :event => 'continue', :next => '/continue.json'
t.on :event => 'incomplete', :next => '/incomplete.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][:reminder][:value]
if answer == "yes"
t.say(:value => "Ok, just checkin.")
else
t.say(:value => "What are you waiting for?")
end
t.response
end
post '/incomplete.json' do
t = Tropo::Generator.new
t.say(:value => "Sorry, that wasn't on of the options.")
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();
//to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout
tropo.call("14075550100", null, null, null, null, null, "SMS", null, null, null);
var say = new Say("Hey, did you remember to take your pills?");
var choices = new Choices("yes(yes,y,1), no(no,n,2)");
// (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
tropo.ask(choices, null, null, null, "reminder", null, null, say, 60, null);
tropo.on("continue", null, "/continue", true);
tropo.on("incomplete", null, "/incomplete", true);
res.send(TropoJSON(tropo));
});
app.post('/continue', function(req, res){
var tropo = new TropoWebAPI();
var answer = req.body['result']['actions']['value'];
if(answer == "yes") {
tropo.say("Ok, just checkin.");
res.send(TropoJSON(tropo));
}
else {
tropo.say("What are you waiting for?");
res.send(TropoJSON(tropo));
}
});
app.post('/incomplete', function(req, res){
var tropo = new TropoWebAPI();
tropo.say("Sorry, that wasn't on of the options.");
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();
$tropo->call("+14155550100", array('network'=>'SMS'));
// Set up options for input.
$options = array("choices" => "yes(yes,y,1), no(no,n,2)", "name" => "reminder", "timeout" => 60);
// Ask the caller for input, pass in options.
$tropo->ask("Hey, did you remember to take your pills?", $options);
$tropo->on(array("event" => "continue", "next" => "hello_world.php?uri=continue"));
$tropo->on(array("event" => "incomplete", "next" => "hello_world.php?uri=incomplete"));
$tropo->RenderJson();
}
dispatch_post('/continue', 'app_continue');
function app_continue() {
$tropo = new Tropo();
@$result = new Result();
$choice = $result->getValue();
if ($choice == "yes")
{
$tropo->say("Ok, just checkin.");
}
else
{
$tropo->say("What are you waiting for?");
}
$tropo->RenderJson();
}
dispatch_post('/incomplete', 'app_incomplete');
function app_incomplete() {
$tropo = new Tropo();
$tropo->say("Sorry, that wasn't on of the options.");
$tropo->RenderJson();
}
run();
?>
from itty import *
from tropo import Tropo, Result
@post('/index.json')
def index(request):
t = Tropo()
t.call(to="+14155550100", network = "SMS")
t.ask(choices = "yes(yes,y,1), no(no,n,2)", timeout=60, name="reminder", say = "Hey, did you remember to take your pills?")
t.on(event = "continue", next ="/continue")
t.on(event = "incomplete", next ="/incomplete")
return t.RenderJson()
@post("/continue")
def index(request):
r = Result(request.body)
t = Tropo()
answer = r.getValue()
if answer == "yes" :
t.say("Ok, just checkin.")
else :
t.say("What are you waiting for?")
return t.RenderJson()
@post("/incomplete")
def index(request):
t = Tropo()
t.say("Sorry, that wasn't on of the options.")
return t.RenderJson()
run_itty(server='wsgiref', host='0.0.0.0', port=8888)