Tropo is part of CiscoLearn More

Call & Message Properties

In WebAPI, all of the properties for a call or a text message are stored in the session JSON - the to, the from, the initialText if it's a text message, the channel and network info, etc. The method to extract them for use varies from library to library:

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

post '/index.json' do
  
  v = Tropo::Generator.parse request.env["rack.input"].read
  
  to = v[:session][:from][:id]
  n = v[:session][:from][:network]

  t = Tropo::Generator.new
  
  t.say(:value => "Hello " + from + ", on the " + n + " network.")
  
  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 from = session.session.from.id;
		var n = session.session.from.network;
		
		tropo.say("Hello " + from + ", on the " + n + " network.");
	
		response.end(TropoJSON(tropo));
	});

}).listen(8000); 
<?php

require 'tropo.class.php';

$session = new Session(); 
$from = $session->getFrom(); 
$n = $session->getFrom(); 
    
$tropo = new Tropo(); 

$tropo->say("Hello " . $from['id'] . ", on the " . $n['network'] . " network."); 

return $tropo->RenderJson(); 

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

@post('/index.json')

def index(request):

    s = Session(request.body)
    t = Tropo()
    to = s.fromaddress['id']
    n = s.fromaddress['network']

    t.say("Hello " + to + ", on the " + n + " network.")

    return t.RenderJson()

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

CallerID can be a bit complex, both for voice and text - if you're interested in working with it, it's definitely recommended to review the following chapter first.