70 public function send($directly =
false)
76 $result->addError(
new Main\
Error(
"Module messageservice is not installed.", self::ERR_MODULE));
80 $senderId = Main\Config\Option::get(
"main",
"sms_default_service");
88 if (!$messageListResult->isSuccess())
90 return $result->addErrors($messageListResult->getErrors());
92 $messageList = $messageListResult->getData();
94 foreach($messageList as $message)
96 $smsMessage = \Bitrix\MessageService\Sender\SmsManager::createMessage([
97 'SENDER_ID' => $senderId,
98 'MESSAGE_FROM' => $message->getSender(),
99 'MESSAGE_TO' => $message->getReceiver(),
100 'MESSAGE_BODY' => $message->getText(),
103 $event =
new Main\Event(
'main',
'onBeforeSendSms', [
104 'message' => $smsMessage,
105 'template' => $message->getTemplate()
108 foreach($event->getResults() as $evenResult)
110 if($evenResult->getType() === Main\EventResult::ERROR)
118 $smsResult = $smsMessage->sendDirectly();
122 $smsResult = $smsMessage->send();
125 if(!$smsResult->isSuccess())
127 $result->addErrors($smsResult->getErrors());
140 $context = Main\Context::getCurrent();
142 if($this->siteId ===
null)
144 $this->siteId = $context->getSite();
145 if($this->siteId ===
null)
147 $result->addError(
new Main\
Error(
"Can't filter templates, the siteId is not set.", self::ERR_SITE));
152 if($this->languageId ===
null)
154 $this->languageId = $context->getLanguage();
158 if($templates->isEmpty())
160 $result->addError(
new Main\
Error(
"Templates not found.", self::ERR_TEMPLATES));
165 foreach($templates as $template)
167 $messageList[] = Message::createFromTemplate($template, $this->fields);
169 $result->setData($messageList);