44 if (ModuleManager::isModuleInstalled(
'crm'))
46 $list[] =
'Bitrix\Sender\Integration\Crm\Preset\Segment';
61 if (Loader::includeModule(
'crm'))
63 $list[] = Crm\CompanyCard::getArray();
78 if (ModuleManager::isModuleInstalled(
'crm'))
80 Crm\EventHandler::onAfterPostingSendRecipient($eventData, $letter);
83 if (Bitrix24\Service::isCloud() && $eventData[
'SEND_RESULT'] && $letter->getMessage()->getCode() ===
Message\iBase::CODE_MAIL)
85 Bitrix24\Limitation\DailyLimit::increment();
98 if (ModuleManager::isModuleInstalled(
'crm'))
100 Crm\EventHandler::onAfterPostingSendRecipientMultiple($eventDataArray, $letter);
112 if (Bitrix24\Service::isCloud() && is_array($eventData))
114 Bitrix24\Limitation\Rating::regulate();
127 if (Loader::includeModule(
'sale') && !Bitrix24\Service::isCloud())
129 if (Templates\Category::class === $className)
131 return Sale\Preset\TriggerCampaign::getTemplateCategories();
147 Message\iBase::CODE_MAIL => []
151 if (Loader::includeModule(
'sale') && !Bitrix24\Service::isCloud())
153 foreach (
Sale\Preset\TriggerCampaign::getAll() as $item)
155 foreach ($item[
'CHAIN'] as $letter)
157 $list[Message\iBase::CODE_MAIL][] = array(
158 'ID' => $letter[
'TEMPLATE_ID'],
159 'TYPE' => $letter[
'TEMPLATE_TYPE'],
160 'CATEGORY' => mb_strtoupper($item[
'CODE']),
161 'MESSAGE_CODE' =>
Message\iBase::CODE_MAIL,
163 'IS_TRIGGER' =>
true,
167 'NAME' => $letter[
'SUBJECT'],
172 'VALUE' => $letter[
'SUBJECT'],
176 'VALUE' => $letter[
'MESSAGE'],
185 return isset($list[$messageType]) ? $list[$messageType] : [];
197 $data[
'CONNECTOR'][] =
'Bitrix\Sender\Integration\Sender\Connectors\Recipient';
198 $data[
'CONNECTOR'][] =
'Bitrix\Sender\Integration\Sender\Connectors\Contact';
199 $data[
'CONNECTOR'][] =
'Bitrix\Sender\Integration\Sender\Connectors\UnSubscribers';
202 if (Loader::includeModule(
'crm'))
204 $data[
'CONNECTOR'][] =
'Bitrix\Sender\Integration\Crm\Connectors\Lead';
205 $data[
'CONNECTOR'][] =
'Bitrix\Sender\Integration\Crm\Connectors\Client';
220 'Bitrix\Sender\Integration\Main\Triggers\UserAuth',
221 'Bitrix\Sender\Integration\Main\Triggers\UserDontAuth',
237 $list[] =
'Bitrix\Sender\Integration\Sender\Mail\MessageMail';
240 if (MessageService\Sms\Service::canUse())
242 $list[] =
'Bitrix\Sender\Integration\MessageService\Sms\MessageSms';
246 if (Im\Service::canUse())
248 $list[] =
'Bitrix\Sender\Integration\Im\MessageIm';
252 if (VoxImplant\Service::canUse())
254 $list[] =
'Bitrix\Sender\Integration\VoxImplant\MessageCall';
255 $list[] =
'Bitrix\Sender\Integration\VoxImplant\MessageAudioCall';
262 if (Seo\Ads\Service::canUse())
265 'Bitrix\Sender\Integration\Seo\Ads\MessageYa',
266 \
Bitrix\
Sender\Integration\Seo\Ads\MessageLookalikeYandex::class,
267 'Bitrix\Sender\Integration\Seo\Ads\MessageGa',
269 'Bitrix\Sender\Integration\Seo\Ads\MessageFb',
270 'Bitrix\Sender\Integration\Seo\Ads\MessageMarketingFb',
271 'Bitrix\Sender\Integration\Seo\Ads\MessageMarketingInstagram',
272 'Bitrix\Sender\Integration\Seo\Ads\MessageLookalikeFb',
274 foreach ($adsList as $adsClass)
276 if (!Bitrix24\Service::isAdVisibleInRegion($adsClass::CODE))
286 if (Crm\ReturnCustomer\Service::canUse())
288 $list[] =
'Bitrix\Sender\Integration\Crm\ReturnCustomer\MessageLead';
289 $list[] =
'Bitrix\Sender\Integration\Crm\ReturnCustomer\MessageDeal';
292 if (Bitrix24\Service::isMasterYandexVisibleInRegion())
294 $list[] = \Bitrix\Sender\Integration\Yandex\Master\MessageMasterYandex::class;
296 if(Bitrix24\Service::isTolokaVisibleInRegion())
298 $list[] =
'Bitrix\Sender\Integration\Yandex\Toloka\MessageToloka';
314 if (Loader::includeModule(
'sale') && !Bitrix24\Service::isCloud())
316 $list = array_merge($list,
Sale\Preset\TriggerCampaign::getAll());
325 $list[] =
'Bitrix\Sender\Integration\Sender\Mail\ConsentBuilderMail';
326 $list[] =
'Bitrix\Sender\Integration\Sender\Mail\TestConsentBuilderMail';
332 $list[] =
'Bitrix\Sender\Integration\Sender\Mail\ConsentResponseMail';
333 $list[] =
'Bitrix\Sender\Integration\Sender\Mail\TestConsentResponseMail';
346 $list[] =
'Bitrix\Sender\Integration\Sender\Mail\TransportMail';
349 if (MessageService\Sms\Service::canUse())
351 $list[] =
'Bitrix\Sender\Integration\MessageService\Sms\TransportSms';
355 if (Im\Service::canUse())
357 $list[] =
'Bitrix\Sender\Integration\Im\TransportIm';
361 if (VoxImplant\Service::canUse())
363 $list[] =
'Bitrix\Sender\Integration\VoxImplant\TransportCall';
364 $list[] =
'Bitrix\Sender\Integration\VoxImplant\TransportAudioCall';
371 if (Seo\Ads\Service::canUse())
373 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportYa';
374 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportGa';
375 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportVk';
376 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportFb';
377 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportMarketingFb';
378 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportMarketingInstagram';
379 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportLookalikeVk';
380 $list[] =
'Bitrix\Sender\Integration\Seo\Ads\TransportLookalikeFb';
381 $list[] = \Bitrix\Sender\Integration\Seo\Ads\TransportLookalikeYandex::class;
385 if (Crm\ReturnCustomer\Service::canUse())
387 $list[] =
'Bitrix\Sender\Integration\Crm\ReturnCustomer\TransportLead';
388 $list[] =
'Bitrix\Sender\Integration\Crm\ReturnCustomer\TransportDeal';
391 $list[] =
'Bitrix\Sender\Integration\Yandex\Toloka\TransportToloka';
405 $data = $event->getParameters();
407 if (Bitrix24\Service::isCloud() && isset($data[
'fields'][
'STATUS']))
409 $oldRow = LetterTable::getRowById($data[
'primary'][
'ID']);
410 $updatedBy = $data[
'fields'][
'UPDATED_BY'] ?? $oldRow[
'UPDATED_BY'];
412 if (in_array($data[
'fields'][
'STATUS'], Dispatch\Semantics::getWorkStates()))
414 $user =
new User($updatedBy);
415 if (!$user->isAgreementAccepted())
423 $letter = Entity\Letter::createInstanceById($data[
'primary'][
'ID']);
425 if (is_null($letter))
429 Loc::getMessage(
"SENDER_LETTER_ONBEFOREUPDATE_ERROR_LETTER_NOT_AVAILABLE"),
'FEATURE_NOT_AVAILABLE'
435 if (!$letter->getMessage()->isAvailable())
437 if ($letter->getState()->isWaiting() || $letter->getState()->isSending())
444 Loc::getMessage(
"SENDER_LETTER_ONBEFOREUPDATE_ERROR_FEATURE_NOT_AVAILABLE"),
'FEATURE_NOT_AVAILABLE'
450 $isEmail = ($oldRow[
'MESSAGE_CODE'] === Message\iBase::CODE_MAIL);
451 $isEmailBlocked = Bitrix24\Limitation\Rating::isBlocked();
452 if ($isEmail && $isEmailBlocked)
456 Bitrix24\Limitation\Rating::getNotifyText(
'blocked')
464 $emailFrom = $letter->getMessage()->getConfiguration()->getOption(
'EMAIL_FROM')->getValue();
465 if (!
Sender\AllowedSender::isAllowed($emailFrom, $updatedBy))
469 Loc::getMessage(
"SENDER_LETTER_ONBEFOREUPDATE_ERROR_INVALID_FROM_EMAIL"),
'WRONG_EMAIL_FROM'
486 if (!$result->isBelongTo(
'sender',
'rcpt'))
492 $row = PostingRecipientTable::getRow([
494 'STATUS',
'POSTING_ID',
'CONTACT_ID',
495 'CONTACT_IS_SEND_SUCCESS' =>
'CONTACT.IS_SEND_SUCCESS'
497 'filter' => [
'=ID' => $result->getEntityId()]
504 if (!$result->isError())
507 if ($row[
'CONTACT_IS_SEND_SUCCESS'] !==
'Y')
509 ContactTable::update($row[
'CONTACT_ID'], [
'IS_SEND_SUCCESS' =>
'Y']);
512 elseif ($result->isPermanentError())
521 Model\Posting\RecipientTable::update(
522 $result->getEntityId(),
527 Model\PostingTable::update(
530 'COUNT_SEND_ERROR' =>
new Main\DB\
SqlExpression(
'?# + 1',
'COUNT_SEND_ERROR'),
531 'COUNT_SEND_SUCCESS' =>
new Main\DB\
SqlExpression(
'?# - 1',
'COUNT_SEND_SUCCESS')
536 if (Bitrix24\Service::isCloud())
538 Bitrix24\Limitation\DailyLimit::incrementError();
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static onConnectorList(array $data=array())
static onSenderConsentMessageBuildersList()
static onSenderCompanyCard()
static onMailEventMailChangeStatus($result)
static onTriggerList(array $data=[])
static onSenderPresetList()
static onSenderConsentResponseList()
static onAfterPostingSendRecipient(array $eventData, Entity\Letter $letter)
static onSenderMessageList()
static onSenderTriggerCampaignPreset()
static onTemplateList($messageType)
static onConstantList($className)
static onBeforeUpdateLetterTable(MainEntity\Event $event, MainEntity\EventResult $result)
static onAfterPostingRecipientUnsubscribe(array $eventData)
static onSenderTransportList()
static onAfterPostingSendRecipientMultiple(array $eventDataArray, Entity\Letter $letter)