如何将PAMI与我的Web应用程序集成?

时间:2019-05-03 13:22:01

标签: php asterisk

我想将PAMI与我的Web应用程序集成,该应用程序应该打开一个特定的URL,该URL只是传入呼叫者的应用程序中的网页(呼叫者的详细信息)。 我有PAMI的api详细信息,例如主机名,用户名,密码,端口号。

我的问题是:如何运行每种条件,以便每次在呼叫中发生不同事件(例如振铃,不响应,被接收者拒绝,被接收者应答,呼叫结束)时仅运行一次。 (下面的代码进行描述)。

我使用(http://marcelog.github.io/PAMI)中的示例代码来实现我想要的功能,但是我陷入了困境。

以下是我到目前为止已实现的代码

<?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();
?>

来自星号服务器的响应如下:

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 个答案:

没有答案