64 $result = RestAppTable::getList();
65 while ($row = $result->fetch())
68 'id' => $row[
'APP_ID'].
'|'.$row[
'CODE'],
69 'name' => sprintf(
'[%s] %s',
70 $this->getLangField($row[
'ID'],
'APP_NAME'),
71 $this->getLangField($row[
'ID'],
'NAME')
73 'description' => $this->getLangField($row[
'ID'],
'DESCRIPTION')
101 $sendResult->addError(
new Error(
Loc::getMessage(
'MESSAGESERVICE_SENDER_SMS_REST_ERROR_APP_NOT_FOUND')));
105 [$appId, $code] = explode(
'|', $messageFields[
'MESSAGE_FROM']);
110 $restSender = RestAppTable::getList(
122 $sendResult->addError(
new Error(
Loc::getMessage(
'MESSAGESERVICE_SENDER_SMS_REST_ERROR_APP_NOT_FOUND')));
133 $dbRes = \Bitrix\Rest\AppTable::getList([
135 '=CLIENT_ID' => $restSender[
'APP_ID'],
138 $application = $dbRes->fetch();
142 $sendResult->addError(
new Error(
Loc::getMessage(
'MESSAGESERVICE_SENDER_SMS_REST_ERROR_APP_NOT_FOUND')));
146 $appStatus = \Bitrix\Rest\AppTable::getAppStatusInfo($application,
'');
147 if($appStatus[
'PAYMENT_ALLOW'] ===
'N')
149 $sendResult->addError(
new Error(
Loc::getMessage(
'MESSAGESERVICE_SENDER_SMS_REST_ERROR_PAYMENT_ALLOW')));
153 $auth = $messageFields[
'AUTHOR_ID'] > 0 ? [
154 'CODE' => $restSender[
'CODE'],
157 "application_token" => \CRestUtil::getApplicationToken($application),
160 $messageId = $messageFields[
'EXTERNAL_ID'] ?? 0;
163 $messageId = md5(($messageFields[
'ID'] ?? 0).
'|'.uniqid());
164 $this->setExternalMessageId((
int)$messageFields[
'ID'], $messageId);
167 $restData = is_array($messageFields[
'MESSAGE_HEADERS']) ? $messageFields[
'MESSAGE_HEADERS'] : array();
169 $restData[
'properties'] = [
170 'phone_number' => $messageFields[
'MESSAGE_TO'],
173 $restData[
'type'] = $restSender[
'TYPE'];
174 $restData[
'code'] = $restSender[
'CODE'];
175 $restData[
'message_id'] = $messageId;
176 $restData[
'message_to'] = $messageFields[
'MESSAGE_TO'];
178 $restData[
'ts'] = time();
182 $restSender[
'APP_ID'],
183 $restSender[
'HANDLER'],
187 "sendAuth" => (
bool)$auth,
188 "sendRefreshToken" =>
false,
194 \Bitrix\Rest\OAuthService::getEngine()->getClient()->sendEvent($queryItems);
195 $sendResult->setExternalId($messageId);
196 $sendResult->setStatus(MessageService\MessageStatus::SENT);
198 if ($application[
'CODE'])
202 'sendRest' . $restSender[
'TYPE'],
203 uniqid($application[
'CODE'],
true),
208 if (is_callable([
'\Bitrix\Rest\UsageStatTable',
'logMessage']))
210 \Bitrix\Rest\UsageStatTable::logMessage($application[
'CLIENT_ID'], $restSender[
'TYPE']);
211 \Bitrix\Rest\UsageStatTable::finalize();
219 $status = parent::resolveStatus($serviceStatus);
221 switch ((
string)$serviceStatus)
224 return MessageService\MessageStatus::QUEUED;
227 return MessageService\MessageStatus::SENT;
230 return MessageService\MessageStatus::DELIVERED;
233 return MessageService\MessageStatus::UNDELIVERED;
236 return MessageService\MessageStatus::FAILED;