简体   繁体   中英

Asterisk Server Pass Variable from Dialplan to AGI Script

My Dialplan is like this

[dial-plan]
exten => s,1,Answer()
exten => s,n,Noop(exten = ${EXTEN}
exten => s,n,Macro(dumpvars)
exten => s,n,Macro(record-enable)
exten => s,n,AGI(success.php)
exten => i,1,Noop(REASON = ${REASON})
exten => i,n,Macro(dumpvars)
exten => i,n,AGI(faile.php)
exten => failed,1,Noop(REASON = ${REASON})
exten => failed,n,Macro(dumpvars)
exten => failed,n,AGI(faile.php)

I want to catch from where faile.php called , It may be called from failed or from i . How can I check this

I need to make like this is faile.php

if($some_var == 1){
     //Invalid
}
elsif($some_var == 2){
    //Failed
}

The agi will be called with some standard paramaters, include the called-from extension (in your case, that will be i or failed ). Make sure you are parsing the arguments being passed to your script (via stdin)!

Use phpagi.php in your script, it provide all required parsing for AGI.

Or see examples at http://www.voip-info.org/wiki/view/Asterisk+AGI+php

If I understood your question correctly, you need to pass a variable to your PHP AGI script. Here's how to do it:

exten => i,n,AGI(faile.php,invalid)

exten => failed,n,AGI(faile.php,failed)

And then, your PHP AGI script should look like this:

#!/usr/bin/php -q
<?php
set_time_limit(30);
//load PHP AGI
require('phpagi/phpagi.php');
error_reporting(E_ALL);
$agi = new AGI();

$status = $argv[1];

if($status == "invalid")
{
  // invalid
} else
{ 
  // failed
}
?>

Here is how I implemented same with php-agi.php

failed.php (will execute if call failed)

<?php
    require_once "phpagi.php";
    require_once "phpagi-asmanager.php";

    $astman = new AGI();
    $astman->set_variable('CallState','failed');

?>

success.php (will execute if call success)

<?php
    require_once "phpagi.php";
    require_once "phpagi-asmanager.php";

    $astman = new AGI();
    $astman->set_variable('CallState','success');

?>

hangup.php (will execute on end of the call, if call failed or success)

<?php
    require_once "phpagi.php";
    require_once "phpagi-asmanager.php";

    $astman = new AGI();
    $call_state = agi_get_var('CallState');
    if($call_state == "success"){
        //call was success
    }
    elseif($call_state == "failed"){
        //call was failed
    }
?>

In Dialplan

exten => _*999*.,1,Answer()
exten => _*999*.,n,Set(var1=1) 
exten => _*999*.,n,AGI(test.php,${var1})

In php

<?php
    require('phpagi.php');

    $agi = new AGI();

    $agi->say_digit($argv[1]);

    $agi->hangup();
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM