Tropo WebAPI Development Guide Home  |  Frameset Home

  Controlling Calls  |  TOC  |  Rejecting a Call  

Transferring a Call


At some point, the majority of applications will find a use for transfer, whether it's a voicemail system with caller selection options, blind moves based on callerID or middle-of-a-call transfers to move a caller to a different application - all of it can be handled by Tropo with relatively little code.

Here's the simplest form of transfer:

require 'tropo-webapi-ruby'
require 'sinatra'

post '/index.json' do
  
  t = Tropo::Generator.new
  
  t.say(:value => "Transferring you now, please wait.")
  t.transfer(:to => "+14075550100")
  
  t.response
  
end
var http = require('http');
var tropo_webapi = require('tropo-webapi');

var server = http.createServer(function (request, response) {  
  
	var tropo = new TropoWebAPI();

	tropo.say("Transferring you now, please wait.");
	tropo.transfer("+14075550100");
	
	response.end(TropoJSON(tropo));

}).listen(8000); 
<?php

require 'tropo.class.php';

$tropo = new Tropo();

$tropo->say("Transferring you now, please wait");
$tropo->transfer("+14075550100");
	
$tropo->RenderJson();

?>
from itty import *
from tropo import Tropo

@post('/index.json')

def index(request):

	t = Tropo()
	
	t.say("Transferring you now, please wait.")
	t.transfer("+14075550100")

	return t.RenderJson()

run_itty(server='wsgiref', host='0.0.0.0', port=8888)
{"tropo":[
      {
         "say":[{"value":"Transferring you now, please wait."}]
      },
      {
         "transfer":{"to":"+14075550100"}
      }
   ]}

You can get fancier, however. The following example adds multiple destinations as an array (first to answer wins!), then adds hold music and a terminator to cancel the transfer, all with just a little extra code:

require 'tropo-webapi-ruby'
require 'sinatra'

post '/index.json' do
  
  t = Tropo::Generator.new
  
  t.say(:value => "Transferring you now, please wait.")
  t.transfer(:to => ["+14075550100", "+18005550100"],
            :choices => {:terminator => "#"},
            :on => {:event => "ring", :say => {:value => "http://www.phono.com/audio/holdmusic.mp3"}})
  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("http://www.phono.com/audio/holdmusic.mp3");
	var choices = new Choices(null, null, "#");
	var on = {"event":"ring", "say": say};
	
	tropo.say("Transferring you now, please wait.");
	
	//to, answerOnMedia, choices, from, name, on, required, timeout
	tropo.transfer(["+14075550100","+18005550100"], null, choices, null, null, on, null, null);
	
	response.end(TropoJSON(tropo));

}).listen(8000); 
<?php 
 
require 'tropo.class.php';

$tropo = new Tropo();
$choices = new Choices(null, null, "#");
$say = new Say("http://www.phono.com/audio/holdmusic.mp3"); 
$on = new On("ring", null, $say); 

$options = array(
          'choices' => $choices,
          'on' => $on
		);
 
$tropo->say("Transferring you now, please wait");
$tropo->transfer(array("+14074095231", "+18005550100"), $options);
     
$tropo->RenderJson();
 
?>
from itty import *
from tropo import Tropo

@post('/index.json')

def index(request):

	t = Tropo()
	
	t.say("Transferring you now, please wait.")
	t.transfer(["+14075550100","18005550100"], choices = {"terminator":"#"}, on = {"event":"ring", "say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}})

	return t.RenderJson()

run_itty(server='wsgiref', host='0.0.0.0', port=8888)
{"tropo":[
      {
         "say":[{"value":"Transferring you now, please wait."}]
      },
      {
         "transfer":{
            "to":["+14075550100","+18005550100"],
            "choices":{"terminator":"#"},
            "on":{
               "say":{"value":"http://www.phono.com/audio/holdmusic.mp3"},
               "event":"ring"
            }
         }
      }
   ]}

How about the blind move based on callerID? Note, this will only work with a library, since you need to extract info from the session.

require 'tropo-webapi-ruby'
require 'sinatra'

post '/index.json' do
  
  v = Tropo::Generator.parse request.env["rack.input"].read
  t = Tropo::Generator.new
  
  callerID = v[:session][:from][:id]
  
  if (callerID == "4075550100")
    t.transfer(:to => "+13217105094")
  else
    t.say(:value => "Hi friend!")
  end
  
  t.response
  
end
var http = require('http');
var tropo_webapi = require('tropo-webapi');

var server = http.createServer(function (request, response) {  
  
  request.addListener('data', function(data){
    json = data.toString();
  });
    
  request.addListener('end', function() {

	var session = JSON.parse(json);
	var tropo = new TropoWebAPI();
	var callerID = session.session.from.id;
	
	if(callerID == "4075550100")
		tropo.transfer("+13217105094");
	else
		tropo.say("Hi friend!");
	
    response.end(TropoJSON(tropo));
});

}).listen(8000); 
<?php

require 'tropo.class.php';

$tropo = new Tropo();
$session = new Session();

$from = $session->getFrom();
$callerID = $from["id"];

if ($callerID == '4075550100')
	$tropo->transfer("+13217105094");
else
	$tropo->say("Hi friend!");
	
$tropo->RenderJson();

?>
from itty import *
from tropo import Tropo, Session

@post('/index.json')

def index(request):

	s = Session(request.body)
	callerID = s.fromaddress['id']
	t = Tropo()

	if(callerID == '4075550100') :
		t.transfer("+13217105094")
	else :
		t.say("Hi friend!")
		
	return t.RenderJson()

run_itty(server='wsgiref', host='0.0.0.0', port=8888)

Need to block a phone number all together, instead of transferring it somewhere else? Tropo's got you covered there, too.

Next Step: Rejecting a Call


  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login
  Controlling Calls  |  TOC  |  Rejecting a Call  

© 2012 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site