2017-06-22 00:55:08 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
|
|
|
* Telephony
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace RetailCrm\Methods\V3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
|
|
|
* Telephony class
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
trait Telephony
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get telephony settings
|
|
|
|
*
|
|
|
|
* @param string $code
|
|
|
|
*
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function telephonySettingsGet($code)
|
|
|
|
{
|
|
|
|
if (empty($code)) {
|
|
|
|
throw new \InvalidArgumentException('Parameter `code` must be set');
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
"/telephony/setting/$code",
|
|
|
|
"GET"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call event
|
|
|
|
*
|
2020-09-09 12:51:31 +03:00
|
|
|
* @param string $phone phone number
|
|
|
|
* @param string $type call type
|
2017-06-22 00:55:08 +03:00
|
|
|
* @param array $codes
|
2020-09-09 12:51:31 +03:00
|
|
|
* @param array $userIds
|
|
|
|
* @param string $callExternalId
|
2017-06-22 00:55:08 +03:00
|
|
|
* @param string $hangupStatus
|
|
|
|
* @param string $externalPhone
|
|
|
|
* @param array $webAnalyticsData
|
2020-09-09 12:51:31 +03:00
|
|
|
* @param string $site (default: null)
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
* @internal param string $code additional phone code
|
|
|
|
* @internal param string $status call status
|
|
|
|
*/
|
|
|
|
public function telephonyCallEvent(
|
|
|
|
$phone,
|
|
|
|
$type,
|
|
|
|
$codes,
|
2020-09-09 12:51:31 +03:00
|
|
|
$userIds = [],
|
2019-05-30 09:29:51 +03:00
|
|
|
$hangupStatus = null,
|
2017-06-22 00:55:08 +03:00
|
|
|
$externalPhone = null,
|
2020-09-09 12:51:31 +03:00
|
|
|
$callExternalId = null,
|
2019-12-09 09:15:57 +03:00
|
|
|
$webAnalyticsData = [],
|
|
|
|
$site = null
|
2017-06-22 00:55:08 +03:00
|
|
|
) {
|
|
|
|
if (!isset($phone)) {
|
|
|
|
throw new \InvalidArgumentException('Phone number must be set');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($type)) {
|
|
|
|
throw new \InvalidArgumentException('Type must be set (in|out|hangup)');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($codes)) {
|
|
|
|
throw new \InvalidArgumentException('Codes array must be set');
|
|
|
|
}
|
|
|
|
|
|
|
|
$parameters['phone'] = $phone;
|
|
|
|
$parameters['type'] = $type;
|
|
|
|
$parameters['codes'] = $codes;
|
2020-09-09 12:51:31 +03:00
|
|
|
|
|
|
|
if (!empty($userIds)) {
|
|
|
|
$parameters['userIds'] = $userIds;
|
|
|
|
}
|
|
|
|
|
2017-06-22 00:55:08 +03:00
|
|
|
$parameters['hangupStatus'] = $hangupStatus;
|
2020-09-09 12:51:31 +03:00
|
|
|
$parameters['callExternalId'] = $callExternalId;
|
|
|
|
$parameters['externalPhone'] = $externalPhone;
|
2017-06-22 00:55:08 +03:00
|
|
|
$parameters['webAnalyticsData'] = $webAnalyticsData;
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/telephony/call/event',
|
|
|
|
"POST",
|
2019-12-09 09:15:57 +03:00
|
|
|
['event' => json_encode($this->fillSite($site, $parameters))]
|
2017-06-22 00:55:08 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload calls
|
|
|
|
*
|
2019-12-09 09:15:57 +03:00
|
|
|
* @param array $calls calls data
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
2019-12-09 09:15:57 +03:00
|
|
|
* @param bool $autoFillSite fill site code from API client in provided calls
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
2019-12-09 09:15:57 +03:00
|
|
|
public function telephonyCallsUpload(array $calls, $autoFillSite = false)
|
2017-06-22 00:55:08 +03:00
|
|
|
{
|
|
|
|
if (!count($calls)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `calls` must contains array of the calls'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-09 09:15:57 +03:00
|
|
|
if ($autoFillSite) {
|
|
|
|
foreach ($calls as $key => $call) {
|
|
|
|
$calls[$key] = $this->fillSite(null, $call);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/telephony/calls/upload',
|
|
|
|
"POST",
|
|
|
|
['calls' => json_encode($calls)]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get call manager
|
|
|
|
*
|
|
|
|
* @param string $phone phone number
|
|
|
|
* @param bool $details detailed information
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function telephonyCallManager($phone, $details)
|
|
|
|
{
|
|
|
|
if (!isset($phone)) {
|
|
|
|
throw new \InvalidArgumentException('Phone number must be set');
|
|
|
|
}
|
|
|
|
|
|
|
|
$parameters['phone'] = $phone;
|
|
|
|
$parameters['details'] = isset($details) ? $details : 0;
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/telephony/manager',
|
|
|
|
"GET",
|
|
|
|
$parameters
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|