Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
transportcall.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
TransportCall
implements
Transport\iBase
,
Transport\iDuration
,
Transport\iLimitation
25
{
26
const
CODE
=
self::CODE_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_CALL_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
87
public
function
saveConfiguration
(
Message
\
Configuration
$configuration
)
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
}
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\Limiter
Definition
limiter.php:23
Bitrix\Sender\Integration\VoxImplant\Service\send
static send($outputNumber, $number, $text, $voiceLanguage='', $voiceSpeed='', $voiceVolume='')
Definition
service.php:48
Bitrix\Sender\Integration\VoxImplant\SpeechRate\create
static create()
Definition
speechrate.php:28
Bitrix\Sender\Integration\VoxImplant\TransportCall
Definition
transportcall.php:25
Bitrix\Sender\Integration\VoxImplant\TransportCall\CODE
const CODE
Definition
transportcall.php:26
Bitrix\Sender\Integration\VoxImplant\TransportCall\__construct
__construct()
Definition
transportcall.php:37
Bitrix\Sender\Integration\VoxImplant\TransportCall\$httpClient
$httpClient
Definition
transportcall.php:35
Bitrix\Sender\Integration\VoxImplant\TransportCall\getDuration
getDuration(Message\Adapter $message=null)
Definition
transportcall.php:158
Bitrix\Sender\Integration\VoxImplant\TransportCall\getName
getName()
Definition
transportcall.php:47
Bitrix\Sender\Integration\VoxImplant\TransportCall\getSupportedRecipientTypes
getSupportedRecipientTypes()
Definition
transportcall.php:67
Bitrix\Sender\Integration\VoxImplant\TransportCall\send
send(Message\Adapter $message)
Definition
transportcall.php:112
Bitrix\Sender\Integration\VoxImplant\TransportCall\end
end()
Definition
transportcall.php:145
Bitrix\Sender\Integration\VoxImplant\TransportCall\loadConfiguration
loadConfiguration()
Definition
transportcall.php:77
Bitrix\Sender\Integration\VoxImplant\TransportCall\$configuration
$configuration
Definition
transportcall.php:29
Bitrix\Sender\Integration\VoxImplant\TransportCall\getLimiters
getLimiters(Message\iBase $message=null)
Definition
transportcall.php:180
Bitrix\Sender\Integration\VoxImplant\TransportCall\getCode
getCode()
Definition
transportcall.php:57
Bitrix\Sender\Integration\VoxImplant\TransportCall\$limiter
$limiter
Definition
transportcall.php:32
Bitrix\Sender\Integration\VoxImplant\TransportCall\saveConfiguration
saveConfiguration(Message\Configuration $configuration)
Definition
transportcall.php:87
Bitrix\Sender\Integration\VoxImplant\TransportCall\getCountLimiter
getCountLimiter()
Definition
transportcall.php:189
Bitrix\Sender\Integration\VoxImplant\TransportCall\start
start()
Definition
transportcall.php:95
Bitrix\Sender\Message\Adapter
Definition
adapter.php:21
Bitrix\Sender\Message\iBase
Definition
ibase.php:16
Bitrix\Sender\Message\iBase\CODE_CALL
const CODE_CALL
Definition
ibase.php:22
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
transportcall.php
Создано системой
1.10.0