public function sendInvite($users)
{
$lineConfig = $this->call->getConfig();
$isTransfer = $this->call->getParentCallId() != '';
$call = $isTransfer ? Call::load($this->call->getParentCallId()) : $this->call;
$externalNumber = '';
if ($lineConfig['PORTAL_MODE'] === CVoxImplantConfig::MODE_SIP)
{
if($call->getExternalLineId())
{
$externalLine = ExternalLineTable::getRowById($call->getExternalLineId());
$externalNumber = $externalLine ? $externalLine['NUMBER'] : '';
}
$phoneTitle = $externalNumber ?: $lineConfig['PHONE_TITLE'];
}
else
{
$phoneTitle = $call->getPortalNumber();
}
if($call->isInternalCall() && Loader::includeModule('im'))
{
$portalCallData = CIMContactList::GetUserData([
'ID' => [$call->getUserId(), $call->getPortalUserId()],
'DEPARTMENT' => 'N',
'HR_PHOTO' => 'Y'
]);
}
else
{
$portalCallData = [];
}
$config = [
"callId" => $this->call->getCallId(), // callId of the transfer call in case of transfer
"callerId" => $call->getCallerId(),
"lineNumber" => $call->getPortalNumber(),
"companyPhoneNumber" => $phoneTitle,
"phoneNumber" => $phoneTitle,
"chatId" => 0,
"chat" => [],
"portalCall" => $call->isInternalCall(),
"portalCallUserId" => $call->isInternalCall() ? (int)$call->getUserId() : 0,
"portalCallData" => $call->isInternalCall() ? $portalCallData : [],
"config" => CVoxImplantConfig::getConfigForPopup($call->getCallId()),
"CRM" => ($call->isCrmEnabled() && !$call->isInternalCall()
? CVoxImplantCrmHelper::GetDataForPopup($call->getCallId(), $call->getCallerId(), $call->getUserId())
: false
),
"showCrmCard" => ($call->isCrmEnabled() && !$call->isInternalCall()),
"crmEntityType" => $call->getPrimaryEntityType(),
"crmEntityId" => $call->getPrimaryEntityId(),
"isCallback" => ($call->getIncoming() == CVoxImplantMain::CALL_CALLBACK),
"isTransfer" => $isTransfer
];
if ($call->isInternalCall())
{
$callerName = $portalCallData['users'][$call->getUserId()]['name'];
}
else
{
$callerName = $call->getCallerId();
if (isset($config['CRM']['CONTACT']['NAME']) && $config['CRM']['CONTACT']['NAME'] <> '')
{
$callerName = $config['CRM']['CONTACT']['NAME'];
}
if (isset($config['CRM']['COMPANY']) && $config['CRM']['COMPANY'] <> '')
{
$callerName .= ' ('.$config['CRM']['COMPANY'].')';
}
else if (isset($config['CRM']['CONTACT']['POST']) && $config['CRM']['CONTACT']['POST'] <> '')
{
$callerName .= ' ('.$config['CRM']['CONTACT']['POST'].')';
}
}
$pushTag = "VI_CALL_{$call->getCallId()}";
$push = [
'sub_tag' => $pushTag,
'message' => Loc::getMessage('INCOMING_CALL', ['#NAME#' => $callerName])
. ($call->isInternalCall() ? '' : ' ' . Loc::getMessage('CALL_FOR_NUMBER', ['#NUMBER#' => $phoneTitle]))
,
'send_immediately' => 'Y',
'sound' => 'call.aif',
'advanced_params' => [
'id' => $pushTag,
'notificationsToCancel' => [$pushTag],
'androidHighPriority' => true,
'isVoip' => true,
'callkit' => true,
]
];
$pushParams = [
'type' => 'telephony',
'callId' => $config['callId'],
'callerId' => $config['callerId'],
'callerName' => $callerName,
'companyPhoneNumber' => $config['companyPhoneNumber'],
'config' => $config['config'],
'isCallback' => $config['isCallback'],
'isTransfer' => $config['isTransfer'],
'portalCall' => $config['portalCall'],
'ts' => time(),
];
if($call->isInternalCall() && is_array($portalCallData['users']))
{
$pushParams['portalCallUserId'] = $config['portalCallUserId'];
$pushParams['portalCallData'] = [
'users' => []
];
foreach ($portalCallData['users'] as $userId => $userFields)
{
if(!in_array($userId, $users))
{
$pushParams['portalCallData']['users'][$userId] = [
'name' => $userFields['name'],
'avatar' => $userFields['avatar'],
];
}
}
}
else
{
$pushParams['CRM'] = [
'FOUND' => $config['CRM']['FOUND'],
'CONTACT' => $config['CRM']['CONTACT'] ?? null,
'COMPANY' => $config['CRM']['COMPANY'] ?? null,
];
}
$push['params'] = [
'ACTION' => $pushTag,
'PARAMS' => $pushParams
];
$this->send($users, static::COMMAND_INVITE, $config, $push, 30);
}