- Модуль: voximplant
- Путь к файлу: ~/bitrix/modules/voximplant/lib/rest/helper.php
- Класс: BitrixVoximplantRestHelper
- Вызов: Helper::startCall
static function startCall($number, $userId, $lineId = '', array $parameters = array())
{
$entityType = $parameters['ENTITY_TYPE'] ?? '';
$entityId = $parameters['ENTITY_ID'];
if (mb_strpos($entityType, 'CRM_') === 0)
{
$entityType = mb_substr($entityType, 4);
}
else if (isset($parameters['ENTITY_TYPE_NAME']) && isset($parameters['ENTITY_ID']))
{
$entityType = $parameters['ENTITY_TYPE_NAME'];
$entityId = $parameters['ENTITY_ID'];
}
else
{
$entityType = '';
$entityId = null;
}
if ($lineId)
{
$line = CVoxImplantConfig::GetLine($lineId);
}
else
{
$line = self::getExternalCallHandler($userId);
}
if (!$line)
{
$result = new Result();
return $result->addError(new Error("Outgoing line is not found", "LINE_NOT_FOUND"));
}
$lineNumber = mb_substr($line['LINE_NUMBER'], 0, 8) === 'REST_APP' ? '' : $line['LINE_NUMBER'];
[$extensionSeparator, $extension] = Parser::getInstance()->stripExtension($number);
$eventFields = [
'PHONE_NUMBER' => $number,
'PHONE_NUMBER_INTERNATIONAL' => Parser::getInstance()->parse($number)->format(Format::E164),
'EXTENSION' => $extension,
'USER_ID' => $userId,
'CALL_LIST_ID' => (int)($parameters['CALL_LIST_ID'] ?? null),
'APP_ID' => $line['REST_APP_ID'],
'LINE_NUMBER' => $lineNumber,
'IS_MOBILE' => $parameters['IS_MOBILE'] === true,
];
$registerResult = static::registerExternalCall([
'USER_ID' => $userId,
'PHONE_NUMBER' => $number,
'LINE_NUMBER' => $lineNumber,
'TYPE' => CVoxImplantMain::CALL_OUTGOING,
'CRM_CREATE' => ($line['CRM_AUTO_CREATE'] ?? 'Y') === 'Y',
'CRM_ENTITY_TYPE' => $entityType,
'CRM_ENTITY_ID' => $entityId,
'CRM_ACTIVITY_ID' => (int)($parameters['SRC_ACTIVITY_ID'] ?? null),
'CRM_BINDINGS' => is_array(($parameters['BINDINGS'] ?? null)) ? $parameters['BINDINGS'] : null,
'REST_APP_ID' => $line['REST_APP_ID'],
'CALL_LIST_ID' => (int)($parameters['CALL_LIST_ID'] ?? null),
]);
if($registerResult->isSuccess())
{
$callData = $registerResult->getData();
$eventFields['CALL_ID'] = $callData['CALL_ID'];
$eventFields['CRM_ENTITY_TYPE'] = $callData['CRM_ENTITY_TYPE'];
$eventFields['CRM_ENTITY_ID'] = $callData['CRM_ENTITY_ID'];
$eventFields['CRM_CREATED_LEAD'] = $callData['CRM_CREATED_LEAD'];
$eventFields['CRM_CREATED_ENTITIES'] = $callData['CRM_CREATED_ENTITIES'];
$event = new Event(
'voximplant',
'onExternalCallStart',
$eventFields
);
$event->send();
}
return $registerResult;
}