@unboundcx/sdk 4.13.141 → 4.13.143

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/index.js CHANGED
@@ -60,6 +60,7 @@ import {
60
60
  DataImportService,
61
61
  DataExportService,
62
62
  } from './services/dataImport.js';
63
+ import { VoicemailDropsService } from './services/voicemailDrops.js';
63
64
 
64
65
  class UnboundSDK extends BaseSDK {
65
66
  constructor(options = {}) {
@@ -166,6 +167,7 @@ class UnboundSDK extends BaseSDK {
166
167
  this.developerApis = new DeveloperApisService(this);
167
168
  this.dataImport = new DataImportService(this);
168
169
  this.dataExport = new DataExportService(this);
170
+ this.voicemailDrops = new VoicemailDropsService(this);
169
171
 
170
172
  // Add additional services that might be missing
171
173
  this._initializeAdditionalServices();
@@ -387,5 +389,9 @@ export {
387
389
  DataImportService,
388
390
  DataExportService,
389
391
  } from './services/dataImport.js';
392
+ export {
393
+ VoicemailDropsService,
394
+ VoicemailDropTypesService,
395
+ } from './services/voicemailDrops.js';
390
396
  export { BaseSDK } from './base.js';
391
397
  export { layoutJourney, MAX_LANES as JOURNEY_LAYOUT_MAX_LANES } from './lib/journeyLayout.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.141",
3
+ "version": "4.13.143",
4
4
  "description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -741,6 +741,10 @@ export class TaskService {
741
741
  *
742
742
  * @param {Object} options - Parameters
743
743
  * @param {string} options.taskId - The task ID to move to wrap-up (required)
744
+ * @param {boolean} [options.skipSipHangup] - Skip hanging up the worker's SIP leg (e.g. a voicemail
745
+ * drop already released the leg; see voicemail-drop-plan.md §4.2.4)
746
+ * @param {string} [options.dispositionId] - Disposition to pre-fill/stamp for this wrap-up
747
+ * @param {Object} [options.metadata] - Extra context to carry into wrap-up (e.g. voicemail drop id/duration)
744
748
  * @returns {Promise<Object>} Object containing the task ID and new status
745
749
  * @returns {string} result.taskId - The task ID that was modified
746
750
  * @returns {string} result.status - The new status ('wrapUp')
@@ -754,24 +758,37 @@ export class TaskService {
754
758
  * // Move a held task to wrap-up
755
759
  * const result = await sdk.taskRouter.task.wrapUp({ taskId: 'task456' });
756
760
  * console.log(result.taskId); // "task456"
761
+ *
762
+ * @example
763
+ * // Voicemail drop: leg already released, pre-fill disposition
764
+ * const result = await sdk.taskRouter.task.wrapUp({
765
+ * taskId: 'task789',
766
+ * skipSipHangup: true,
767
+ * dispositionId: 'disp_leftVoicemail',
768
+ * metadata: { voicemailDropId: 'vmd_123', durationMs: 23000 },
769
+ * });
757
770
  */
758
771
  async wrapUp(options = {}) {
759
- const { taskId } = options;
772
+ const { taskId, skipSipHangup, dispositionId, metadata } = options;
760
773
 
761
774
  this.sdk.validateParams(
762
- { taskId },
775
+ { taskId, skipSipHangup, dispositionId, metadata },
763
776
  {
764
777
  taskId: { type: 'string', required: true },
778
+ skipSipHangup: { type: 'boolean', required: false },
779
+ dispositionId: { type: 'string', required: false },
780
+ metadata: { type: 'object', required: false },
765
781
  },
766
782
  );
767
783
 
768
- const params = {
769
- body: {
770
- taskId,
771
- },
772
- };
784
+ const body = { taskId };
785
+ if (skipSipHangup !== undefined) body.skipSipHangup = skipSipHangup;
786
+ if (dispositionId !== undefined) body.dispositionId = dispositionId;
787
+ if (metadata !== undefined) body.metadata = metadata;
773
788
 
774
- const result = await internalRequest(this.sdk,
789
+ const params = { body };
790
+
791
+ const result = await internalRequest(this.sdk,
775
792
  '/taskRouter/tasks/wrapUp',
776
793
  'PUT',
777
794
  params,
package/services/voice.js CHANGED
@@ -380,6 +380,40 @@ export class VoiceService {
380
380
  return result;
381
381
  }
382
382
 
383
+ /**
384
+ * Drop a pre-recorded/TTS voicemail message on an active outbound call and
385
+ * release the leg immediately (voicemail-drop-plan.md §4.2, §5).
386
+ *
387
+ * @param {Object} options
388
+ * @param {string} options.callId - The call ID to drop the message on (required)
389
+ * @param {string} options.dropId - The voicemail drop message id to play (required)
390
+ * @returns {Promise<Object>} result.status
391
+ *
392
+ * @example
393
+ * const result = await sdk.voice.voicemailDrop({ callId: 'call123', dropId: 'vmd_456' });
394
+ */
395
+ async voicemailDrop({ callId, dropId }) {
396
+ this.sdk.validateParams(
397
+ { callId, dropId },
398
+ {
399
+ callId: { type: 'string', required: true },
400
+ dropId: { type: 'string', required: true },
401
+ },
402
+ );
403
+
404
+ const params = {
405
+ body: { dropId },
406
+ };
407
+
408
+ const result = await internalRequest(
409
+ this.sdk,
410
+ `/voice/calls/${callId}/voicemailDrop`,
411
+ 'PUT',
412
+ params,
413
+ );
414
+ return result;
415
+ }
416
+
383
417
  async conference(channels) {
384
418
  this.sdk.validateParams(
385
419
  { channels },
@@ -0,0 +1,268 @@
1
+ import { internalRequest } from '../base.js';
2
+
3
+ /**
4
+ * Admin-managed voicemail drop types (voicemail-drop-plan.md §5). A type is
5
+ * the category a message belongs to (e.g. "Not home", "Left message");
6
+ * queues/journeys preselect by type.
7
+ */
8
+ export class VoicemailDropTypesService {
9
+ constructor(sdk) {
10
+ this.sdk = sdk;
11
+ }
12
+
13
+ /**
14
+ * List voicemail drop types.
15
+ * @param {Object} [params]
16
+ * @param {boolean} [params.includeInactive]
17
+ * @returns {Promise<{results: Object[]}>}
18
+ */
19
+ async list(params = {}) {
20
+ return internalRequest(this.sdk, '/voicemailDrops/types', 'GET', { query: { ...params } });
21
+ }
22
+
23
+ /**
24
+ * Get a single voicemail drop type.
25
+ * @param {string} id
26
+ * @returns {Promise<Object>}
27
+ */
28
+ async get(id) {
29
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
30
+ return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'GET');
31
+ }
32
+
33
+ /**
34
+ * Create a voicemail drop type.
35
+ * @param {Object} options
36
+ * @param {string} options.name
37
+ * @param {string} [options.description]
38
+ * @param {boolean} [options.active]
39
+ * @returns {Promise<Object>}
40
+ */
41
+ async create(options = {}) {
42
+ this.sdk.validateParams(
43
+ { name: options.name },
44
+ { name: { type: 'string', required: true } },
45
+ );
46
+ return internalRequest(this.sdk, '/voicemailDrops/types', 'POST', {
47
+ body: { ...options },
48
+ });
49
+ }
50
+
51
+ /**
52
+ * Update a voicemail drop type.
53
+ * @param {string} id
54
+ * @param {Object} options
55
+ * @returns {Promise<Object>}
56
+ */
57
+ async update(id, options = {}) {
58
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
59
+ return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'PUT', {
60
+ body: { ...options },
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Remove (soft-delete) a voicemail drop type.
66
+ * @param {string} id
67
+ * @returns {Promise<{id: string, deleted: boolean}>}
68
+ */
69
+ async remove(id) {
70
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
71
+ return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'DELETE');
72
+ }
73
+
74
+ /**
75
+ * Set which users/groups can see a voicemail drop type.
76
+ * @param {string} id
77
+ * @param {Object} options
78
+ * @param {string[]} [options.userIds]
79
+ * @param {string[]} [options.groupIds]
80
+ * @returns {Promise<Object>}
81
+ */
82
+ async setAccess(id, { userIds, groupIds } = {}) {
83
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
84
+ return internalRequest(this.sdk, `/voicemailDrops/types/${id}/access`, 'PUT', {
85
+ body: { userIds, groupIds },
86
+ });
87
+ }
88
+
89
+ /**
90
+ * List users who have recorded a voicemail drop message for this type.
91
+ * @param {string} id
92
+ * @returns {Promise<{results: Object[]}>}
93
+ */
94
+ async recordings(id) {
95
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
96
+ return internalRequest(this.sdk, `/voicemailDrops/types/${id}/recordings`, 'GET');
97
+ }
98
+ }
99
+
100
+ // Build a multipart body for a single audio file + scalar fields. Mirrors
101
+ // storage.js's node/browser FormData construction so this works in both
102
+ // environments without depending on StorageService internals.
103
+ function buildMultipart(file, fields) {
104
+ const isNode = typeof window === 'undefined';
105
+
106
+ if (!isNode) {
107
+ const formData = new FormData();
108
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(file)) {
109
+ formData.append('file', new Blob([file]), fields.fileName || 'file');
110
+ } else if (typeof File !== 'undefined' && file instanceof File) {
111
+ formData.append('file', file);
112
+ } else {
113
+ throw new Error('In browser environment, file must be a Buffer or File object');
114
+ }
115
+ for (const [name, value] of Object.entries(fields)) {
116
+ if (value === undefined || value === null) continue;
117
+ formData.append(name, typeof value === 'object' ? JSON.stringify(value) : String(value));
118
+ }
119
+ return { body: formData, headers: {} };
120
+ }
121
+
122
+ // Node: build the multipart buffer by hand.
123
+ const boundary = `----formdata-${Date.now()}-${Math.random().toString(36).slice(2)}`;
124
+ const CRLF = '\r\n';
125
+ const fileName = fields.fileName || 'file';
126
+ const parts = [];
127
+
128
+ parts.push(Buffer.from(
129
+ `--${boundary}${CRLF}Content-Disposition: form-data; name="file"; filename="${fileName}"${CRLF}` +
130
+ `Content-Type: application/octet-stream${CRLF}${CRLF}`,
131
+ 'utf8',
132
+ ));
133
+ parts.push(Buffer.isBuffer(file) ? file : Buffer.from(file));
134
+ parts.push(Buffer.from(CRLF, 'utf8'));
135
+
136
+ for (const [name, value] of Object.entries(fields)) {
137
+ if (value === undefined || value === null) continue;
138
+ const v = typeof value === 'object' ? JSON.stringify(value) : String(value);
139
+ parts.push(Buffer.from(
140
+ `--${boundary}${CRLF}Content-Disposition: form-data; name="${name}"${CRLF}${CRLF}${v}${CRLF}`,
141
+ 'utf8',
142
+ ));
143
+ }
144
+ parts.push(Buffer.from(`--${boundary}--${CRLF}`, 'utf8'));
145
+
146
+ return {
147
+ body: Buffer.concat(parts),
148
+ headers: { 'content-type': `multipart/form-data; boundary=${boundary}` },
149
+ };
150
+ }
151
+
152
+ /**
153
+ * Per-user voicemail drop messages (voicemail-drop-plan.md §5, §6). A
154
+ * message is either an uploaded/recorded file or TTS-generated, scoped to a
155
+ * type (or personal/untyped), with one default per type.
156
+ */
157
+ export class VoicemailDropsService {
158
+ constructor(sdk) {
159
+ this.sdk = sdk;
160
+ this.types = new VoicemailDropTypesService(sdk);
161
+ }
162
+
163
+ /**
164
+ * List the current user's own voicemail drop messages plus all active
165
+ * types, with `hasMessage` flagged per type.
166
+ * @returns {Promise<{messages: Object[], types: Object[]}>}
167
+ */
168
+ async listMine() {
169
+ return internalRequest(this.sdk, '/voicemailDrops/mine', 'GET');
170
+ }
171
+
172
+ /**
173
+ * Create a voicemail drop message — either an uploaded/recorded audio
174
+ * file (multipart, works in browser and Node) or a TTS message (plain
175
+ * JSON, no file needed).
176
+ * @param {Object} options
177
+ * @param {Object} [options.file] - Buffer or browser File; omit for TTS
178
+ * @param {string} options.name
179
+ * @param {string} [options.typeId]
180
+ * @param {string} [options.ttsText]
181
+ * @param {string} [options.ttsVoice]
182
+ * @param {boolean} [options.isDefault]
183
+ * @returns {Promise<Object>} the created row (status 'processing' until transcode completes)
184
+ */
185
+ async create({ file, name, typeId, ttsText, ttsVoice, isDefault, fileName } = {}) {
186
+ this.sdk.validateParams(
187
+ { name, typeId, ttsText, ttsVoice, isDefault, fileName },
188
+ {
189
+ name: { type: 'string', required: true },
190
+ typeId: { type: 'string', required: false },
191
+ ttsText: { type: 'string', required: false },
192
+ ttsVoice: { type: 'string', required: false },
193
+ isDefault: { type: 'boolean', required: false },
194
+ fileName: { type: 'string', required: false },
195
+ },
196
+ );
197
+
198
+ if (!file && !ttsText) {
199
+ throw new Error('create requires either file or ttsText');
200
+ }
201
+
202
+ if (file) {
203
+ const { body, headers } = buildMultipart(file, {
204
+ fileName,
205
+ name,
206
+ typeId,
207
+ isDefault,
208
+ });
209
+ return internalRequest(
210
+ this.sdk,
211
+ '/voicemailDrops',
212
+ 'POST',
213
+ { body, headers },
214
+ true,
215
+ );
216
+ }
217
+
218
+ return internalRequest(this.sdk, '/voicemailDrops', 'POST', {
219
+ body: { name, typeId, ttsText, ttsVoice, isDefault },
220
+ });
221
+ }
222
+
223
+ /**
224
+ * Update a voicemail drop message (rename, change type, set default).
225
+ * @param {string} id
226
+ * @param {Object} options
227
+ * @returns {Promise<Object>}
228
+ */
229
+ async update(id, options = {}) {
230
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
231
+ return internalRequest(this.sdk, `/voicemailDrops/${id}`, 'PUT', {
232
+ body: { ...options },
233
+ });
234
+ }
235
+
236
+ /**
237
+ * Remove (soft-delete) a voicemail drop message.
238
+ * @param {string} id
239
+ * @returns {Promise<{id: string, deleted: boolean}>}
240
+ */
241
+ async remove(id) {
242
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
243
+ return internalRequest(this.sdk, `/voicemailDrops/${id}`, 'DELETE');
244
+ }
245
+
246
+ /**
247
+ * Get a short-lived signed preview URL for a message's audio.
248
+ * @param {string} id
249
+ * @returns {Promise<{url: string}>}
250
+ */
251
+ async preview(id) {
252
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
253
+ return internalRequest(this.sdk, `/voicemailDrops/${id}/preview`, 'POST');
254
+ }
255
+
256
+ /**
257
+ * Admin: a user's message coverage per type.
258
+ * @param {string} userId
259
+ * @returns {Promise<{messages: Object[], types: Object[]}>}
260
+ */
261
+ async forUser(userId) {
262
+ this.sdk.validateParams(
263
+ { userId },
264
+ { userId: { type: 'string', required: true } },
265
+ );
266
+ return internalRequest(this.sdk, `/voicemailDrops/users/${userId}`, 'GET');
267
+ }
268
+ }