- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/rest.php
- Класс: BitrixImOpenLinesRest
- Вызов: Rest::dialogFormSend
static function dialogFormSend($params, $n, CRestServer $server)
{
$params = array_change_key_case($params, CASE_UPPER);
if (!Loader::includeModule('im'))
{
throw new RestException('Messenger is not installed.', 'IM_NOT_INSTALLED', CRestServer::STATUS_WRONG_REQUEST);
}
if (!Loader::includeModule('crm'))
{
throw new RestException('CRM module is not installed.', 'CRM_NOT_INSTALLED', CRestServer::STATUS_WRONG_REQUEST);
}
if (!isset($params['SESSION_ID']))
{
throw new RestException('You need to specify session id', 'SESSION_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
if (
!isset($params['CRM_FORM']['ID'], $params['CRM_FORM']['CODE'], $params['CRM_FORM']['SEC'], $params['CRM_FORM']['NAME'])
)
{
throw new RestException('You need to specify CRM-form details', 'FORM_INFO_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
$sessionData = SessionTable::getByIdPerformance($params['SESSION_ID'])->fetch();
if (!$sessionData)
{
throw new RestException('Error getting session info', 'NO_SESSION_ERROR', CRestServer::STATUS_WRONG_REQUEST);
}
$session = new Session();
$session->load([
'USER_CODE' => $sessionData['USER_CODE'],
'SKIP_CREATE' => 'Y'
]);
if (!ImChat::isUserInChat($session->getData('CHAT_ID')))
{
throw new RestException('You do not have access to the specified dialog', 'ACCESS_ERROR', CRestServer::STATUS_WRONG_REQUEST);
}
$formLink = WebFormScript::getPublicUrl([
'ID' => $params['CRM_FORM']['ID'],
'CODE' => $params['CRM_FORM']['CODE'],
'SECURITY_CODE' => $params['CRM_FORM']['SEC']
]);
$formLinkWithParams = $formLink;
// for other connectors we send public link, need to attach properties and crm bindings to the link
if ($session->getData('SOURCE') !== Connector::TYPE_LIVECHAT)
{
$operatorChat = $session->getChat();
$crmBindings = $operatorChat->getFieldData(Chat::FIELD_CRM);
$signedData = new WebFormEmbedSign();
$signedData->setProperty('eventNamePostfix', FormHandler::EVENT_POSTFIX);
$userCode = FormHandler::encodeConnectorName($session->getData('USER_CODE'));
$signedData->setProperty('openlinesCode', $userCode);
foreach ($crmBindings as $bindingType => $bindingId)
{
if ($bindingId > 0)
{
$signedData->addEntity(CCrmOwnerType::ResolveId($bindingType), $bindingId);
}
}
$uri = new Uri($formLink);
$signedData->appendUriParameter($uri);
$urlManager = UrlManager::getInstance();
$host = $urlManager->getHostUrl();
$formLinkWithParams = $host . CBXShortUri::GetShortUri($uri->getLocator());
}
return BitrixImOpenlinesIm::addMessage([
'TO_CHAT_ID' => $session->getData('CHAT_ID'),
'MESSAGE' => FormHandler::buildSentFormMessageForClient($formLinkWithParams),
'AUTHOR_ID' => CurrentUser::get()->getId(),
'FROM_USER_ID' => CurrentUser::get()->getId(),
'IMPORTANT_CONNECTOR' => 'Y',
'PARAMS' => [
'COMPONENT_ID' => FormHandler::FORM_COMPONENT_NAME,
'CRM_FORM_ID' => $params['CRM_FORM']['ID'],
'CRM_FORM_SEC' => $params['CRM_FORM']['SEC'],
'CRM_FORM_FILLED' => 'N',
]
]);
}