通話プロパティ|Tropo Web API

   

WebAPIでは、全ての発信者がJSONのセッション - to , from , initialText に保存されます。

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 == "0901234XXXX" || callerID == "039876XXXX")
    t.reject
  else
    t.say(:value => "こんにちは")
  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 == "0901234XXXX" || callerID == "039876XXXX")
        tropo.reject();
    else
        tropo.say("こんにちは");
    
    response.end(TropoJSON(tropo));
});

}).listen(8000); 
<?php

require 'tropo.class';

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

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

if ($callerID == '0901234XXXX' || $callerID == '039876XXXX') 
    $tropo->reject();
else
    $tropo->say("こんにちは");
    
$tropo->RenderJson();

?>
from itty import *
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 == '039876XXXX' or callerID == '0901234XXXX') :
        t.reject()
    else :
        t.say("こんにちは")
        
    return t.RenderJson()

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

次は、callerIDの機能について説明します。