Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
transportaudiocall.php
1<?php
10
13
17
18Loc::loadMessages(__FILE__);
19
25{
27
29 protected $configuration;
30
32 protected $limiter;
33
35 protected $httpClient = array();
36
37 public function __construct()
38 {
39 $this->configuration = new Message\Configuration();
40 }
41
47 public function getName()
48 {
49 return Loc::getMessage('SENDER_INTEGRATION_AUDIOCALL_TRANSPORT_NAME');
50 }
51
57 public function getCode()
58 {
59 return self::CODE;
60 }
61
68 {
69 return array(Recipient\Type::PHONE);
70 }
71
77 public function loadConfiguration()
78 {
80 }
81
89 {
90 $this->configuration = $configuration;
91 }
92
97 public function start()
98 {
99 $clientOptions = array(
100 'waitResponse' => false,
101 'socketTimeout' => 5,
102 );
103 $this->httpClient = new HttpClient($clientOptions);
104 $this->httpClient->setTimeout(1);
105 }
106
116 public function send(Message\Adapter $message)
117 {
118 $outputNumber = $message->getConfiguration()->get('OUTPUT_NUMBER');
119 $number = $message->getTo();
120 $fileJson = $message->getConfiguration()->get('AUDIO_FILE');
121
122 $audio = (new Audio())
123 ->withJsonString($fileJson)
124 ->withMessageCode($message->getCode());
125
126 $callId = Service::sendFile(
127 $outputNumber,
128 $number,
129 $audio->getFileUrl(true)
130 );
131
132 if ($callId && $message->getRecipientId())
133 {
134 CallLogTable::add(array(
135 'CALL_ID' => $callId,
136 'RECIPIENT_ID' => $message->getRecipientId()
137 ));
138 }
139
140 return !!$callId;
141 }
142
147 public function end()
148 {
149
150 }
151
160 public function getDuration(Message\Adapter $message = null)
161 {
162 $length = 0;
163 $fileJson = $message->getConfiguration()->get('AUDIO_FILE');
164 if ($fileJson)
165 {
166 $audio = (new Audio())
167 ->withJsonString($fileJson)
168 ->withMessageCode($message->getCode());
169
170 $length = $audio->getDuration();
171 }
172 $length = $length ?: 20;
173 $magic = 5;
174 $limit = $this->getCountLimiter()->getLimit();
175
176 return round(($length + $magic) / $limit);
177 }
178
185 public function getLimiters(Message\iBase $message = null)
186 {
187 return array(
188 $this->getCountLimiter(),
189 Transport\TimeLimiter::create()
190 ->withLetter($message)
191 );
192 }
193
198 protected function getCountLimiter()
199 {
200 if ($this->limiter === null)
201 {
202 $this->limiter = new Limiter();
203 }
204
205 return $this->limiter;
206 }
207}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static sendFile($outputNumber, $number, $fileUrl)
Definition service.php:81
saveConfiguration(Message\Configuration $configuration)