nasimtelecom/simotel-php-connect

使用 PHP 保持与 Simotel 连接

此包的官方仓库似乎已不存在,因此该包已被冻结。

4.0.0 2022-09-25 13:15 UTC

This package is not auto-updated.

Last update: 2023-06-15 18:45:39 UTC


README

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 API

require("vendor/autoload.php");

$config = Simotel::getDefaultConfig();
$config["simotelApi"]= [
        'api_auth' => 'both', // simotel api authentication: basic,token,both 
        'api_user' => 'apiUser',
        'api_pass' => 'apiPass',
        'api_token' => 'apiToken',
        'server_address' => 'http://simotelServer/api/v4',
    ],

$simotel = new \NasimTelecom\Simotel\Simotel($config);

// The data will be sent to Simotel server as request body
$data = [
    "alike"=>false,
    "conditions"=>["name"=>"200"],
];

try{
    // Sending request to simotel server
    $res = $simotel->connect("pbx/users/search",$data);
}
catch(\Exception $e){
    die($e->getMessage());
}


// Determines whether the transaction was successful or not
// In other words if the response status code is 
// between 200~299 then isOk() will return true 
if(!$res->isOk())
    die("There is a problem");

// Or you can get response status code
$statusCode = $res->getStatusCode();

// Simotel will return a json response,
// to cast it to array use toArray() method
// it will be an array like this:
// [
//      "success" => true/false, 
//      "message" => "Simotel Error Message"
//      "data"    =>  [response data array]    
// ]
// success: determine wether transaction by simotel is ok or not
// message: this is simotel response message
// that tell us why transactoion did not completed
$res->toArray();

// Simotel Success is true or false
if(!$res->isSuccess())
    // Get Simotel message if isSuccess()==false
    die($res->getMessage());

// Get Simotel response data array
$users = $res->getData();

Simotel 事件 API

1. 为事件创建监听器

$simotel = new Simotel();
$simotel->eventApi()->addListener('Cdr', function ($simotelApiData) {
    // codes to store Cdr $simotelApiData or something else
});

2. 在您的 API 端点收到 Simotel 事件 API 请求后触发事件

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

您可以将 API 端点地址放在 Simotel API 设置

Simotel 智能API

我们建议您首先研究 Simotel SmartApi 文档

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

use NasimTelecom\Simotel\SmartApi\Commands;

class PlayWelcomeMessage
{
    use Commands;
    
    public function playAnnounceApp($appData)
    {
        $this->cmdPlayAnnouncement("announcement file name");
        return $this->okResponse();
        // return: {'ok':1,'commands':'PlayAnnouncement('announcement file name')'}
    }
}

class RestOfApps
{
    use SmartApiCommands;
    
    public function sayClock($appData)
    {
        $this->cmdSayClock("14:00");
        return $this->okResponse();
        // return: {'ok':1,'commands':'SayClock("14:00")'} 
    }

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

        if($appData["data"]=="2")
            return $this->errorResponse();
            // return: {'ok':0}
    }
}

不要忘记在您的类中 use NasimTelecom\Simotel\SmartApi\Commands 特性。

  1. 处理从 Simotel 智能API 收到的请求
$config = Simotel::getDefaultConfig();
$config["smartApi"]["apps"] = [
  '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->smartApi($appData)->toJson();

header('Content-Type: application/json; charset=utf-8');
echo $jsonResponse;

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

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

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

在您的 SmartApps 类中,您可以使用以下命令:

cmdPlayAnnouncement($announceFilename);
cmdPlayback($announceFilename);
cmdExit($exit);
cmdGetData($announceFilename, $timeout, $digitsCount);
cmdSayDigit($number);
cmdSayNumber($number);
cmdSayClock($clock);
cmdSayDate($date,$calender);
cmdSayDuration($duration);
cmdSetExten($exten, $clearUserData = true);
cmdSetLimitOnCall($seconds);
cmdClearUserData();
cmdMusicOnHold();