ini_set('display_errors', 0);
require __DIR__ . '/vendor/autoload.php';
use PAMI\Client\Impl\ClientImpl;
use PAMI\Listener\IEventListener;
use PAMI\Message\Event\EventMessage;
use PAMI\Message\Action\OriginateAction;
use \PAMI\Message\Event\NewchannelEvent;
class A implements IEventListener
{
public $result;
public function handle(EventMessage $event)
{
if ($event instanceof \PAMI\Message\Event\NewchannelEvent) {
$this->result = $event->getUniqueID();
return $this->result;
}
}
}
$agent = $_GET['agent'];
$extension = $_GET['extension'];
$destination = $_GET['destination'];
while ($agent && $extension) {
echo "No agent and extension possible!";
exit;
}
include "config.php";
$a = new ClientImpl($options);
$a->open();
$ClassA = new A();
$a->registerEventListener($ClassA);
while ($agent && $destination) {
echo "Agent && Destination";
$result = makecallagent($a,$agent,$destination);
$arr = array('success' => false, 'errormsg' => $result);
if ($result === true)
$arr = array('success' => $result,'errormsg' => NULL, 'uniqueid' => $ClassA->result);
echo json_encode($arr);
$a->close();
exit;
}
while ($extension && $destination) {
$result = makecall($a,$extension,$destination);
$arr = array('success' => false, 'errormsg' => $result);
if ($result === true)
$arr = array('success' => $result,'errormsg' => NULL, 'uniqueid' => $ClassA->result);
echo json_encode($arr);
$a->close();
exit;
}
echo "No extension\agent and destination correctly passed";
exit;
function makecall($a,$source,$number) {
$originateMsg = new OriginateAction("PJSIP/$source");
$originateMsg->setContext('from-internal');
$originateMsg->setPriority('1');
$originateMsg->setExtension("$number");
$res = $a->send($originateMsg);
if ($res->isSuccess()) return true; //return tru if originating success
return $res->getKeys()['message']; //otherwise return error message
}
function makecallagent($a,$source,$number) {
$originateMsg = new OriginateAction("Local/28@queuemetrics");
$originateMsg->setContext('queuemetrics');
$originateMsg->setPriority('1');
$originateMsg->setVariable('AGENTCODE',$source);
$originateMsg->setVariable('QDIALER_QUEUE','outqueue');
$originateMsg->setVariable('EXTTODIAL',$number);
$originateMsg->setExtension("28");
$res = $a->send($originateMsg);
if ($res->isSuccess()) return true; //return tru if originating success
return $res->getKeys()['message']; //otherwise return error message
}
Leave a Reply