|
|
|
require_once 'vendor/autoload.php'; |
|
require_once 'configlocal.php'; |
|
|
|
|
|
use PAMI\Client\Impl\ClientImpl; |
|
use PAMI\Listener\IEventListener; |
|
use PAMI\Message\Event\EventMessage; |
|
use PAMI\Message\Action\OriginateAction; |
|
use PAMI\Message\Action\StatusAction; |
|
|
|
|
|
class PamiEventListener implements IEventListener |
|
{ |
|
|
|
public function __construct($cli) |
|
{ |
|
$this->cli = $cli; |
|
|
|
} |
|
|
|
|
|
/** |
|
* To Handle the All Pami Events |
|
* @param EventMessage $event |
|
*/ |
|
public function handle(EventMessage $event) |
|
{ |
|
|
|
echo $strevt = $event->getKeys()['event']; |
|
$this->var_error_log($event->getKeys()); |
|
|
|
if ($strevt == 'DialBegin') { |
|
echo "DialBegin event --- \n"; |
|
|
|
} |
|
if ($strevt == 'DialEnd') { |
|
echo "Dial end event --- \n"; |
|
|
|
} |
|
|
|
if ($strevt == 'Hangup') { |
|
echo "Hangup event --- \n"; |
|
|
|
} |
|
} |
|
|
|
|
|
|
|
public function var_error_log($object = null) |
|
{ |
|
$datetime = date("Y-m-d h:i:s a"); |
|
|
|
$contents = PHP_EOL . $datetime . " :"; |
|
ob_start(); // start buffer capture |
|
var_dump($object); // dump the values |
|
$contents .= ob_get_contents(); // put the buffer into a variable |
|
ob_end_clean(); // end capture |
|
//create the log file if not exist |
|
$log_file_path = "log.txt"; |
|
|
|
|
|
if (file_exists($log_file_path) == false) { |
|
fopen($log_file_path, "w"); |
|
} |
|
error_log($contents, 3, $log_file_path); |
|
} |
|
|
|
} |
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
// Code STARTS. |
|
//////////////////////////////////////////////////////////////////////////////// |
|
error_reporting(E_ALL); |
|
ini_set('display_errors', 1); |
|
try { |
|
$options = array( |
|
'host' => 122.111.111.222, |
|
'scheme' => 'tcp://', |
|
'port' => 5038, |
|
'username' => 'testuser', |
|
'secret' => '#######', |
|
'connect_timeout' => 10, |
|
'read_timeout' => 10000000 |
|
); |
|
|
|
$phonenumber=1000; |
|
$sipNumber=20000; |
|
|
|
$a = new ClientImpl($options); |
|
|
|
$eventListener = new PamiEventListener($a); |
|
$a->registerEventListener($eventListener); |
|
$a->open(); |
|
$time = time(); |
|
while (true) { |
|
//(time() - $time) < 60) // Wait for events. |
|
usleep(1000); // 1ms delay |
|
//check the Avilable Agents status |
|
|
|
|
|
$actionid = md5(uniqid()); |
|
$response = $a->send(new StatusAction()); |
|
|
|
$originateMsg = new OriginateAction('SIP/' . $phonenumber . "@voipgw"); |
|
$originateMsg->setContext('dialer'); |
|
$originateMsg->setPriority('1'); |
|
$originateMsg->setExtension($sipNumber); |
|
$originateMsg->setCallerId($sipNumber); |
|
$originateMsg->setAsync(false); |
|
$originateMsg->setActionID($actionid); |
|
$orgresp = $a->send($originateMsg); |
|
$orgStatus = $orgresp->getKeys()['response']; |
|
|
|
// Since we declare(ticks=1) at the top, the following line is not necessary |
|
$a->process(); |
|
} |
|
$a->close(); // send logoff and close the connection. |
|
} catch (Exception $e) { |
|
echo $e->getMessage() . "\n"; |
|
} |