simotel/simotel-laravel-connect

4.2.0 2023-11-09 06:51 UTC

This package is auto-updated.

Last update: 2024-09-26 06:52:11 UTC


README

PHP 包

使用 simotel-php-connect 连接到 simotel: simotel/simotel-php-connect

通过 Laravel 保持与 Simotel 的连接。Simotel 是一款功能强大的呼叫中心软件。访问以下文档了解更多信息: simotelwiki.simotel.com

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

安装

使用 composer 安装并自动加载此包

composer require simotel/simotel-laravel-connect

发布配置

使用 artisan 命令在 Laravel 配置文件夹中发布 simotel 连接配置文件

php artisan vendor:publish --provider="NasimTelecom\Simotel\Laravel\SimotelLaravelServiceProvider"
// config/laravel-simotel.php

[
    'smartApi' => [
        'apps' => [
            '*' => "\YourApp\SmartApiAppClass",
        ],
    ],
    'ivrApi' => [
        'apps' => [
            '*' => "\YourApp\IvrApiAppClass",
        ],
    ],
    'trunkApi' => [
        'apps' => [
            '*' => "\YourApp\TrunkApiApp",
        ],
    ],
    'extensionApi' => [
        'apps' => [
            '*' => "\YourApp\ExtensionApiAppClass",
        ],
    ],
    'simotelApi' => [
        'server_address' => 'http://yourSimotelServer/api/v4',
        'api_auth' => 'basic',  // simotel api authentication: basic,token,both
        'api_user' => 'apiUser',
        'api_pass' => 'apiPass',
        'api_key' => 'apiToken',
    ],
];

如何使用

Simotel API

Simotel API 帮助您连接到 Simotel 服务器并管理 Simotel 用户、队列、交换机、公告、获取报告、发送传真等 更多信息

连接到 Simotel API

use Simotel\Laravel\Facade\Simotel;

// 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

您可以使用我们的预定义 SimotelEvents 在 EventServiceProvider 中与监听器关联。

以下是您可以使用 Simotel 事件类的列表

现在,您必须在路由器中派发 Simotel 事件

// routes/api.php

Route::get("/eventApi",function(){
    Simotel::eventApi()->dispatch(request()->all());
})

Simotel 智能API

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

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

namespace \App\SimotelSmartApps;

use Simotel\SmartApi\Commands;

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

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

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

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

不要忘记在您的类中使用 use Simotel\SmartApi\Commands trait。

2. 自定义 simotel 配置

// config/laravel-simotel.php

 'smartApi' => [
        'apps' => [
            'playAnnounce' => \App\SimotelSmartApps\PlayWelcomeAnnounce::class,
            '*' => \App\SimotelSmartApps\RestOfApps::class,
        ],
    ],

3. 处理从 simotel 智能API 收到的请求

Route::get("smartApi",function(){
    Simotel::smartApi()->call(request()->all());
})
$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}
*/

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

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

Simotel 交换机 API

我们建议您首先研究 Simotel 交换机 API 文档

1. 创建 TrunkApp 类和方法

class SelectTrunk
{
    public function selectTrunk($appData)
    {
        if(/* some conditions */)
            return [
                "trunk" => "trunk1",
                "extension" => "extension1",
                "call_limit" => "300"
            ];
        
        //else
        return [
            "trunk" => "trunk2",
            "extension" => "extension2",
            "call_limit" => "400"
        ];
    }
}

2. 处理从 Simotel 交换机 API 收到的请求

$config = Simotel::getDefaultConfig();
$config["trunkApi"]["apps"] = [
  'selectTrunk' => SelectTrunk::class,
];

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

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

/*
    if some conditions then 
		 jsonResponse = {
            "ok": "1",             
            "trunk": "trunk1",
            "extension": "extension1",
            "call_limit": "300"
        }
	 else 
		jsonResponse = {
            "ok": "1",             
            "trunk": "trunk2",
            "extension": "extension2",
            "call_limit": "400"
        }
*/

Simotel 扩展 API

我们建议您首先研究 Simotel 扩展 API 文档

1. 创建 Extension API 类和方法

class SelectExtension
{
    public function selectExtension($appData)
    {
        if(/* some conditions */)
            return "ext1";
        
        //else
            return "ext2";
    }
}

2. 处理从 Simotel 扩展 API 收到的请求

$config = Simotel::getDefaultConfig();
$config["extensionApi"]["apps"] = [
  'selectExtension' => SelectExtension::class,
];

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

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

/*
    if some conditions then 
		 jsonResponse = {"ok": "1", "extension": "ext1"}
	 else 
		 jsonResponse = {"ok": "1", "extension": "ext2"}
*/

Simotel IVR API

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

1. 创建 Ivr API 类和方法

class SelectIvrCase
{
    public function selectCase($appData)
    {
        if(/* some conditions */)
            return "1";
        
        //else
            return "2";
    }
}

2. 处理从 Simotel IVR API 收到的请求

$config = Simotel::getDefaultConfig();
$config["ivrApi"]["apps"] = [
  'selectCase' => SelectIvrCase::class,
];

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

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

/*
    if some conditions then 
		 jsonResponse = {"ok": "1", "case": "1"}
	 else 
		 jsonResponse = {"ok": "1", "case": "2"}
*/

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

贡献

请参阅 CONTRIBUTINGCONDUCT 了解详细信息。

安全

如果您发现任何与安全相关的问题,请通过电子邮件 hosseinyaghmaee@gmail.com 反馈,而不是使用问题跟踪器。

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件