PHP code example of simotel / simotel-laravel-connect
1. Go to this page and download the library: Download simotel/simotel-laravel-connect library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
simotel / simotel-laravel-connect example snippets
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();
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}
}
}