3namespace Bitrix\MessageService\Providers\Edna\WhatsApp;
6use Bitrix\ImConnector\Library;
7use Bitrix\ImOpenLines\Im;
8use Bitrix\ImOpenLines\Session;
10use Bitrix\Main\Loader;
11use Bitrix\Main\Result;
12use Bitrix\MessageService\Providers;
13use Bitrix\MessageService\Providers\Constants\InternalOption;
18 'image/jpeg' => 5 * 1024 * 1024,
19 'image/png' => 5 * 1024 * 1024,
20 'audio/aac' => 16 * 1024 * 1024,
21 'audio/mp4' => 16 * 1024 * 1024,
22 'audio/amr' => 16 * 1024 * 1024,
23 'audio/mpeg' => 16 * 1024 * 1024,
24 'audio/ogg' => 16 * 1024 * 1024,
25 'video/mp4' => 16 * 1024 * 1024,
26 'video/3gpp' => 16 * 1024 * 1024,
64 return $this->emoji->convertEmoji(
$text, InternalOption::EMOJI_ENCODE);
69 $cascadeResult =
new Result();
72 $cascadeResult = $this->utils->getCascadeIdFromSubject(
74 static function(
array $externalSubjectData,
int $internalSubject)
76 return $externalSubjectData[
'id'] === $internalSubject;
82 $cascadeResult = $this->utils->getCascadeIdFromSubject(
84 static function(
array $externalSubjectData,
string $internalSubject)
86 return $externalSubjectData[
'subject'] === $internalSubject;
92 return $cascadeResult->addError(
new Error(
'Invalid subject id'));
95 if (!$cascadeResult->isSuccess())
97 return $cascadeResult;
103 'requestId' => uniqid(
'',
true),
104 'cascadeId' => $cascadeResult->getData()[
'cascadeId'],
105 'subscriberFilter' => [
150 'whatsappContent' => $whatsAppContent
165 foreach ([
'header',
'footer',
'keyboard'] as $templateField)
168 isset(
$messageFields[
'MESSAGE_HEADERS'][
'template'][$templateField])
176 return $this->emoji->convertEmojiInTemplate(
$params, InternalOption::EMOJI_DECODE);
188 if (Loader::includeModule(
'disk') && preg_match(
'/^http.+~.+$/', trim($messageBody)))
193 $parsedUrl = parse_url($fileUri[
'URI']);
195 parse_str($parsedUrl[
'query'], $queryParams);
196 if (isset($queryParams[
'FILE_ID']))
198 $diskFile = \Bitrix\Disk\File::getById((
int)$queryParams[
'FILE_ID']);
202 $messageBody = $fileUri[
'URI'];
213 case Constants::CONTENT_TYPE_IMAGE:
214 case Constants::CONTENT_TYPE_AUDIO:
215 case Constants::CONTENT_TYPE_VIDEO:
216 case Constants::CONTENT_TYPE_DOCUMENT:
218 'url' => $messageBody
221 case Constants::CONTENT_TYPE_TEXT:
229 private function determineContentType(File $diskFile): string
232 $file = $diskFile->getFile();
234 if (is_array($file) && isset($file[
'CONTENT_TYPE']))
236 if (isset(self::AVAILABLE_CONTENT_TYPES[$file[
'CONTENT_TYPE']]))
238 $maxSize = self::AVAILABLE_CONTENT_TYPES[$file[
'CONTENT_TYPE']];
239 if ($diskFile->getSize() <= $maxSize)
241 $contentType = Constants::CONTENT_TYPE_MAP[$diskFile->getTypeFile()] ?? Constants::CONTENT_TYPE_DOCUMENT;
243 elseif ($diskFile->getSize() <= self::DOCUMENT_MAX_FILE_SIZE)
248 elseif ($diskFile->getSize() <= self::DOCUMENT_MAX_FILE_SIZE)
259 if (!Loader::includeModule(
'imopenlines') || !Loader::includeModule(
'imconnector'))
261 return (
new Result())->addError(
new Error(
'Missing modules imopenlines and imconnector'));
264 $externalChatId = str_replace(
'+',
'',
$messageFields[
'MESSAGE_TO']);
268 return (
new Result())->addError(
new Error(
'Missing User Id'));
272 $lineId = $this->connectorLine->getLineId((
int)$from);
275 return (
new Result())->addError(
new Error(
'Missing Line Id. Please reconfigure the open line'));
282 return (
new Result())->addError(
new Error(
'Missing Chat Id'));
286 'TO_CHAT_ID' => $chatId,
287 'MESSAGE' => $this->utils->prepareTemplateMessageText(
$messageFields),
289 'SKIP_COMMAND' =>
'Y',
290 'NO_SESSION_OL' =>
'Y',
292 'CLASS' =>
'bx-messenger-content-item-ol-output'
299 $resultData[
'chatId'] = $chatId;
304 $result->addError(
new Error(
'Error sending a message to the chat'));
311 $userXmlId = Library::ID_EDNA_WHATSAPP_CONNECTOR .
'|' . $externalChatId;
314 'filter' => [
'=XML_ID' => $userXmlId],
322 return Library::ID_EDNA_WHATSAPP_CONNECTOR.
'|'. $lineId.
'|'. $externalChatId.
'@'. $from.
'|' .
$userId;
328 $sessionLoadResult = $session->getLast([
'USER_CODE' => $userSessionCode]);
329 if (!$sessionLoadResult->isSuccess())
333 $sessionData = $session->getData();
334 $chatId = $sessionData[
'CHAT_ID'];
335 $closed = $sessionData[
'CLOSED'] ===
'Y';
347 $this->optionManager->getOption(InternalOption::API_KEY),
349 $this->optionManager->getSocketTimeout(),
350 $this->optionManager->getStreamTimeout()
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getRow(array $parameters)
getSendMessageParams(array $messageFields)
const AVAILABLE_CONTENT_TYPES
const DOCUMENT_MAX_FILE_SIZE
Providers OptionManager $optionManager
getSessionUserCode(string $lineId, string $externalChatId, string $from, string $userId)
__construct(Providers\OptionManager $optionManager, Providers\SupportChecker $supportChecker, Providers\Edna\EdnaRu $utils, EmojiConverter $emoji)
sendHSMtoChat(array $messageFields)
getOpenedSessionChatId(string $userSessionCode)
prepareMessageBodyForSave(string $text)
ConnectorLine $connectorLine
isTemplateMessage(array $messageFields)
getSendMessageMethod(array $messageFields)
initializeDefaultExternalSender()
getImconnectorUserId(string $externalChatId)
Providers Edna EdnaRu $utils
getMessageContent(array $messageFields)
Providers SupportChecker $supportChecker
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']