Skip to content

Commit

Permalink
Add pbx info method
Browse files Browse the repository at this point in the history
  • Loading branch information
zadarma-github committed May 31, 2021
1 parent e2076df commit 23badf5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// pbx methods
$result = $api->getPbxInternal();
$result = $api->getPbxStatus($pbx);
$result = $api->getPbxInfo($pbx);
$result = $api->getPbxRecord($callId, null);
$result = $api->getPbxRedirection($pbx);

Expand Down
26 changes: 24 additions & 2 deletions lib/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Zadarma_API\Response\DirectNumber;
use Zadarma_API\Response\IncomingCallsStatistics;
use Zadarma_API\Response\NumberLookup;
use Zadarma_API\Response\PbxInfo;
use Zadarma_API\Response\PbxInternal;
use Zadarma_API\Response\PbxRecording;
use Zadarma_API\Response\PbxRecordRequest;
Expand Down Expand Up @@ -210,6 +211,18 @@ public function getPbxStatus($pbxId)
return new PbxStatus($data);
}

/**
* Return information about the PBX extension number.
* @param $pbxId
* @return PbxInfo
* @throws ApiException
*/
public function getPbxInfo($pbxId)
{
$data = $this->request('pbx/internal/' . self::filterNumber($pbxId) . '/info');
return new PbxInfo($data);
}

/**
* Return call recording file request.
* @param string|null $callId Unique call ID, it is specified in the name of the file with the call
Expand Down Expand Up @@ -418,11 +431,14 @@ public function setSipRedirectionNumber($sipId, $number)
* send the recordings to the email address only, "off_email" - disable the option to send the recordings to the
* email address only, "on_store" - enable the option to save the recordings to the cloud, "off_store" - disable the
* option to save the recordings to the cloud.
* @param string|null $email
* @param string|null $email (optional) change the email address, where the call recordings will be sent.
* You can specify up to 3 email addresses, separated by comma.
* @param string|null $speechRecognition (optional) change the speech recognition settings: "all" - recognize all,
* "optional" - recognize selectively in statistics, "off" - disable.
* @return PbxRecording
* @throws ApiException
*/
public function setPbxRecording($sipId, $status, $email = null)
public function setPbxRecording($sipId, $status, $email = null, $speechRecognition = null)
{
if (!in_array($status, ['on', 'off', 'on_email', 'off_email', 'on_store', 'off_store'])) {
throw new \BadFunctionCallException('Wrong status parameter');
Expand All @@ -434,6 +450,12 @@ public function setPbxRecording($sipId, $status, $email = null)
if ($email) {
$params['email'] = $email;
}
if ($speechRecognition && !in_array($status, ['off', 'off_store'])) {
if (!in_array($speechRecognition, ['all', 'optional', 'off'])) {
throw new \BadFunctionCallException('Wrong speechRecognition parameter');
}
$params['speech_recognition'] = $speechRecognition;
}
$data = $this->request('pbx/internal/recording', $params, 'put');
return new PbxRecording($data);
}
Expand Down
35 changes: 35 additions & 0 deletions lib/Response/PbxInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Zadarma_API\Response;

class PbxInfo extends Response
{
/** @var integer PBX ID */
public $pbx_id;

/** @var integer PBX extension number */
public $number;

/** @var string display name */
public $name;

/** @var string CallerID */
public $caller_id;

/** @var string change the CallerID from the app (true|false) */
public $caller_id_app_change;

/** @var string CallerID by direction (true|false) */
public $caller_id_by_direction;

/** @var string number of lines */
public $lines;

/** @var string ip access restriction (false if omitted) */
public $ip_restriction;

/** @var string record conversations to the cloud (Without recognition|For manual recognition|For automatic speech recognition|false) */
public $record_store;

/** @var string email for sending conversation recordings (false if not enabled) */
public $record_email;
}
1 change: 1 addition & 0 deletions lib/Response/PbxRecording.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class PbxRecording extends Response
public $internal_number;
public $recording;
public $email;
public $speech_recognition;
}

0 comments on commit 23badf5

Please sign in to comment.