- Модуль: voximplant
- Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_rest.php
- Класс: CVoxImplantRestService
- Вызов: CVoxImplantRestService::registerExternalCall
static function registerExternalCall($params, $n, $server)
{
if ($server->getAuthType() !== OauthAuth::AUTH_TYPE && $server->getAuthType() !== APAuthAuth::AUTH_TYPE)
{
throw new BitrixRestAuthTypeException();
}
$params['USER_PHONE_INNER'] ??= null;
$params['USER_ID'] ??= null;
$params['PHONE_NUMBER'] ??= null;
$params['CALL_START_DATE'] ??= null;
$params['CRM_CREATE'] ??= null;
$params['CRM_SOURCE'] ??= null;
$params['CRM_ENTITY_TYPE'] ??= null;
$params['CRM_ENTITY_ID'] ??= null;
$params['SHOW'] ??= null;
$params['CALL_LIST_ID'] ??= null;
$params['LINE_NUMBER'] ??= null;
$params['TYPE'] ??= null;
/*
$permissions = SecurityPermissions::createWithCurrentUser();
if(!$permissions->canPerform(SecurityPermissions::ENTITY_CALL_DETAIL, SecurityPermissions::ACTION_MODIFY, SecurityPermissions::PERMISSION_ANY))
{
throw new BitrixRestAccessException();
}
*/
$clientId = $server->getClientId();
$row = BitrixRestAppTable::getByClientId($clientId);
$appId = $row['ID'];
$userId = (int)$params['USER_ID'];
if ($userId == 0)
{
$userId = RestHelper::getUserByPhone($params['USER_PHONE_INNER']);
}
if (!$userId)
{
throw new BitrixRestRestException('USER_ID or USER_PHONE_INNER should be set');
}
if (!in_array($params['TYPE'], CVoxImplantMain::getCallTypes()))
{
throw new BitrixRestRestException('Unknown TYPE');
}
if (isset($params['CALL_START_DATE']) && $params['CALL_START_DATE'] !== '')
{
$parsedDate = CRestUtil::unConvertDateTime($params['CALL_START_DATE']);
if ($parsedDate === false)
{
throw new BitrixRestRestException('CALL_START_DATE should be in the ISO-8601 format');
}
$startDate = new BitrixMainTypeDateTime($parsedDate);
}
else
{
$startDate = new BitrixMainTypeDateTime();
}
$result = RestHelper::registerExternalCall([
'USER_ID' => $userId,
'PHONE_NUMBER' => $params['PHONE_NUMBER'] ?? null,
'LINE_NUMBER' => $params['LINE_NUMBER'] ?? null,
'EXTERNAL_CALL_ID' => $params['EXTERNAL_CALL_ID'],
'TYPE' => $params['TYPE'] ?? null,
'CALL_START_DATE' => $startDate,
'CRM' => $params['CRM'] ?? null,
'CRM_CREATE' => $params['CRM_CREATE'] ?? null,
'CRM_SOURCE' => $params['CRM_SOURCE'] ?? null,
'CRM_ENTITY_TYPE' => $params['CRM_ENTITY_TYPE'] ?? null,
'CRM_ENTITY_ID' => $params['CRM_ENTITY_ID'] ?? null,
'REST_APP_ID' => $appId,
'ADD_TO_CHAT' => $params['ADD_TO_CHAT'] ?? null,
'SHOW' => isset($params['SHOW']) ? (bool)$params['SHOW'] : true
]);
if (!$result->isSuccess())
{
throw new BitrixRestRestException(implode('; ', $result->getErrorMessages()));
}
$code = $row['CODE'] ? : 'webHook' . $server->getPasswordId();
if ($code)
{
AddEventToStatFile(
'voximplant',
'callRegister',
uniqid($code, true),
$code,
'type' . $params['TYPE']
);
}
return $result->getData();
}