Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
transportcall.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_CALL_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
88 {
89 $this->configuration = $configuration;
90 }
91
95 public function start()
96 {
97 $clientOptions = array(
98 'waitResponse' => false,
99 'socketTimeout' => 5,
100 );
101 $this->httpClient = new HttpClient($clientOptions);
102 $this->httpClient->setTimeout(1);
103 }
104
112 public function send(Message\Adapter $message)
113 {
114 $outputNumber = $message->getConfiguration()->get('OUTPUT_NUMBER');
115 $number = $message->getTo();
116 $text = $message->getConfiguration()->get('MESSAGE_TEXT');
117 $text = $message->replaceFields($text);
118 $voiceLanguage = $message->getConfiguration()->get('VOICE_LANGUAGE');
119 $voiceSpeed = $message->getConfiguration()->get('VOICE_SPEED');
120 $voiceVolume = $message->getConfiguration()->get('VOICE_VOLUME');
121
122 $callId = Service::send(
123 $outputNumber,
124 $number,
125 $text,
126 $voiceLanguage,
127 $voiceSpeed,
128 $voiceVolume
129 );
130
131 if ($callId && $message->getRecipientId())
132 {
133 CallLogTable::add(array(
134 'CALL_ID' => $callId,
135 'RECIPIENT_ID' => $message->getRecipientId()
136 ));
137 }
138
139 return !!$callId;
140 }
141
145 public function end()
146 {
147
148 }
149
158 public function getDuration(Message\Adapter $message = null)
159 {
160 $messageText = $message->getConfiguration()->get('MESSAGE_TEXT');
161 $voiceSpeed = $message->getConfiguration()->get('VOICE_SPEED');
162 $length = SpeechRate::create()
163 ->withSpeed($voiceSpeed)
164 ->withText($messageText)
165 ->getDuration();
166
167 $length = $length ?: 20;
168 $magic = 5;
169 $limit = $this->getCountLimiter()->getLimit();
170
171 return round(($length + $magic) / $limit);
172 }
173
180 public function getLimiters(Message\iBase $message = null)
181 {
182 return [
183 $this->getCountLimiter(),
184 Transport\TimeLimiter::create()
185 ->withLetter($message)
186 ];
187 }
188
189 protected function getCountLimiter()
190 {
191 if ($this->limiter === null)
192 {
193 $this->limiter = new Limiter();
194 }
195
196 return $this->limiter;
197 }
198}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static send($outputNumber, $number, $text, $voiceLanguage='', $voiceSpeed='', $voiceVolume='')
Definition service.php:48
saveConfiguration(Message\Configuration $configuration)