|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\TotalVoice; |
|
4
|
|
|
|
|
5
|
|
|
use TotalVoice\Client as TotalVoiceService; |
|
6
|
|
|
use NotificationChannels\TotalVoice\Exceptions\CouldNotSendNotification; |
|
7
|
|
|
|
|
8
|
|
|
class TotalVoice |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var TotalVoiceService |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $totalVoiceService; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var TotalVoiceConfig |
|
17
|
|
|
*/ |
|
18
|
|
|
private $config; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* TotalVoice constructor. |
|
22
|
|
|
* |
|
23
|
|
|
* @param TotalVoiceService $totalVoiceService |
|
24
|
|
|
* @param TotalVoiceConfig $config |
|
25
|
|
|
*/ |
|
26
|
8 |
|
public function __construct(TotalVoiceService $totalVoiceService, TotalVoiceConfig $config) |
|
27
|
|
|
{ |
|
28
|
8 |
|
$this->totalVoiceService = $totalVoiceService; |
|
29
|
8 |
|
$this->config = $config; |
|
30
|
8 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Send a TotalVoiceMessage to the a phone number. |
|
34
|
|
|
* |
|
35
|
|
|
* @param TotalVoiceMessage $message |
|
36
|
|
|
* @param string $to |
|
37
|
|
|
* @return mixed |
|
38
|
|
|
* @throws CouldNotSendNotification |
|
39
|
|
|
*/ |
|
40
|
3 |
|
public function sendMessage(TotalVoiceMessage $message, $to) |
|
41
|
|
|
{ |
|
42
|
3 |
|
if ($message instanceof TotalVoiceSmsMessage) { |
|
43
|
1 |
|
return $this->sendSmsMessage($message, $to); |
|
44
|
|
|
} |
|
45
|
2 |
|
if ($message instanceof TotalVoiceTtsMessage) { |
|
46
|
1 |
|
return $this->sendTtsMessage($message, $to); |
|
47
|
|
|
} |
|
48
|
1 |
|
if ($message instanceof TotalVoiceAudioMessage) { |
|
49
|
|
|
return $this->sendAudioMessage($message, $to); |
|
50
|
|
|
} |
|
51
|
1 |
|
throw CouldNotSendNotification::invalidMessageObject($message); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Send an sms message using the TotalVoice Service. |
|
56
|
|
|
* |
|
57
|
|
|
* @param TotalVoiceSmsMessage $message |
|
58
|
|
|
* @param string $to |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
* @throws CouldNotSendNotification |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function sendSmsMessage(TotalVoiceSmsMessage $message, $to) |
|
63
|
|
|
{ |
|
64
|
1 |
|
return $this->totalVoiceService->sms->enviar($to, |
|
65
|
1 |
|
trim($message->content), |
|
66
|
1 |
|
$message->provide_feedback, |
|
67
|
1 |
|
$message->multi_part, |
|
68
|
1 |
|
$message->scheduled_datetime); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Make a text-to-speech call using the TotalVoice Service. |
|
73
|
|
|
* |
|
74
|
|
|
* @param TotalVoiceTtsMessage $message |
|
75
|
|
|
* @param string $to |
|
76
|
|
|
* @return mixed |
|
77
|
|
|
* @throws CouldNotSendNotification |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function sendTtsMessage(TotalVoiceTtsMessage $message, $to) |
|
80
|
|
|
{ |
|
81
|
|
|
$optionalParams = [ |
|
82
|
1 |
|
'velocidade' => $message->speed, |
|
83
|
1 |
|
'resposta_usuario' => $message->provide_feedback, |
|
84
|
1 |
|
'tipo_voz' => $message->voice_type, |
|
85
|
1 |
|
'bina' => $message->fake_number, |
|
86
|
1 |
|
'gravar_audio' => $message->record_audio, |
|
87
|
1 |
|
'detecta_caixa' => $message->detect_callbox, |
|
88
|
1 |
|
]; |
|
89
|
|
|
|
|
90
|
1 |
|
return $this->totalVoiceService->tts->enviar($to, |
|
91
|
1 |
|
trim($message->content), |
|
92
|
1 |
|
$optionalParams); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Make a call using the TotalVoice Service. |
|
97
|
|
|
* |
|
98
|
|
|
* @param TotalVoiceAudioMessage $message |
|
99
|
|
|
* @param string $to |
|
100
|
|
|
* @return mixed |
|
101
|
|
|
* @throws CouldNotSendNotification |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function sendAudioMessage(TotalVoiceAudioMessage $message, $to) |
|
104
|
|
|
{ |
|
105
|
1 |
|
return $this->totalVoiceService |
|
106
|
1 |
|
->audio |
|
107
|
1 |
|
->enviar($to, |
|
108
|
1 |
|
trim($message->content), |
|
109
|
1 |
|
$message->provide_feedback, |
|
110
|
1 |
|
$message->fake_number, |
|
111
|
1 |
|
$message->record_audio); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|