hsyir/simotel-php-connect

用 PHP 与 simotel 保持连接

dev-main 2021-07-25 15:49 UTC

This package is auto-updated.

Last update: 2024-09-14 15:22:00 UTC


README

Build Status StyleCI

Simotel 和 Laravel

如果您想通过 Laravel 连接到 simotel,请访问我们的 Laravel 包:nasimtelecom/simotel-laravel-connect

通过 PHP 与 Simotel 保持连接。Simotel 是一款功能强大的呼叫中心软件。请在此处查看 Simotel 文档:doc.mysup.ir

使用此包,您可以轻松通过 PHP 连接到 simotel 服务器并执行一些令人惊叹的操作。

安装

使用 composer 安装和自动加载包

composer require nasimtelecom/simotel-php-connect

Simotel Api

Simotel Api 帮助您远程连接到 simotel 服务器并管理 simotel 用户、队列、中继、公告、获取报告、发送传真以及与 Simotel 呼叫中心的所有操作。

simotel api 连接

use \Hsy\Simotel\Simotel;
use \Hsy\Simotel\SimotelApi\Parameters;

$config = Simotel::getDefaultConfig();
$config["simotelApi"]["connect"]=[
    'user'=> 'apiUser',
    'pass'=> 'apiPass',
    'token'=> 'apiToken',
    'server_address' => 'http://simotelServer',
                                 
];

$simotel = new Simotel($config);

$parameters = new Parameters();
$parameters->name = "user name";
$parameters->number = "101";
$parameters->secret = "password";
  
/**  
 * result is instance of \Psr\Http\Message\ResponseInterface  
 */
$result = $simotel->connect()->pbx()->users()->add($parameters);

Simotel 事件 Api

  1. 为事件创建监听器
$simotel = new Simotel();
$simotel->eventApi()->addListener('Cdr', function ($simotelApiData) {
    var_dump($simotelApiData);
});
  1. 在您的 api 端点接收到 simotel 事件 api 的请求后,发送事件

您必须在 Simotel 设置中放置您的 api 端点地址

use \Hsy\Simotel\Simotel;
$simotelEventApiData =  $_POST["api_data"];
$eventName = $_POST["api_data"]["event_name"];
$simotel = new Simotel();
$simotel->eventApi()->dispatch($eventName,$simotelEventApiData);

Simotel 智能Api

  1. 创建由智能 api 应用程序调用的 smartApp 类和方法

不要忘记导入 SmartApiCommands 特性

use Hsy\Simotel\SimotelSmartApi\SmartApiCommands;


class PlayWelcomeMessage
{
    use SmartApiCommands;
    
    public function playAnnounceApp($appData)
    {
        $this->cmdPlayAnnouncement("announcement file name");
        return $this->okResponse();
    }
}

class RestOfApps
{
    use SmartApiCommands;
    
    public function sayClock($appData)
    {
        $this->cmdSayClock("22:00");

        return $this->okResponse();

    }

    public function interactiveApp($appData)
    {
        if($appData["data"]=="1")
            return $this->okResponse();

        if($appData["data"]=="2")
            return $this->errorResponse();
            
    }
}

这里有您可以在 smartApp 类中使用的所有命令

cmdPlayAnnouncement($file);
cmdPlayback($file);
cmdExit($exit);
cmdGetData($file,$timeout,$digitsCount);
cmdSayDigit($number);
cmdSayNumber($number);
cmdSayClock($clock);
cmdSayDate($date,$calender);
cmdSayDuration($duration);
cmdSetExten($exten);
cmdSetLimitOnCall($seconds);
cmdMusicOnHold();
  1. 处理从 simotel 智能api 收到的请求
$config = Simotel::getDefaultConfig();
$config["smartApi"]["appClasses"] = [
  'playWelcomeMessage' => PlayWelcomeMessage::class,
  '*' => RestOfApps::class,
];

// place this codes where you want grab income requests
// from simotel smartApi calls     
$simotel = new Simotel($config);
$appData = $_POST["app_data"];
$jsonResponse = $simotel->smartApiCall($appData)->toJson();
$arrayResponse = $simotel->smartApiCall($appData)->toArray();

echo $jsonResponse;
/*
 if app_name='playAnnounceApp' 
	 response = {'ok':1,'commands':'PlayAnnouncement('announcement file name')'}

 if app_name='sayClock' 
	 response = {'ok':1,'commands':'SayClock("14:00")'}

 if app_name='interactiveApp' 
	 if data=1 
		 response = {'ok':1}
	 if data=2 
		 response = {'ok':0}
*/