I want to integrate PAMI with my web application which should open a particular URL which is nothing but a web page in our application (Details of the caller) of the incoming caller. I have the api details of PAMI e.g hostname,username,password,port no.

My question is: How do I run every condition so that it runs only one time whenever different event occurs in a call like Ringing,Not responding,Rejected by receiver,Answered by receiver,Call ended. (Below code for description).

I used the sample code from (http://marcelog.github.io/PAMI) to achieve what I wanted to but I'm stuck at a point.

Following is the code which I have implemented so far

<?php

// declare(ticks=1);
require 'vendor/autoload.php';
$options = array(
   'host' => 'sip3.intupbx.wave-tell.com',
   'scheme' => 'tcp://',
   'port' => 5039,
   'username' => 'someusername',
    'secret' => '******',
   'connect_timeout' => 1000,
   'read_timeout' => 1000
);
$client = new \PAMI\Client\Impl\ClientImpl($options);
// Open the connection
$client->open();
use PAMI\Message\Event\EventMessage;
use PAMI\Listener\IEventListener;
use PAMI\Message\Event\HangupEvent;
// use PAMI\Listener\IEventListener;

$running = true;
while($running) {
  $client->registerEventListener(function ( $event) {
    $eventType = $event->getKeys()['event'];
    $stateType = $event->getKeys()['channelstatedesc'];
    if($eventType=='Newstate' && $stateType=='Ring'){
      echo('Ringing..');
      // Perform some Database Query and custom event perform by web app.
      // Show StateType on Popup Screen in web app.
    }
    else if($eventType=='HangupRequest' && $stateType=='Ringing'){
      echo('Not Responding..');
      // Show StateType on Popup Screen in web app.
    }
    else if($eventType=='Hangup' && $stateType=='Ringing'){
      echo('Rejected by receiver..');
      // Show StateType on Popup Screen in web app.
    }
    else if($eventType=='Newstate' && $stateType=='Up'){
      echo('Answered by receiver..');
      // Show StateType on Popup Screen in web app.
    }
    else if($eventType=='HangupRequest' && $stateType=='Up'){
      echo('Call Ended..');
      // Show StateType on Popup Screen in web app.
    }
    echo '<pre>';print_r($event);
    die;
  });
    $client->process();
    usleep(1000);
}
// Close the connection
$client->close();
?>

Response from the asterisk server is as follows:

Ringing..

PAMI\Message\Event\NewstateEvent Object
(
    [rawContent:protected] => Event: Newstate
Privilege: call,all
SystemName: pbx03
Channel: SIP/200-WTC-000b5da0
ChannelState: 4
ChannelStateDesc: Ring
CallerIDNum: 200
CallerIDName: 200-WTC
ConnectedLineNum: 
ConnectedLineName: 
Language: en
AccountCode: WTC
Context: authenticated
Exten: 201
Priority: 1
Uniqueid: pbx03-1556624215.8440298
Linkedid: pbx03-1556624215.8440298
    [channelVariables:protected] => Array
        (
            [sip/200-wtc-000b5da0] => Array
                (
                )

        )

    [lines:protected] => Array
        (
        )

    [variables:protected] => Array
        (
        )

    [keys:protected] => Array
        (
            [event] => Newstate
            [privilege] => call,all
            [systemname] => pbx03
            [channel] => SIP/200-WTC-000b5da0
            [channelstate] => 4
            [channelstatedesc] => Ring
            [calleridnum] => 200
            [calleridname] => 200-WTC
            [connectedlinenum] => 
            [connectedlinename] => 
            [language] => en
            [accountcode] => WTC
            [context] => authenticated
            [exten] => 201
            [priority] => 1
            [uniqueid] => pbx03-1556624215.8440298
            [linkedid] => pbx03-1556624215.8440298
        )

    [createdDate:protected] => 1556624215
)

0 Answers