23 return Loader::includeModule(
'messageservice');
34 $list = static::getSenderInfoList();
35 foreach ($list as $item)
42 $item[
'from'] = static::getSenderFromList($item[
'id']);
43 if (count($item[
'from']) == 0)
62 foreach (self::getProviders() as $item)
64 if (!$item[
'canUse'] || count($item[
'from']) == 0)
68 foreach ($item[
'from'] as $number)
70 $id = $item[
'id'] .
':' . $number[
'id'];
71 $name = $item[
'id'] ===
'rest' ? $number[
'name'] : ($item[
'shortName'] ?: $item[
'name']);
86 return MessageService\Sender\Limitation::getDailyLimits();
99 public static function send($senderId, $from, $to, $text, $authorId = 1)
101 if (!static::canUse())
106 $sender = MessageService\Sender\SmsManager::getSenderById($senderId);
112 $smsMessage = MessageService\Sender\SmsManager::createMessage(array(
113 'AUTHOR_ID' => $authorId,
115 'MESSAGE_BODY' => $text,
116 'MESSAGE_FROM' => $from,
117 'MESSAGE_HEADERS' => array(
118 'module_id' =>
'sender'
122 $sendResult = $smsMessage->sendDirectly();
123 return $sendResult->isSuccess();
133 return MessageService\Sender\SmsManager::getManageUrl();
143 return '/crm/configs/sms/?page=limits';
153 if (static::canUse())
155 $sender = MessageService\Sender\SmsManager::getSenderById($senderId);
158 $list = $sender->getFromList();
168 protected static function getSenderInfoList($getFromList =
false)
171 if (static::canUse())
173 $uri =
new Uri(self::getManageUrl());
174 foreach (MessageService\
Sender\SmsManager::getSenders() as $sender)
177 $uri->deleteParams([
'sender'])->addParams([
'sender' => $sender->getId()]);
180 'id' => $sender->getId(),
181 'isConfigurable' => $sender->isConfigurable(),
182 'name' => $sender->getName(),
183 'shortName' => $sender->getShortName(),
184 'canUse' => $sender->canUse(),
185 'isDemo' => $sender->isConfigurable() ? $sender->isDemo() : null,
186 'manageUrl' => $sender->isConfigurable() ?
187 $uri->getLocator() :
''
192 $senderInfo[
'fromList'] = static::getSenderFromList($sender->getId());
195 $info[] = $senderInfo;
205 if (
null === $numbers)
208 if (static::canUse())
210 $providers = static::getProviders();
211 foreach ($providers as $provider)
213 foreach ($provider[
'from'] as $number)
215 $numbers[$provider[
'id'] .
':'. $number[
'id']] = $number[
'name'];
221 return $numbers[$value] ?: $value;