Controlling asterisk call logic through web-service - Consuming Dot Net web-service in PHP

This is a sample code on how we can use PHP web-service to control incoming call logic in asterisk . Im using nusoup and phpagi library to connect to ASP.NET web-service and play the appropriate file based on status receiving .
User will call the asterisk system and enter a code . Code and caller-id are sending to script with arguments ( argv[1] and argv[2] ) . appropriate file will play based on status receiving by web-service



#!/usr/bin/php -q
<?
set_time_limit(30);
require('phpagi/phpagi.php');
require_once ('lib/nusoap.php');
error_reporting(E_ALL);
$agi = new AGI();
$code = $argv[1];
$callerid = $argv[2];
$client = new nusoap_client('http://localhost/services/namad.asmx?WSDL', 'WSDL');


$error = $client->getError();
if ($error) {
    die("client construction error: {$error}\n");
}

$params=array('pwd'=>'T3D8askjls', 'phonenumber'=>$callerid ,'code'=>$code);

$answer = $client->call('TelCheck', $params);


$error = $client->getError();
if ($error) {
    print_r($client->response);
    print_r($client->getDebug());
    die();
 }


switch ($answer[status])
{

case 0 :
    $agi->stream_file("/usr/local/src/error");
    break;
case 1 :
    $agi->stream_file("/usr/local/src/accepted");
    break;
case 2 :
    $agi->stream_file("/usr/local/src/wrongcallerid");
    break;
case 3 :
    $agi->stream_file("/usr/local/src/wrongcode");
    break;
}


?>

                                      

Comments

  1. Thank U for the solution, but i have any pair questions, do you have an method for integration between agi file into web to vicidial, on menu for creation to IVR? sorry for my bad english and i will wait any answer of your person

    ReplyDelete
  2. Hi Miguel.

    If you want to use in IVR maybe its simpler to user extensions.conf to create IVR with your AGI and then just route to the destination you want .

    ReplyDelete

Post a Comment