クイックスタート|Tropo Web API

着信拒否

   

着信拒否は、非常に簡単です。通常は、callerIDに基づいてコールを拒否する場合が多いでしょう。下記はその例です。

 
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" || callerID == "9165550100")
    t.reject
  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" || callerID == "9165550100")
        tropo.reject();
    else
        tropo.say("Hi friend!");
    
    response.end(TropoJSON(tropo));
});

}).listen(8000); 
<?php

require 'tropo.class';

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

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

if ($callerID == '4075550100' || $callerID == '9165550100') 
    $tropo->reject();
else
    $tropo->say("Hi friend!");
    
$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 == '9165550100' or callerID == '4075550100') :
        t.reject()
    else :
        t.say("Hi friend!")
        
    return t.RenderJson()

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

 

また、transferと組み合わせることができます。

 
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" || callerID == "9165550100")
    t.reject
  elsif (callerID == "3865550100")
    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" || callerID == "9165550100")
        tropo.reject();
    else if(callerID == "3865550100")
        tropo.transfer("+13217105094");
    else
        tropo.say("Hi friend!");
    
    response.end(TropoJSON(tropo));
});

}).listen(8000); 
<?php

require 'tropo.class';

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

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

if ($callerID == '4075550100' || $callerID == '9165550100') 
    $tropo->reject();
else
    $tropo->say("Hi friend!");
    
$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 == '9165550100' or callerID == '4075550100') :
        t.reject()
    elif (callerID == '3865550100') :
        t.transfer("+13217105094")
    else :
        t.say("Hi friend!")
        
    return t.RenderJson()

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

 

カンファレンスコール、多人数通話をご希望の場合は、次の項目をご覧ください。