@unboundcx/sdk 2.8.6 → 2.8.7

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.
package/services/voice.js CHANGED
@@ -3,72 +3,151 @@ export class VoiceService {
3
3
  this.sdk = sdk;
4
4
  }
5
5
 
6
- async call({
7
- to,
8
- from,
9
- callerIdName,
10
- callerIdNumber,
11
- timeout,
12
- confirmAnswer,
13
- app,
14
- variables,
15
- engagementSessionId,
16
- voiceChannelId,
17
- serverId,
18
- }) {
6
+ async record({ cdrId, callId, action = 'start', direction = 'sendrecv' }) {
19
7
  this.sdk.validateParams(
20
- {},
8
+ { callId, cdrId, action, direction },
21
9
  {
22
- to: { type: 'string', required: false },
23
- from: { type: 'string', required: false },
24
- callerIdName: { type: 'string', required: false },
25
- callerIdNumber: { type: 'string', required: false },
26
- timeout: { type: 'number', required: false },
27
- confirmAnswer: { type: 'boolean', required: false },
28
- app: { type: 'object', required: false },
29
- variables: { type: 'object', required: false },
30
- engagementSessionId: { type: 'string', required: false },
31
- voiceChannelId: { type: 'string', required: false },
32
- serverId: { type: 'string', required: false },
10
+ cdrId: { type: 'string', required: false },
11
+ callId: { type: 'string', required: false },
12
+ action: { type: 'string', required: false },
13
+ direction: { type: 'string', required: false },
33
14
  },
34
15
  );
35
16
 
36
- const callData = {};
37
- if (to) callData.to = to;
38
- if (from) callData.from = from;
39
- if (callerIdName) callData.callerIdName = callerIdName;
40
- if (callerIdNumber) callData.callerIdNumber = callerIdNumber;
41
- if (timeout !== undefined) callData.timeout = timeout;
42
- if (confirmAnswer !== undefined) callData.confirmAnswer = confirmAnswer;
43
- if (app) callData.app = app;
44
- if (variables) callData.variables = variables;
45
- if (engagementSessionId) callData.engagementSessionId = engagementSessionId;
46
- if (voiceChannelId) callData.voiceChannelId = voiceChannelId;
47
- if (serverId) callData.serverId = serverId;
17
+ const params = {
18
+ body: { callId, cdrId, action, direction },
19
+ };
20
+
21
+ const result = await this.sdk._fetch(`/voice/record/`, 'POST', params);
22
+ return result;
23
+ }
24
+
25
+ async call({ to, from, destination, app, timeout, customHeaders }) {
26
+ this.sdk.validateParams(
27
+ { to, from, destination, app, timeout, customHeaders },
28
+ {
29
+ to: { type: 'string', required: true },
30
+ from: { type: 'string', required: true },
31
+ destination: { type: 'string', required: false },
32
+ app: { type: 'object', required: false },
33
+ timeout: { type: 'number', required: false },
34
+ customHeaders: { type: 'object', required: false },
35
+ },
36
+ );
48
37
 
49
38
  const params = {
50
- body: callData,
39
+ body: {
40
+ to,
41
+ from,
42
+ destination,
43
+ app,
44
+ timeout,
45
+ customHeaders,
46
+ },
51
47
  };
52
48
 
53
- const result = await this.sdk._fetch('/voice/calls', 'POST', params);
49
+ const result = await this.sdk._fetch('/voice/', 'POST', params);
54
50
  return result;
55
51
  }
56
52
 
57
- async hangup(voiceChannelId) {
53
+ /**
54
+ * Replace the voice application on an active call
55
+ * Dynamically updates the voice app running on a call, allowing you to change the call flow in real-time.
56
+ * This can be used to play new audio, gather input, or execute any other voice commands while the call is active.
57
+ *
58
+ * @param {Object} options - Parameters
59
+ * @param {string} options.callId - The call ID to replace the app for (required)
60
+ * @param {Object} options.app - The voice app object containing commands to execute (required)
61
+ * @param {string} options.app.version - Voice app version (e.g., '2.0')
62
+ * @param {string} options.app.name - Voice app name identifier
63
+ * @param {Array} options.app.commands - Array of command objects to execute
64
+ * @returns {Promise<Object>} Object containing the operation status and metadata
65
+ * @returns {boolean} result.status - Whether the replacement was successful
66
+ * @returns {Object} result.meta - Metadata including the payload sent to media manager
67
+ *
68
+ * @example
69
+ * // Replace call app to play audio and hangup
70
+ * const result = await sdk.voice.replaceCallApp({
71
+ * callId: 'call123',
72
+ * app: {
73
+ * version: '2.0',
74
+ * name: 'dynamic-app',
75
+ * commands: [
76
+ * { command: 'play', file: 'example.wav' },
77
+ * { command: 'hangup' }
78
+ * ]
79
+ * }
80
+ * });
81
+ * console.log(result.status); // true
82
+ *
83
+ * @example
84
+ * // Replace call app to gather input
85
+ * const result = await sdk.voice.replaceCallApp({
86
+ * callId: 'call456',
87
+ * app: {
88
+ * version: '2.0',
89
+ * name: 'gather-app',
90
+ * commands: [
91
+ * { command: 'play', file: 'prompt.wav' },
92
+ * { command: 'gather', numDigits: 1, timeout: 5 }
93
+ * ]
94
+ * }
95
+ * });
96
+ */
97
+ async replaceCallApp({ callId, app }) {
58
98
  this.sdk.validateParams(
59
- { voiceChannelId },
99
+ { callId, app },
60
100
  {
61
- voiceChannelId: { type: 'string', required: true },
101
+ callId: { type: 'string', required: true },
102
+ app: { type: 'object', required: true },
62
103
  },
63
104
  );
64
105
 
65
- const result = await this.sdk._fetch(
66
- `/voice/calls/${voiceChannelId}`,
67
- 'DELETE',
106
+ const params = {
107
+ body: {
108
+ callId,
109
+ app,
110
+ },
111
+ };
112
+
113
+ const result = await this.sdk._fetch('/voice/replace', 'PUT', params);
114
+ return result;
115
+ }
116
+
117
+ /**
118
+ * HangUp active call
119
+ * Ends a currently active SIP phone call
120
+ *
121
+ * @param {string} callId - The call ID to hangup (required)
122
+ * @returns {Promise<Object>} Object containing the operation status and metadata
123
+ * @returns {boolean} result.status - Whether the replacement was successful
124
+ *
125
+ * @example
126
+ * // hangup call
127
+ * const result = await sdk.voice.hangup(callId);
128
+ * console.log(result.status); // true
129
+ *
130
+ */
131
+
132
+ async hangup(callId) {
133
+ this.sdk.validateParams(
134
+ { callId },
135
+ {
136
+ callId: { type: 'string', required: true },
137
+ },
68
138
  );
139
+ const params = {
140
+ body: {
141
+ callId,
142
+ },
143
+ };
144
+
145
+ const result = await this.sdk._fetch(`/voice/hangup`, 'PUT', params);
69
146
  return result;
70
147
  }
71
148
 
149
+ /* legacy methods, to be updated and replaced */
150
+
72
151
  async hold(channels) {
73
152
  this.sdk.validateParams(
74
153
  { channels },
@@ -132,28 +211,6 @@ export class VoiceService {
132
211
  return result;
133
212
  }
134
213
 
135
- async record(voiceChannelId, action = 'start', direction = 'both') {
136
- this.sdk.validateParams(
137
- { voiceChannelId },
138
- {
139
- voiceChannelId: { type: 'string', required: true },
140
- action: { type: 'string', required: false },
141
- direction: { type: 'string', required: false },
142
- },
143
- );
144
-
145
- const params = {
146
- body: { action, direction },
147
- };
148
-
149
- const result = await this.sdk._fetch(
150
- `/voice/calls/record/${voiceChannelId}`,
151
- 'POST',
152
- params,
153
- );
154
- return result;
155
- }
156
-
157
214
  async stopRecording(voiceChannelId, direction = 'both') {
158
215
  return this.record(voiceChannelId, 'stop', direction);
159
216
  }
@@ -21,6 +21,15 @@ export class WorkflowsService {
21
21
  const result = await this.sdk._fetch('/workflows/settings', 'GET', params);
22
22
  return result;
23
23
  }
24
+
25
+ async listModules() {
26
+ const params = {
27
+ query: {},
28
+ };
29
+
30
+ const result = await this.sdk._fetch('/workflows/modules', 'GET', params);
31
+ return result;
32
+ }
24
33
  }
25
34
 
26
35
  export class WorkflowItemsService {
@@ -288,12 +297,12 @@ export class WorkflowSessionsService {
288
297
  this.sdk = sdk;
289
298
  }
290
299
 
291
- async create(workflowId, sessionData) {
300
+ async create(workflowVersionId, sessionData) {
292
301
  this.sdk.validateParams(
293
- { workflowId, sessionData },
302
+ { workflowVersionId, sessionData },
294
303
  {
295
- workflowId: { type: 'string', required: true },
296
- sessionData: { type: 'object', required: true },
304
+ workflowVersionId: { type: 'string', required: true },
305
+ sessionData: { type: 'object', required: false },
297
306
  },
298
307
  );
299
308
 
@@ -302,7 +311,7 @@ export class WorkflowSessionsService {
302
311
  };
303
312
 
304
313
  const result = await this.sdk._fetch(
305
- `/workflows/${workflowId}/sessions`,
314
+ `/workflows/session/${workflowVersionId}`,
306
315
  'POST',
307
316
  params,
308
317
  );
@@ -329,7 +338,7 @@ export class WorkflowSessionsService {
329
338
  { sessionId, updateData },
330
339
  {
331
340
  sessionId: { type: 'string', required: true },
332
- updateData: { type: 'object', required: true },
341
+ updateData: { type: 'object', required: false },
333
342
  },
334
343
  );
335
344
 
@@ -338,7 +347,25 @@ export class WorkflowSessionsService {
338
347
  };
339
348
 
340
349
  const result = await this.sdk._fetch(
341
- `/workflows/sessions/${sessionId}`,
350
+ `/workflows/session/${sessionId}`,
351
+ 'PUT',
352
+ params,
353
+ );
354
+ return result;
355
+ }
356
+
357
+ async complete(sessionId) {
358
+ this.sdk.validateParams(
359
+ { sessionId },
360
+ {
361
+ sessionId: { type: 'string', required: true },
362
+ },
363
+ );
364
+
365
+ const params = {};
366
+
367
+ const result = await this.sdk._fetch(
368
+ `/workflows/session/${sessionId}/complete`,
342
369
  'PUT',
343
370
  params,
344
371
  );