-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsteriskAri.php
169 lines (126 loc) · 4.9 KB
/
AsteriskAri.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
namespace App\Models;
use Illuminate\Support\Facades\Http;
class AsteriskAri
{
protected $baseUrl;
protected $username;
protected $password;
public function __construct($baseUrl, $username, $password){
$this->baseUrl = $baseUrl;
$this->username = $username;
$this->password = $password;
}
private function request($method, $endpoint, $data = []){
$response = Http::withBasicAuth($this->username, $this->password)
->$method("{$this->baseUrl}/$endpoint", $data);
if ($response->failed())
throw new \Exception("ARI API Error: " . $response->body());
return $response->json();
}
public function listApplications(){
return $this->request('get', 'applications');
}
public function deleteApplicationSubscription($applicationName){
return $this->request('delete', "applications/{$applicationName}/subscription");
}
public function listBridges(){
return $this->request('get', 'bridges');
}
public function createBridge($data){
return $this->request('post', 'bridges', $data);
}
public function addChannelToBridge($bridgeId, $channel){
return $this->request('post', "bridges/{$bridgeId}/addChannel", ['channel' => $channel]);
}
public function removeChannelFromBridge($bridgeId, $channel){
return $this->request('post', "bridges/{$bridgeId}/removeChannel", ['channel' => $channel]);
}
public function deleteBridge($bridgeId){
return $this->request('delete', "bridges/{$bridgeId}");
}
public function listChannels(){
return $this->request('get', 'channels');
}
public function setChannel($channelId, $targetNumber, $callerId, $priority, $content){
return $this->request('post', "channels", [
'endpoint' => $channelId,
'extension' => $targetNumber,
'context' => $content,
'priority' => $priority,
'callerId' => $callerId,
]);
}
public function getChannel($channelId){
return $this->request('get', "channels/{$channelId}");
}
public function hangupChannel($channelId){
return $this->request('post', "channels/{$channelId}/hangup");
}
public function answerChannel($channelId){
return $this->request('post', "channels/{$channelId}/answer");
}
public function playMediaOnChannel($channelId, $mediaUri){
return $this->request('post', "channels/{$channelId}/play", ['media' => $mediaUri]);
}
public function holdChannel($channelId){
return $this->request('post', "channels/{$channelId}/hold");
}
public function unholdChannel($channelId){
return $this->request('post', "channels/{$channelId}/unhold");
}
public function listStoredRecordings(){
return $this->request('get', 'recordings/stored');
}
public function getStoredRecording($recordingName){
return $this->request('get', "recordings/stored/{$recordingName}");
}
public function deleteStoredRecording($recordingName){
return $this->request('delete', "recordings/stored/{$recordingName}");
}
public function startRecording($recordingName, $data){
return $this->request('post', "recordings/live/{$recordingName}", $data);
}
public function stopRecording($recordingName){
return $this->request('delete', "recordings/live/{$recordingName}");
}
public function listEndpoints(){
return $this->request('get', 'endpoints');
}
public function getEndpoint($tech, $resource){
return $this->request('get', "endpoints/{$tech}/{$resource}");
}
public function listDeviceStates(){
return $this->request('get', 'deviceStates');
}
public function getDeviceState($deviceName){
return $this->request('get', "deviceStates/{$deviceName}");
}
public function updateDeviceState($deviceName, $state){
return $this->request('put', "deviceStates/{$deviceName}", ['state' => $state]);
}
public function listSounds(){
return $this->request('get', 'sounds');
}
public function getSound($soundId){
return $this->request('get', "sounds/{$soundId}");
}
public function getPlayback($playbackId){
return $this->request('get', "playbacks/{$playbackId}");
}
public function stopPlayback($playbackId){
return $this->request('delete', "playbacks/{$playbackId}");
}
public function sendTextMessage($data){
return $this->request('post', 'messages', $data);
}
public function listModules(){
return $this->request('get', 'modules');
}
public function loadModule($moduleName){
return $this->request('post', "modules/load", ['module' => $moduleName]);
}
public function unloadModule($moduleName){
return $this->request('delete', "modules/unload", ['module' => $moduleName]);
}
}