Tropo WebAPI Development Guide Home  |  Frameset Home

  CallerID - Reading & Setting  |  TOC  |  Advanced Speech Control  

SIP Headers - Retrieving & Sending


SIP headers are extremely useful - they provide a wealth of information about an incoming call, as well as enable you to define a variety of settings, such as toggling answerOnMedia on or off. Every Tropo call contains some SIP headers by default; carriers or SIP networks can define a wide variety of additional options as well. All included SIP headers are displayed in the Tropo logs, including the debugger - here's an example:


Sending SIP Headers


You can add custom headers when invoking a call or transfer method by using the headers attribute; make sure to include x- for your customer headers, e.g. test-header becomes x-test-header. The header will be downcased, so if you needed to access x-Test-Header later, it would need to be written it as x-test-header. Here's an example:

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

post '/' do
  
  tropo = Tropo::Generator.new 
    
  tropo.say "Hello...transferring"
  
  tropo.transfer :to => username@sip.server.com',
                 :headers => {'x-callername' => 'Kevin Bond'}

end
var http = require('http');
var tropo_webapi = require('tropo-webapi');
 
var server = http.createServer(function (request, response) {

	var tropo = new TropoWebAPI();

	tropo.say("Hello...transferring");
	//to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout
	tropo.transfer('username@sip.server.com', null, null, null, {'x-callername' : 'Kevin Bond'}, null, null, true, null, null);

	response.end(TropoJSON(tropo));

}).listen(8000);
<?php

require 'tropo.class.php';

$tropo = new Tropo();

$tropo->say("Hello...transferring");
$tropo->transfer('username@sip.server.com', array('headers' => array('x-callername' => 'Kevin Bond')));
$tropo->RenderJson();

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

@post('/')
def index(request):

  s = Session(request.body)
  t = Tropo()

  t.say("Hello...transferring")
  t.transfer(to="username@sip.server.com", headers={"x-callername":"Kevin Bond"})
  return t.RenderJson()

run_itty()

Retrieving Individual SIP Headers


You'll also want to use a header sent to an app...in order to retrieve the information for a particular SIP header, you would use a method defined in one of the libraries to extract it. Below we'll show an example that retrieves the content from the custom header 'x-callername' (same one we set previously). Note that headers will be downcased, so if you need to access something like x-Test-Header, you would need to write it as x-test-header.

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

post '/' do

  t = Tropo::Generator.new
  v = Tropo::Generator.parse request.env["rack.input"].read

  getHeader = v[:session][:headers]['x-callername']
  
  t.say :value => "Hello " + getHeader
  
  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 getHeader = session.session.headers['x-callername'];

            tropo.say("Hello" + getHeader);

            response.end(TropoJSON(tropo));
        });
    
}).listen(8000);
<?php

require 'tropo.class.php';

$tropo = new Tropo();
$session = new Session();
$headers = $session->getHeaders();

$tropo->say("Hello, {$headers->x_callername}");

$tropo->RenderJson();

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

@post('/')

def index(request):
  
  s = Session(request.body)
  t = Tropo()
  
  getHeader = s.headers['x-callername']

  t.say ("Hello " + getHeader)

  return t.RenderJson()

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

This blogpost explains how using x-voxeo-to could enable you to determine the inbound network used to place the call.

This by no means covers all the potential uses of headers, but should at the very least help explain how to start using them with Tropo.



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

login
  CallerID - Reading & Setting  |  TOC  |  Advanced Speech Control  

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