@unboundcx/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,434 @@
1
+ export class VoiceService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ async createCall({ to, from, connectionId, callerId, timeout, machineDetection, machineDetectionTimeout, recordingChannels, record, recordingFormat, recordingTrack, recordingMaxLength, transcribe, transcribeLanguage, webhookUrl, commandId, clientState, customHeaders, sipAuthUsername, sipAuthPassword, sipTransport, sipHeaders, ringTimeout, answeringMachineDetection, detectWordOrPhrase, billingGroupId, answerUrl, answerMethod }) {
7
+ this.sdk.validateParams(
8
+ { to },
9
+ {
10
+ to: { type: 'string', required: true },
11
+ from: { type: 'string', required: false },
12
+ connectionId: { type: 'string', required: false },
13
+ callerId: { type: 'string', required: false },
14
+ timeout: { type: 'number', required: false },
15
+ machineDetection: { type: 'boolean', required: false },
16
+ machineDetectionTimeout: { type: 'number', required: false },
17
+ recordingChannels: { type: 'string', required: false },
18
+ record: { type: 'boolean', required: false },
19
+ recordingFormat: { type: 'string', required: false },
20
+ recordingTrack: { type: 'string', required: false },
21
+ recordingMaxLength: { type: 'number', required: false },
22
+ transcribe: { type: 'boolean', required: false },
23
+ transcribeLanguage: { type: 'string', required: false },
24
+ webhookUrl: { type: 'string', required: false },
25
+ commandId: { type: 'string', required: false },
26
+ clientState: { type: 'string', required: false },
27
+ customHeaders: { type: 'array', required: false },
28
+ sipAuthUsername: { type: 'string', required: false },
29
+ sipAuthPassword: { type: 'string', required: false },
30
+ sipTransport: { type: 'string', required: false },
31
+ sipHeaders: { type: 'array', required: false },
32
+ ringTimeout: { type: 'number', required: false },
33
+ answeringMachineDetection: { type: 'string', required: false },
34
+ detectWordOrPhrase: { type: 'string', required: false },
35
+ billingGroupId: { type: 'string', required: false },
36
+ answerUrl: { type: 'string', required: false },
37
+ answerMethod: { type: 'string', required: false },
38
+ },
39
+ );
40
+
41
+ const callData = { to };
42
+ if (from) callData.from = from;
43
+ if (connectionId) callData.connectionId = connectionId;
44
+ if (callerId) callData.callerId = callerId;
45
+ if (timeout) callData.timeout = timeout;
46
+ if (machineDetection !== undefined) callData.machineDetection = machineDetection;
47
+ if (machineDetectionTimeout) callData.machineDetectionTimeout = machineDetectionTimeout;
48
+ if (recordingChannels) callData.recordingChannels = recordingChannels;
49
+ if (record !== undefined) callData.record = record;
50
+ if (recordingFormat) callData.recordingFormat = recordingFormat;
51
+ if (recordingTrack) callData.recordingTrack = recordingTrack;
52
+ if (recordingMaxLength) callData.recordingMaxLength = recordingMaxLength;
53
+ if (transcribe !== undefined) callData.transcribe = transcribe;
54
+ if (transcribeLanguage) callData.transcribeLanguage = transcribeLanguage;
55
+ if (webhookUrl) callData.webhookUrl = webhookUrl;
56
+ if (commandId) callData.commandId = commandId;
57
+ if (clientState) callData.clientState = clientState;
58
+ if (customHeaders) callData.customHeaders = customHeaders;
59
+ if (sipAuthUsername) callData.sipAuthUsername = sipAuthUsername;
60
+ if (sipAuthPassword) callData.sipAuthPassword = sipAuthPassword;
61
+ if (sipTransport) callData.sipTransport = sipTransport;
62
+ if (sipHeaders) callData.sipHeaders = sipHeaders;
63
+ if (ringTimeout) callData.ringTimeout = ringTimeout;
64
+ if (answeringMachineDetection) callData.answeringMachineDetection = answeringMachineDetection;
65
+ if (detectWordOrPhrase) callData.detectWordOrPhrase = detectWordOrPhrase;
66
+ if (billingGroupId) callData.billingGroupId = billingGroupId;
67
+ if (answerUrl) callData.answerUrl = answerUrl;
68
+ if (answerMethod) callData.answerMethod = answerMethod;
69
+
70
+ const params = {
71
+ body: callData,
72
+ };
73
+
74
+ const result = await this.sdk._fetch('/voice/calls', 'POST', params);
75
+ return result;
76
+ }
77
+
78
+ async hangup(callControlId, clientState, commandId) {
79
+ this.sdk.validateParams(
80
+ { callControlId },
81
+ {
82
+ callControlId: { type: 'string', required: true },
83
+ clientState: { type: 'string', required: false },
84
+ commandId: { type: 'string', required: false },
85
+ },
86
+ );
87
+
88
+ const hangupData = {};
89
+ if (clientState) hangupData.clientState = clientState;
90
+ if (commandId) hangupData.commandId = commandId;
91
+
92
+ const params = {
93
+ body: hangupData,
94
+ };
95
+
96
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/hangup`, 'POST', params);
97
+ return result;
98
+ }
99
+
100
+ async hold(callControlId, audioUrl, clientState, commandId) {
101
+ this.sdk.validateParams(
102
+ { callControlId },
103
+ {
104
+ callControlId: { type: 'string', required: true },
105
+ audioUrl: { type: 'string', required: false },
106
+ clientState: { type: 'string', required: false },
107
+ commandId: { type: 'string', required: false },
108
+ },
109
+ );
110
+
111
+ const holdData = {};
112
+ if (audioUrl) holdData.audioUrl = audioUrl;
113
+ if (clientState) holdData.clientState = clientState;
114
+ if (commandId) holdData.commandId = commandId;
115
+
116
+ const params = {
117
+ body: holdData,
118
+ };
119
+
120
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/hold`, 'POST', params);
121
+ return result;
122
+ }
123
+
124
+ async unhold(callControlId, clientState, commandId) {
125
+ this.sdk.validateParams(
126
+ { callControlId },
127
+ {
128
+ callControlId: { type: 'string', required: true },
129
+ clientState: { type: 'string', required: false },
130
+ commandId: { type: 'string', required: false },
131
+ },
132
+ );
133
+
134
+ const unholdData = {};
135
+ if (clientState) unholdData.clientState = clientState;
136
+ if (commandId) unholdData.commandId = commandId;
137
+
138
+ const params = {
139
+ body: unholdData,
140
+ };
141
+
142
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/unhold`, 'POST', params);
143
+ return result;
144
+ }
145
+
146
+ async mute(callControlId, clientState, commandId) {
147
+ this.sdk.validateParams(
148
+ { callControlId },
149
+ {
150
+ callControlId: { type: 'string', required: true },
151
+ clientState: { type: 'string', required: false },
152
+ commandId: { type: 'string', required: false },
153
+ },
154
+ );
155
+
156
+ const muteData = {};
157
+ if (clientState) muteData.clientState = clientState;
158
+ if (commandId) muteData.commandId = commandId;
159
+
160
+ const params = {
161
+ body: muteData,
162
+ };
163
+
164
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/mute`, 'POST', params);
165
+ return result;
166
+ }
167
+
168
+ async unmute(callControlId, clientState, commandId) {
169
+ this.sdk.validateParams(
170
+ { callControlId },
171
+ {
172
+ callControlId: { type: 'string', required: true },
173
+ clientState: { type: 'string', required: false },
174
+ commandId: { type: 'string', required: false },
175
+ },
176
+ );
177
+
178
+ const unmuteData = {};
179
+ if (clientState) unmuteData.clientState = clientState;
180
+ if (commandId) unmuteData.commandId = commandId;
181
+
182
+ const params = {
183
+ body: unmuteData,
184
+ };
185
+
186
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/unmute`, 'POST', params);
187
+ return result;
188
+ }
189
+
190
+ async sendDtmf(callControlId, dtmf, clientState, commandId) {
191
+ this.sdk.validateParams(
192
+ { callControlId, dtmf },
193
+ {
194
+ callControlId: { type: 'string', required: true },
195
+ dtmf: { type: 'string', required: true },
196
+ clientState: { type: 'string', required: false },
197
+ commandId: { type: 'string', required: false },
198
+ },
199
+ );
200
+
201
+ const dtmfData = { dtmf };
202
+ if (clientState) dtmfData.clientState = clientState;
203
+ if (commandId) dtmfData.commandId = commandId;
204
+
205
+ const params = {
206
+ body: dtmfData,
207
+ };
208
+
209
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/send_dtmf`, 'POST', params);
210
+ return result;
211
+ }
212
+
213
+ async record(callControlId, recordingChannels, recordingFormat, recordingMaxLength, recordingTerminators, recordingBeep, recordingPlayBeep, clientState, commandId) {
214
+ this.sdk.validateParams(
215
+ { callControlId },
216
+ {
217
+ callControlId: { type: 'string', required: true },
218
+ recordingChannels: { type: 'string', required: false },
219
+ recordingFormat: { type: 'string', required: false },
220
+ recordingMaxLength: { type: 'number', required: false },
221
+ recordingTerminators: { type: 'string', required: false },
222
+ recordingBeep: { type: 'boolean', required: false },
223
+ recordingPlayBeep: { type: 'boolean', required: false },
224
+ clientState: { type: 'string', required: false },
225
+ commandId: { type: 'string', required: false },
226
+ },
227
+ );
228
+
229
+ const recordData = {};
230
+ if (recordingChannels) recordData.recordingChannels = recordingChannels;
231
+ if (recordingFormat) recordData.recordingFormat = recordingFormat;
232
+ if (recordingMaxLength) recordData.recordingMaxLength = recordingMaxLength;
233
+ if (recordingTerminators) recordData.recordingTerminators = recordingTerminators;
234
+ if (recordingBeep !== undefined) recordData.recordingBeep = recordingBeep;
235
+ if (recordingPlayBeep !== undefined) recordData.recordingPlayBeep = recordingPlayBeep;
236
+ if (clientState) recordData.clientState = clientState;
237
+ if (commandId) recordData.commandId = commandId;
238
+
239
+ const params = {
240
+ body: recordData,
241
+ };
242
+
243
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/record_start`, 'POST', params);
244
+ return result;
245
+ }
246
+
247
+ async stopRecording(callControlId, clientState, commandId) {
248
+ this.sdk.validateParams(
249
+ { callControlId },
250
+ {
251
+ callControlId: { type: 'string', required: true },
252
+ clientState: { type: 'string', required: false },
253
+ commandId: { type: 'string', required: false },
254
+ },
255
+ );
256
+
257
+ const stopData = {};
258
+ if (clientState) stopData.clientState = clientState;
259
+ if (commandId) stopData.commandId = commandId;
260
+
261
+ const params = {
262
+ body: stopData,
263
+ };
264
+
265
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/record_stop`, 'POST', params);
266
+ return result;
267
+ }
268
+
269
+ async transcribe(callControlId, transcriptionEngine, transcriptionLanguage, transcriptionFormat, clientState, commandId) {
270
+ this.sdk.validateParams(
271
+ { callControlId },
272
+ {
273
+ callControlId: { type: 'string', required: true },
274
+ transcriptionEngine: { type: 'string', required: false },
275
+ transcriptionLanguage: { type: 'string', required: false },
276
+ transcriptionFormat: { type: 'string', required: false },
277
+ clientState: { type: 'string', required: false },
278
+ commandId: { type: 'string', required: false },
279
+ },
280
+ );
281
+
282
+ const transcribeData = {};
283
+ if (transcriptionEngine) transcribeData.transcriptionEngine = transcriptionEngine;
284
+ if (transcriptionLanguage) transcribeData.transcriptionLanguage = transcriptionLanguage;
285
+ if (transcriptionFormat) transcribeData.transcriptionFormat = transcriptionFormat;
286
+ if (clientState) transcribeData.clientState = clientState;
287
+ if (commandId) transcribeData.commandId = commandId;
288
+
289
+ const params = {
290
+ body: transcribeData,
291
+ };
292
+
293
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/transcription_start`, 'POST', params);
294
+ return result;
295
+ }
296
+
297
+ async stopTranscribing(callControlId, clientState, commandId) {
298
+ this.sdk.validateParams(
299
+ { callControlId },
300
+ {
301
+ callControlId: { type: 'string', required: true },
302
+ clientState: { type: 'string', required: false },
303
+ commandId: { type: 'string', required: false },
304
+ },
305
+ );
306
+
307
+ const stopData = {};
308
+ if (clientState) stopData.clientState = clientState;
309
+ if (commandId) stopData.commandId = commandId;
310
+
311
+ const params = {
312
+ body: stopData,
313
+ };
314
+
315
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/transcription_stop`, 'POST', params);
316
+ return result;
317
+ }
318
+
319
+ async transfer(callControlId, to, from, answerUrl, answerMethod, clientState, commandId) {
320
+ this.sdk.validateParams(
321
+ { callControlId, to },
322
+ {
323
+ callControlId: { type: 'string', required: true },
324
+ to: { type: 'string', required: true },
325
+ from: { type: 'string', required: false },
326
+ answerUrl: { type: 'string', required: false },
327
+ answerMethod: { type: 'string', required: false },
328
+ clientState: { type: 'string', required: false },
329
+ commandId: { type: 'string', required: false },
330
+ },
331
+ );
332
+
333
+ const transferData = { to };
334
+ if (from) transferData.from = from;
335
+ if (answerUrl) transferData.answerUrl = answerUrl;
336
+ if (answerMethod) transferData.answerMethod = answerMethod;
337
+ if (clientState) transferData.clientState = clientState;
338
+ if (commandId) transferData.commandId = commandId;
339
+
340
+ const params = {
341
+ body: transferData,
342
+ };
343
+
344
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/transfer`, 'POST', params);
345
+ return result;
346
+ }
347
+
348
+ async createConference({ name, recordingChannels, recordingFormat, recordingMaxLength, recordingTerminators, webhookUrl, commandId, clientState }) {
349
+ this.sdk.validateParams(
350
+ { name },
351
+ {
352
+ name: { type: 'string', required: true },
353
+ recordingChannels: { type: 'string', required: false },
354
+ recordingFormat: { type: 'string', required: false },
355
+ recordingMaxLength: { type: 'number', required: false },
356
+ recordingTerminators: { type: 'string', required: false },
357
+ webhookUrl: { type: 'string', required: false },
358
+ commandId: { type: 'string', required: false },
359
+ clientState: { type: 'string', required: false },
360
+ },
361
+ );
362
+
363
+ const conferenceData = { name };
364
+ if (recordingChannels) conferenceData.recordingChannels = recordingChannels;
365
+ if (recordingFormat) conferenceData.recordingFormat = recordingFormat;
366
+ if (recordingMaxLength) conferenceData.recordingMaxLength = recordingMaxLength;
367
+ if (recordingTerminators) conferenceData.recordingTerminators = recordingTerminators;
368
+ if (webhookUrl) conferenceData.webhookUrl = webhookUrl;
369
+ if (commandId) conferenceData.commandId = commandId;
370
+ if (clientState) conferenceData.clientState = clientState;
371
+
372
+ const params = {
373
+ body: conferenceData,
374
+ };
375
+
376
+ const result = await this.sdk._fetch('/voice/conferences', 'POST', params);
377
+ return result;
378
+ }
379
+
380
+ async joinConference(callControlId, conferenceId, startConferenceOnEnter, endConferenceOnExit, muted, hold, holdAudioUrl, clientState, commandId) {
381
+ this.sdk.validateParams(
382
+ { callControlId, conferenceId },
383
+ {
384
+ callControlId: { type: 'string', required: true },
385
+ conferenceId: { type: 'string', required: true },
386
+ startConferenceOnEnter: { type: 'boolean', required: false },
387
+ endConferenceOnExit: { type: 'boolean', required: false },
388
+ muted: { type: 'boolean', required: false },
389
+ hold: { type: 'boolean', required: false },
390
+ holdAudioUrl: { type: 'string', required: false },
391
+ clientState: { type: 'string', required: false },
392
+ commandId: { type: 'string', required: false },
393
+ },
394
+ );
395
+
396
+ const joinData = { conferenceId };
397
+ if (startConferenceOnEnter !== undefined) joinData.startConferenceOnEnter = startConferenceOnEnter;
398
+ if (endConferenceOnExit !== undefined) joinData.endConferenceOnExit = endConferenceOnExit;
399
+ if (muted !== undefined) joinData.muted = muted;
400
+ if (hold !== undefined) joinData.hold = hold;
401
+ if (holdAudioUrl) joinData.holdAudioUrl = holdAudioUrl;
402
+ if (clientState) joinData.clientState = clientState;
403
+ if (commandId) joinData.commandId = commandId;
404
+
405
+ const params = {
406
+ body: joinData,
407
+ };
408
+
409
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/conference_join`, 'POST', params);
410
+ return result;
411
+ }
412
+
413
+ async leaveConference(callControlId, clientState, commandId) {
414
+ this.sdk.validateParams(
415
+ { callControlId },
416
+ {
417
+ callControlId: { type: 'string', required: true },
418
+ clientState: { type: 'string', required: false },
419
+ commandId: { type: 'string', required: false },
420
+ },
421
+ );
422
+
423
+ const leaveData = {};
424
+ if (clientState) leaveData.clientState = clientState;
425
+ if (commandId) leaveData.commandId = commandId;
426
+
427
+ const params = {
428
+ body: leaveData,
429
+ };
430
+
431
+ const result = await this.sdk._fetch(`/voice/calls/${callControlId}/actions/conference_leave`, 'POST', params);
432
+ return result;
433
+ }
434
+ }