forked from plivo/plivo-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipartycall.go
399 lines (362 loc) · 19.8 KB
/
multipartycall.go
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
package plivo
import "github.com/sirupsen/logrus"
type ListMPCMeta struct {
Previous *string
Next *string
TotalCount int64 `json:"count"`
Offset int64
Limit int64
}
type MultiPartyCallService struct {
client *Client
}
type MPCUpdateResponse struct {
CoachMode string `json:"coach_mode,omitempty" url:"coach_mode,omitempty"`
Mute string `json:"mute,omitempty" url:"mute,omitempty"`
Hold string `json:"hold,omitempty" url:"hold,omitempty"`
}
type MultiPartyCallAddParticipantParams struct {
Role string `json:"role,omitempty" url:"role,omitempty"`
From string `json:"from,omitempty" url:"from,omitempty"`
To string `json:"to,omitempty" url:"to,omitempty"`
CallUuid string `json:"call_uuid,omitempty" url:"call_uuid,omitempty"`
CallerName string `json:"caller_name,omitempty" url:"caller_name,omitempty"`
CallStatusCallbackUrl string `json:"call_status_callback_url,omitempty" url:"call_status_callback_url,omitempty"`
CallStatusCallbackMethod string `json:"call_status_callback_method,omitempty" url:"call_status_callback_method,omitempty"`
SipHeaders string `json:"sip_headers,omitempty" url:"sip_headers,omitempty"`
ConfirmKey string `json:"confirm_key,omitempty" url:"confirm_key,omitempty"`
ConfirmKeySoundUrl string `json:"confirm_key_sound_url,omitempty" url:"confirm_key_sound_url,omitempty"`
ConfirmKeySoundMethod string `json:"confirm_key_sound_method,omitempty" url:"confirm_key_sound_method,omitempty"`
DialMusic string `json:"dial_music,omitempty" url:"dial_music,omitempty"`
RingTimeout interface{} `json:"ring_timeout,omitempty" url:"ring_timeout,omitempty"`
DelayDial interface{} `json:"delay_dial,omitempty" uril:"caller_name,omitempty"`
MaxDuration int64 `json:"max_duration,omitempty" url:"max_duration,omitempty"`
MaxParticipants int64 `json:"max_participants,omitempty" url:"max_participants,omitempty"`
WaitMusicUrl string `json:"wait_music_url,omitempty" url:"wait_music_url,omitempty"`
WaitMusicMethod string `json:"wait_music_method,omitempty" url:"wait_music_method,omitempty"`
AgentHoldMusicUrl string `json:"agent_hold_music_url,omitempty" url:"agent_hold_music_url,omitempty"`
AgentHoldMusicMethod string `json:"agent_hold_music_method,omitempty" url:"agent_hold_music_method,omitempty"`
CustomerHoldMusicUrl string `json:"customer_hold_music_url,omitempty" url:"customer_hold_music_url,omitempty"`
CustomerHoldMusicMethod string `json:"customer_hold_music_method,omitempty" url:"customer_hold_music_method,omitempty"`
RecordingCallbackUrl string `json:"recording_callback_url,omitempty" url:"recording_callback_url,omitempty"`
RecordingCallbackMethod string `json:"recording_callback_method,omitempty" url:"recording_callback_method,omitempty"`
StatusCallbackUrl string `json:"status_callback_url,omitempty" url:"status_callback_url,omitempty"`
StatusCallbackMethod string `json:"status_callback_method,omitempty" url:"status_callback_method,omitempty"`
OnExitActionUrl string `json:"on_exit_action_url,omitempty" url:"on_exit_action_url,omitempty"`
OnExitActionMethod string `json:"on_exit_action_method,omitempty" url:"on_exit_action_method,omitempty"`
Record bool `json:"record,omitempty" url:"record,omitempty"`
RecordFileFormat string `json:"record_file_format,omitempty" url:"record_file_format,omitempty"`
StatusCallbackEvents string `json:"status_callback_events,omitempty" url:"status_callback_events,omitempty"`
StayAlone bool `json:"stay_alone,omitempty" url:"stay_alone,omitempty"`
CoachMode bool `json:"coach_mode,omitempty" url:"coach_mode,omitempty"`
Mute bool `json:"mute,omitempty" url:"mute,omitempty"`
Hold bool `json:"hold,omitempty" url:"hold,omitempty"`
StartMpcOnEnter *bool `json:"start_mpc_on_enter,omitempty" url:"start_mpc_on_enter,omitempty"`
EndMpcOnExit bool `json:"end_mpc_on_exit,omitempty" url:"end_mpc_on_exit,omitempty"`
RelayDtmfInputs bool `json:"relay_dtmf_inputs,omitempty" url:"relay_dtmf_inputs,omitempty"`
EnterSound string `json:"enter_sound,omitempty" url:"enter_sound,omitempty"`
EnterSoundMethod string `json:"enter_sound_method,omitempty" url:"enter_sound_method,omitempty"`
ExitSound string `json:"exit_sound,omitempty" url:"exit_sound,omitempty"`
ExitSoundMethod string `json:"exit_sound_method,omitempty" url:"exit_sound_method,omitempty"`
}
type MultiPartyCallListParams struct {
SubAccount string `json:"sub_account,omitempty" url:"sub_account,omitempty"`
FriendlyName string `json:"friendly_name,omitempty" url:"friendly_name,omitempty"`
Status string `json:"status,omitempty" url:"status,omitempty"`
TerminationCauseCode int64 `json:"termination_cause_code,omitempty" url:"termination_cause_code,omitempty"`
EndTimeGt string `json:"end_time__gt,omitempty" url:"end_time__gt,omitempty"`
EndTimeGte string `json:"end_time__gte,omitempty" url:"end_time__gte,omitempty"`
EndTimeLt string `json:"end_time__lt,omitempty" url:"end_time__lt,omitempty"`
EndTimeLte string `json:"end_time__lte,omitempty" url:"end_time__lte,omitempty"`
CreationTimeGt string `json:"creation_time__gt,omitempty" url:"creation_time__gt,omitempty"`
CreationTimeGte string `json:"creation_time__gte,omitempty" url:"creation_time__gte,omitempty"`
CreationTimeLt string `json:"creation_time__lt,omitempty" url:"creation_time__lt,omitempty"`
CreationTimeLte string `json:"creation_time__lte,omitempty" url:"creation_time__lte,omitempty"`
Limit int64 `json:"limit,omitempty" url:"limit,omitempty"`
Offset int64 `json:"offset,omitempty" url:"offset,omitempty"`
}
type MultiPartyCallBasicParams struct {
MpcUuid string
FriendlyName string
}
type MultiPartyCallListParticipantParams struct {
CallUuid string `json:"call_uuid,omitempty" url:"call_uuid,omitempty"`
}
type MultiPartyCallParticipantParams struct {
MpcUuid string
FriendlyName string
ParticipantId string
}
type MultiPartyCallUpdateParticipantParams struct {
CoachMode *bool `json:"coach_mode,omitempty" url:"coach_mode,omitempty"`
Mute *bool `json:"mute,omitempty" url:"mute,omitempty"`
Hold *bool `json:"hold,omitempty" url:"hold,omitempty"`
}
type MultiPartyCallStartRecordingParams struct {
FileFormat string `json:"file_format,omitempty" url:"file_format,omitempty"`
StatusCallbackUrl string `json:"status_callback_url,omitempty" url:"status_callback_url,omitempty"`
StatusCallbackMethod string `json:"status_callback_method,omitempty" url:"status_callback_method,omitempty"`
}
type MultiPartyCallListResponse struct {
ApiID string `json:"api_id" url:"api_id"`
Meta *ListMPCMeta `json:"meta" url:"meta"`
Objects []*MultiPartyCallGetResponse `json:"objects" url:"objects"`
}
type MultiPartyCallGetResponse struct {
BilledAmount string `json:"billed_amount,omitempty" url:"billed_amount,omitempty"`
BilledDuration int64 `json:"billed_duration,omitempty" url:"billed_duration,omitempty"`
CreationTime string `json:"creation_time,omitempty" url:"creation_time,omitempty"`
Duration int64 `json:"duration,omitempty" url:"duration,omitempty"`
EndTime string `json:"end_time,omitempty" url:"end_time,omitempty"`
FriendlyName string `json:"friendly_name,omitempty" url:"friendly_name,omitempty"`
MpcUuid string `json:"mpc_uuid,omitempty" url:"mpc_uuid,omitempty"`
Participants string `json:"participants,omitempty" url:"participants,omitempty"`
Recording string `json:"recording,omitempty" url:"recording,omitempty"`
ResourceUri string `json:"resource_uri,omitempty" url:"resource_uri,omitempty"`
StartTime string `json:"start_time,omitempty" url:"start_time,omitempty"`
Status string `json:"status,omitempty" url:"status,omitempty"`
StayAlone bool `json:"stay_alone,omitempty" url:"stay_alone,omitempty"`
SubAccount string `json:"sub_account,omitempty" url:"sub_account,omitempty"`
TerminationCause string `json:"termination_cause,omitempty" url:"termination_cause,omitempty"`
TerminationCauseCode int64 `json:"termination_cause_code,omitempty" url:"termination_cause_code,omitempty"`
}
type CallAddParticipant struct {
To string `json:"to,omitempty" url:"to,omitempty"`
From string `json:"from,omitempty" url:"from,omitempty"`
CallUuid string `json:"call_uuid,omitempty" url:"call_uuid,omitempty"`
}
type MultiPartyCallAddParticipantResponse struct {
ApiID string `json:"api_id" url:"api_id"`
Calls []*CallAddParticipant `json:"calls" url:"calls"`
Message string `json:"message,omitempty" url:"message,omitempty"`
RequestUuid string `json:"request_uuid,omitempty" url:"request_uuid,omitempty"`
}
type MultiPartyCallStartRecordingResponse struct {
ApiID string `json:"api_id" url:"api_id"`
Message string `json:"message,omitempty" url:"message,omitempty"`
RecordingId string `json:"recording_id,omitempty" url:"recording_id,omitempty"`
RecordingUrl string `json:"recording_url,omitempty" url:"recording_url,omitempty"`
}
type MultiPartyCallListParticipantsResponse struct {
ApiID string `json:"api_id" url:"api_id"`
Meta *ListMPCMeta `json:"meta" url:"meta"`
Objects []*MultiPartyCallParticipant `json:"objects" url:"objects"`
}
type MultiPartyCallParticipant struct {
BilledAmount string `json:"billed_amount,omitempty" url:"billed_amount,omitempty"`
BilledDuration int64 `json:"billed_duration,omitempty" url:"billed_duration,omitempty"`
CallUuid string `json:"call_uuid,omitempty" url:"call_uuid,omitempty"`
CoachMode bool `json:"coach_mode,omitempty" url:"coach_mode,omitempty"`
Duration int64 `json:"duration,omitempty" url:"duration,omitempty"`
EndMpcOnExit bool `json:"end_mpc_on_exit,omitempty" url:"end_mpc_on_exit,omitempty"`
ExitCause string `json:"exit_cause,omitempty" url:"exit_cause,omitempty"`
ExitTime string `json:"exit_time,omitempty" url:"exit_time,omitempty"`
Hold bool `json:"hold,omitempty" url:"hold,omitempty"`
JoinTime string `json:"join_time,omitempty" url:"join_time,omitempty"`
MemberId string `json:"member_id,omitempty" url:"member_id,omitempty"`
MpcUuid string `json:"mpc_uuid,omitempty" url:"mpc_uuid,omitempty"`
Mute bool `json:"mute,omitempty" url:"mute,omitempty"`
ResourceUri string `json:"resource_uri,omitempty" url:"resource_uri,omitempty"`
Role string `json:"role,omitempty" url:"role,omitempty"`
StartMpcOnEnter bool `json:"start_mpc_on_enter,omitempty" url:"start_mpc_on_enter,omitempty"`
}
type MultiPartyCallUpdateParticipantResponse struct {
ApiID string `json:"api_id" url:"api_id"`
MPCUpdateResponse
}
func (service *MultiPartyCallService) List(params MultiPartyCallListParams) (response *MultiPartyCallListResponse, err error) {
req, err := service.client.NewRequest("GET", params, "MultiPartyCall")
if err != nil {
return
}
response = &MultiPartyCallListResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *MultiPartyCallService) Get(basicParams MultiPartyCallBasicParams) (response *MultiPartyCallGetResponse, err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("GET", nil, "MultiPartyCall/%s", mpcId)
if err != nil {
return
}
response = &MultiPartyCallGetResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *MultiPartyCallService) AddParticipant(basicParams MultiPartyCallBasicParams, params MultiPartyCallAddParticipantParams) (response *MultiPartyCallAddParticipantResponse, err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
if (params.From != "" || params.To != "") && params.CallUuid != "" {
logrus.Fatal("cannot specify call_uuid when (from, to) is provided")
}
if params.From == "" && params.To == "" && params.CallUuid == "" {
logrus.Fatal("specify either call_uuid or (from, to)")
}
if params.CallUuid == "" && (params.From == "" || params.To == "") {
logrus.Fatal("specify (from, to) when not adding an existing call_uuid to multi party participant")
}
if params.CallerName == "" {
params.CallerName = params.From
}
if len(params.CallerName) > 50 {
logrus.Fatal("CallerName length must be in range [0,50]")
}
if params.RingTimeout == nil {
params.RingTimeout = 45
} else {
MultipleValidIntegers("RingTimeout", params.RingTimeout)
}
if params.DelayDial == nil {
params.DelayDial = 0
} else {
MultipleValidIntegers("DelayDial", params.DelayDial)
}
req, err := service.client.NewRequest("POST", params, "MultiPartyCall/%s/Participant", mpcId)
if err != nil {
return
}
response = &MultiPartyCallAddParticipantResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *MultiPartyCallService) Start(basicParams MultiPartyCallBasicParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", map[string]string{"status": "active"}, "MultiPartyCall/%s", mpcId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) Stop(basicParams MultiPartyCallBasicParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("DELETE", nil, "MultiPartyCall/%s", mpcId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) StartRecording(basicParams MultiPartyCallBasicParams, params MultiPartyCallStartRecordingParams) (response *MultiPartyCallStartRecordingResponse, err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", params, "MultiPartyCall/%s/Record", mpcId)
if err != nil {
return
}
response = &MultiPartyCallStartRecordingResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *MultiPartyCallService) StopRecording(basicParams MultiPartyCallBasicParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("DELETE", nil, "MultiPartyCall/%s/Record", mpcId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) PauseRecording(basicParams MultiPartyCallBasicParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", nil, "MultiPartyCall/%s/Record/Pause", mpcId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) ResumeRecording(basicParams MultiPartyCallBasicParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", nil, "MultiPartyCall/%s/Record/Resume", mpcId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) StartParticipantRecording(basicParams MultiPartyCallParticipantParams, params MultiPartyCallStartRecordingParams) (response *MultiPartyCallStartRecordingResponse, err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", params, "MultiPartyCall/%s/Participant/%s/Record", mpcId, basicParams.ParticipantId)
if err != nil {
return
}
response = &MultiPartyCallStartRecordingResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *MultiPartyCallService) StopParticipantRecording(basicParams MultiPartyCallParticipantParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("DELETE", nil, "MultiPartyCall/%s/Participant/%s/Record", mpcId, basicParams.ParticipantId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) PauseParticipantRecording(basicParams MultiPartyCallParticipantParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", nil, "MultiPartyCall/%s/Participant/%s/Record/Pause", mpcId, basicParams.ParticipantId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) ResumeParticipantRecording(basicParams MultiPartyCallParticipantParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", nil, "MultiPartyCall/%s/Participant/%s/Record/Resume", mpcId, basicParams.ParticipantId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) ListParticipants(basicParams MultiPartyCallBasicParams, params MultiPartyCallListParticipantParams) (response *MultiPartyCallListParticipantsResponse, err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("GET", params, "MultiPartyCall/%s/Participant", mpcId)
if err != nil {
return
}
response = &MultiPartyCallListParticipantsResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *MultiPartyCallService) UpdateParticipant(basicParams MultiPartyCallParticipantParams, params MultiPartyCallUpdateParticipantParams) (response *MultiPartyCallUpdateParticipantResponse, err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("POST", params, "MultiPartyCall/%s/Participant/%s", mpcId, basicParams.ParticipantId)
if err != nil {
return
}
response = &MultiPartyCallUpdateParticipantResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *MultiPartyCallService) KickParticipant(basicParams MultiPartyCallParticipantParams) (err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("DELETE", nil, "MultiPartyCall/%s/Participant/%s", mpcId, basicParams.ParticipantId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *MultiPartyCallService) GetParticipant(basicParams MultiPartyCallParticipantParams) (response *MultiPartyCallParticipant, err error) {
mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName)
req, err := service.client.NewRequest("GET", nil, "MultiPartyCall/%s/Participant/%s", mpcId, basicParams.ParticipantId)
if err != nil {
return
}
response = &MultiPartyCallParticipant{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func MakeMPCId(MpcUuid string, FriendlyName string) string {
mpcId := ""
if MpcUuid != "" {
mpcId = "uuid_" + MpcUuid
} else if FriendlyName != "" {
mpcId = "name_" + FriendlyName
} else {
logrus.Fatal("Need to specify a mpc_uuid or name")
}
return mpcId
}