15 use Sender\Traits\RussianProvider;
19 public const ID =
'smsednaru';
23 $this->informant =
new SMS\Informant();
25 $this->utils =
new SMS\Utils($this->
getId(), $this->optionManager);
29 $this->initializeOldApiComponents();
33 $this->initializeNewApiComponents();
40 return $this->informant->getId();
45 return $this->informant->getName();
50 return $this->informant->getShortName();
55 return $this->informant->getType();
60 return $this->informant->getManageUrl();
65 return $this->informant->getExternalId();
70 return $this->registrar->isRegistered();
73 public function register(array $fields):
Result
75 $result = $this->registrar->register($fields);
76 if ($result->isSuccess())
78 \Bitrix\Main\Application::getInstance()->addBackgroundJob([$this,
'refreshFromList']);
79 \Bitrix\Main\Application::getInstance()->addBackgroundJob([$this,
'addRefreshFromListAgent']);
86 return $this->registrar->getOwnerInfo();
91 return $this->registrar->getExternalManageUrl();
96 return $this->registrar->getCallbackUrl();
101 return $this->registrar->isConfirmed();
106 return $this->registrar->confirmRegistration($fields);
111 return $this->registrar->sendConfirmationCode();
119 return $this->initiator->getFromList();
128 $this->utils->updateSavedChannelList($this->initiator->getChannelType());
133 return $this->initiator->isCorrectFrom($from);
138 return $this->initiator->getDefaultFrom();
143 return $this->initiator->getDefaultFrom();
148 return $this->sender->getMessageStatus($messageFields);
153 return $this->sender->sendMessage($messageFields);
158 return $this->sender->prepareMessageBodyForSave($text);
163 return $this->utils->getMessageTemplates($subject);
168 return $this->utils->getSentTemplateMessage($from, $to);
190 return 'https://edna.ru/sms-bitrix/';
195 $isMigratedToNewAPI = \Bitrix\Main\Config\Option::get(
'messageservice', $this->getMigratingOptionName(),
'N');
196 if ($isMigratedToNewAPI ===
'Y')
201 $currentDateTime = time();
202 $migratedDateTime = gmmktime(-3, 15,0, 12,1,2022);
204 return $currentDateTime >= $migratedDateTime;
207 private function initializeOldApiComponents(): void
210 $this->initiator =
new SMS\Old\Initiator($this->optionManager, $this->registrar, $this->utils, $this->
getId());
211 $this->sender =
new SMS\Old\Sender($this->optionManager,$this->registrar, $this->utils);
214 private function initializeNewApiComponents(): void
216 $this->registrar =
new SMS\Registrar($this->
getId(), $this->optionManager, $this->utils);
217 $this->initiator =
new SMS\Initiator($this->optionManager, $this->registrar, $this->utils, $this->
getId());
218 $this->sender =
new SMS\Sender($this->optionManager,$this->registrar, $this->utils);
225 if (!$this->
canUse() && !$oldRegistrar->canUse())
230 if ($this->
getOption(InternalOption::SENDER_ID) !==
null)
235 $channelListResult = $this->utils->getChannelList(Edna\
Constants\ChannelType::SMS);
238 foreach ($channelListResult->getData() as $channel)
240 if (isset($channel[
'active'], $channel[
'subjectId']) && $channel[
'active'] ===
true)
242 $subjectIdList[] = $channel[
'subjectId'];
243 $this->utils->setCallback(
248 $channel[
'subjectId']
252 $this->
setOption(InternalOption::SENDER_ID, $subjectIdList);
258 \Bitrix\Main\Config\Option::set(
'messageservice', $this->getMigratingOptionName(),$mode ?
'Y' :
'N');
261 private function getMigratingOptionName(): string
263 return $this->
getId() .
'_' . InternalOption::NEW_API_AVAILABLE;
276 \CAgent::AddAgent(static::class .
"::refreshFromListAgent();",
'messageservice',
'Y', $period);
286 if (!$sender::isSupported() || !
$sender->isRegistered())
293 return __METHOD__ .
'();';