Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
transportaudiocall.php
1
<?php
9
namespace
Bitrix\Sender\Integration\VoxImplant
;
10
11
use
Bitrix\Main\Localization\Loc
;
12
use
Bitrix\Main\Web\HttpClient
;
13
14
use
Bitrix\Sender\Message
;
15
use
Bitrix\Sender\Transport
;
16
use
Bitrix\Sender\Recipient
;
17
18
Loc::loadMessages
(__FILE__);
19
24
class
TransportAudioCall
implements
Transport\iBase
,
Transport\iDuration
,
Transport\iLimitation
25
{
26
const
CODE
=
self::CODE_AUDIO_CALL
;
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
67
public
function
getSupportedRecipientTypes
()
68
{
69
return
array(Recipient\Type::PHONE);
70
}
71
77
public
function
loadConfiguration
()
78
{
79
return
$this->configuration
;
80
}
81
88
public
function
saveConfiguration
(
Message
\
Configuration
$configuration
)
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
}
Bitrix\Main\Config\Configuration
Definition
configuration.php:7
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Web\HttpClient
Definition
httpclient.php:24
Bitrix\Sender\Entity\Message
Definition
message.php:27
Bitrix\Sender\Integration\VoxImplant\Audio
Definition
audio.php:22
Bitrix\Sender\Integration\VoxImplant\Limiter
Definition
limiter.php:23
Bitrix\Sender\Integration\VoxImplant\Service\sendFile
static sendFile($outputNumber, $number, $fileUrl)
Definition
service.php:81
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall
Definition
transportaudiocall.php:25
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\CODE
const CODE
Definition
transportaudiocall.php:26
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\__construct
__construct()
Definition
transportaudiocall.php:37
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\$httpClient
$httpClient
Definition
transportaudiocall.php:35
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\getDuration
getDuration(Message\Adapter $message=null)
Definition
transportaudiocall.php:160
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\getName
getName()
Definition
transportaudiocall.php:47
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\getSupportedRecipientTypes
getSupportedRecipientTypes()
Definition
transportaudiocall.php:67
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\send
send(Message\Adapter $message)
Definition
transportaudiocall.php:116
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\end
end()
Definition
transportaudiocall.php:147
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\loadConfiguration
loadConfiguration()
Definition
transportaudiocall.php:77
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\$configuration
$configuration
Definition
transportaudiocall.php:29
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\getLimiters
getLimiters(Message\iBase $message=null)
Definition
transportaudiocall.php:185
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\getCode
getCode()
Definition
transportaudiocall.php:57
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\$limiter
$limiter
Definition
transportaudiocall.php:32
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\saveConfiguration
saveConfiguration(Message\Configuration $configuration)
Definition
transportaudiocall.php:88
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\getCountLimiter
getCountLimiter()
Definition
transportaudiocall.php:198
Bitrix\Sender\Integration\VoxImplant\TransportAudioCall\start
start()
Definition
transportaudiocall.php:97
Bitrix\Sender\Message\Adapter
Definition
adapter.php:21
Bitrix\Sender\Message\iBase
Definition
ibase.php:16
Bitrix\Sender\Message\iBase\CODE_AUDIO_CALL
const CODE_AUDIO_CALL
Definition
ibase.php:23
Bitrix\Sender\Transport\iDuration
Definition
iduration.php:18
Bitrix\Sender\Transport\iLimitation
Definition
ilimitation.php:18
Bitrix\Sender\Integration\VoxImplant
Definition
audio.php:9
Bitrix\Sender\Message
Definition
adapter.php:9
Bitrix\Sender\Recipient
Definition
agent.php:8
Bitrix\Sender\Transport
Definition
adapter.php:9
modules
sender
lib
integration
voximplant
transportaudiocall.php
Создано системой
1.10.0