AGI
MikoPBX describes its own implementation of the PHP-AGI library.
Example of a simple PHP script:
<?php
use MikoPBX\Core\Asterisk\AGI;
require_once 'Globals.php';
$agi = new AGI();
$agi->Answer();
$agi->exec_goto('internal', '2001', '1');Get extension state
<?php
function getExtensionStatus($number): int
{
global $agi;
$state = $agi->get_variable("DEVICE_STATE(PJSIP/$number)", true);
$dExists = $agi->get_variable("DIALPLAN_EXISTS(internal,$number,1)", true);
$this->Verbose("DEVICE_STATE: {$state} DIALPLAN_EXISTS: $dExists");
$stateTable = [
'UNKNOWN' => ['Status'=> -1, 'StatusText' => 'Unknown'],
'INVALID' => ['Status'=> -1, 'StatusText' => 'Unknown'],
'NOT_INUSE' => ['Status'=> 0, 'StatusText' => 'Idle'],
'INUSE' => ['Status'=> 1, 'StatusText' => 'In Use'],
'BUSY' => ['Status'=> 2, 'StatusText' => 'Busy'],
'UNAVAILABLE' => ['Status'=> 4, 'StatusText' => 'Unavailable'],
'RINGING' => ['Status'=> 8, 'StatusText' => 'Ringing'],
'ONHOLD' => ['Status'=> 16, 'StatusText' => 'On Hold'],
];
if($state === 'INVALID' && $dExists === '1'){
$result = $stateTable['NOT_INUSE'];
}else{
$result = $stateTable[$state]??$stateTable['UNKNOWN'];
}
return $result;
}Example of a Number input request (IVR)
Last updated
Was this helpful?