| Tropo WebAPI Development Guide | Home | Frameset Home |
|
startRecording and stopRecording can make that happen for you and works with both inbound and outbound calls. The following example starts recording as soon as the call is placed and asks the caller for their favorite color up to three times (repeated only if they give invalid answers). It then disconnects the call and sends the recording to the specified URL:
require 'tropo-webapi-ruby'
require 'sinatra'
post '/index.json' do
t = Tropo::Generator.new
t.start_recording :url => "http://example.com/recording.rb"
t.ask :name => 'color',
:attempts => 3,
:say => {:value => "What's your favorite color? Choose from red, blue or green."},
:choices => {:value => "red, blue, green"}
t.stop_recording
t.response
end
var http = require('http');
var tropo_webapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
var tropo = new TropoWebAPI();
var say = new Say("What's your favorite color? Choose from red, blue or green.");
var choices = new Choices("red, blue, green");
//format, method, url, username, password
tropo.startRecording(null, null, "http://example.com/recording.js", null, null);
// (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
tropo.ask(choices, 3, null, null, "color", null, null, say, null, null);
tropo.stopRecording();
response.end(TropoJSON(tropo));
}).listen(8000);
<?php
require 'tropo.class.php';
$tropo = new Tropo();
$tropo->startRecording(array("url" => "http://example.com/recording.php"));
$options = array("choices" => "red, blue, green", "name" => "color", "attempts" => 3);
$tropo->ask("What's your favorite color? Choose from red, blue or green.", $options);
$tropo->stopRecording();
$tropo->RenderJson();
?>
from itty import *
from tropo import Tropo
@post('/index.json')
def index(request):
t = Tropo()
t.startRecording(url = "http://example.com/recording.py")
t.ask(choices = "red, blue, green", timeout=60, name="color", say = "What's your favorite color? Choose from red, blue or green.")
t.stopRecording()
return t.RenderJson()
run_itty(server='wsgiref', host='0.0.0.0', port=8888)
{
"tropo":[
{
"startRecording":{"url":"http://example.com/recording.php"}
},
{
"ask": {
"say":{"value": "What's your favorite color? Choose from red, blue or green."},
"attempts":3,
"name": "color",
"choices": {"value": "red, blue, green"}
}
},
{
"stopRecording":null
}
]
}
call method at the very beginning, just before startRecording.recording to the call method will automatically start a recording as soon as the call is answered, then when the call ends, the recording will be sent to the URL you defined in the parameter.
require 'tropo-webapi-ruby'
require 'sinatra'
post '/index.json' do
t = Tropo::Generator.new
t.call(:to => "+14075550100",
:recording => {:url => "http://example.com/recording.rb"})
t.ask :say => {:value => "Please say your account number"},
:choices => {:value => "[5 DIGITS]"}
t.response
end
var http = require('http');
var tropo_webapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
var tropo = new TropoWebAPI();
//(format, method, url, username, password)
var recording = new startRecording(null, null, "http://example.com/recording.php", null, null);
//(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout)
tropo.call("+14075550100", null, null, null, null, null, null, recording, null, null);
var say = new Say("Please say your account number");
var choices = new Choices("[5 DIGITS]");
// (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice)
tropo.ask(choices, null, null, null, "digits", null, null, say, null, null);
response.end(TropoJSON(tropo));
}).listen(8000);
<?php
require 'tropo.class.php';
$tropo = new Tropo();
//$format, $method, $password, $url, $username)
$rec = new StartRecording(null,null,null,"http://example.com/recording.php", null);
$options = array("recording" => $rec);
$tropo->call("+14075550100", $options);
$tropo->ask("Please say your account number", array("choices" => "[5 DIGITS]"));
$tropo->RenderJson();
?>
from itty import *
from tropo import Tropo
@post('/index.json')
def index(request):
t = Tropo()
t.call("+14075550100", recording={"url":"http://example.com/recording.php"})
t.ask(choices = "[5 DIGITS]", say = "Please say your account number")
return t.RenderJson()
run_itty(server='wsgiref', host='0.0.0.0', port=8888)
{"tropo":[
{
"call":{
"to":"+14075550100",
"recording":{"url":"http://example.com/recording.php"}
}
},
{
"ask":{
"say":{"value":"Please say your account number"},
"choices":{"value":"[5 DIGITS]"}
}
}
]
}
| ANNOTATIONS: EXISTING POSTS |
| login |
|