Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating PAMI with my Web Application #184

Open
fazalm13 opened this issue May 2, 2019 · 0 comments
Open

Integrating PAMI with my Web Application #184

fazalm13 opened this issue May 2, 2019 · 0 comments

Comments

@fazalm13
Copy link

fazalm13 commented May 2, 2019

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.
I used your sample code to achieve what I wanted to but I'm stuck at a point.

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).

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
)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant