Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Sender.php
1<?php
2
4
10
12{
13
14 public function getMessageStatus(array $messageFields): MessageStatus
15 {
16 return new MessageStatus();
17 }
18
19 public function prepareMessageBodyForSave(string $text): string
20 {
21 return Emoji::encode($text);
22 }
23
24 protected function initializeDefaultExternalSender(): Providers\ExternalSender
25 {
26 return new ExternalSender(
27 $this->optionManager->getOption(Providers\Constants\InternalOption::API_KEY),
29 $this->optionManager->getSocketTimeout(),
30 $this->optionManager->getStreamTimeout()
31 );
32 }
33
34 protected function getSendMessageParams(array $messageFields): Result
35 {
36 $cascadeResult = $this->getSenderFromSubject($messageFields['MESSAGE_FROM']);
37 if (!$cascadeResult->isSuccess())
38 {
39 return $cascadeResult;
40 }
41
42 $params = [
43 'requestId' => uniqid('', true),
44 'cascadeId' => $cascadeResult->getData()['cascadeId'],
45 'subscriberFilter' => [
46 'address' => str_replace('+', '', $messageFields['MESSAGE_TO']),
47 'type' => 'PHONE',
48 ],
49 ];
50 $params['content'] = $this->getMessageContent($messageFields);
51
52 return (new Result())->setData($params);
53 }
54
55 protected function getSendMessageMethod(array $messageFields): string
56 {
57 return Providers\Edna\Constants\Method::SEND_MESSAGE;
58 }
59
60 protected function isTemplateMessage(array $messageFields): bool
61 {
62 return false;
63 }
64
65 protected function sendHSMtoChat(array $messageFields): Result
66 {
67 return new Result();
68 }
69
74 private function getMessageContent(array $messageFields): array
75 {
76 return [
77 'smsContent' => [
78 'contentType' => Providers\Edna\Constants\ContentType::TEXT,
79 'text' => $this->prepareMessageBodyForSend($messageFields['MESSAGE_BODY']),
80 ],
81 ];
82 }
83
84 private function getSenderFromSubject($subject): Result
85 {
86 $cascadeResult = new Result();
87 if (is_numeric($subject))
88 {
89 $cascadeResult = $this->utils->getCascadeIdFromSubject(
90 (int)$subject,
91 static function(array $externalSubjectData, int $internalSubject)
92 {
93 return $externalSubjectData['id'] === $internalSubject;
94 }
95 );
96 }
97 elseif (is_string($subject))
98 {
99 $cascadeResult = $this->utils->getCascadeIdFromSubject(
100 $subject,
101 static function(array $externalSubjectData, string $internalSubject)
102 {
103 return $externalSubjectData['subject'] === $internalSubject;
104 }
105 );
106 }
107 else
108 {
109 $cascadeResult->addError(new Error('Invalid subject id'));
110 }
111
112 return $cascadeResult;
113 }
114}
static encode($text)
Definition emoji.php:17