@unboundcx/sdk 4.13.141 → 4.13.142
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 +6 -0
- package/package.json +1 -1
- package/services/taskRouter/TaskService.js +25 -8
- package/services/voice.js +34 -0
- package/services/voicemailDrops.js +231 -0
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.
|
|
3
|
+
"version": "4.13.142",
|
|
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
|
|
769
|
-
|
|
770
|
-
|
|
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
|
|
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,231 @@
|
|
|
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
|
+
* @returns {Promise<{results: Object[]}>}
|
|
16
|
+
*/
|
|
17
|
+
async list() {
|
|
18
|
+
return internalRequest(this.sdk, '/voicemailDrops/types', 'GET');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a voicemail drop type.
|
|
23
|
+
* @param {Object} options
|
|
24
|
+
* @param {string} options.name
|
|
25
|
+
* @param {string} [options.description]
|
|
26
|
+
* @param {boolean} [options.active]
|
|
27
|
+
* @returns {Promise<Object>}
|
|
28
|
+
*/
|
|
29
|
+
async create(options = {}) {
|
|
30
|
+
this.sdk.validateParams(
|
|
31
|
+
{ name: options.name },
|
|
32
|
+
{ name: { type: 'string', required: true } },
|
|
33
|
+
);
|
|
34
|
+
return internalRequest(this.sdk, '/voicemailDrops/types', 'POST', {
|
|
35
|
+
body: { ...options },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Update a voicemail drop type.
|
|
41
|
+
* @param {string} id
|
|
42
|
+
* @param {Object} options
|
|
43
|
+
* @returns {Promise<Object>}
|
|
44
|
+
*/
|
|
45
|
+
async update(id, options = {}) {
|
|
46
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
47
|
+
return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'PUT', {
|
|
48
|
+
body: { ...options },
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Remove (soft-delete) a voicemail drop type.
|
|
54
|
+
* @param {string} id
|
|
55
|
+
* @returns {Promise<{id: string, deleted: boolean}>}
|
|
56
|
+
*/
|
|
57
|
+
async remove(id) {
|
|
58
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
59
|
+
return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'DELETE');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Build a multipart body for a single audio file + scalar fields. Mirrors
|
|
64
|
+
// storage.js's node/browser FormData construction so this works in both
|
|
65
|
+
// environments without depending on StorageService internals.
|
|
66
|
+
function buildMultipart(file, fields) {
|
|
67
|
+
const isNode = typeof window === 'undefined';
|
|
68
|
+
|
|
69
|
+
if (!isNode) {
|
|
70
|
+
const formData = new FormData();
|
|
71
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(file)) {
|
|
72
|
+
formData.append('file', new Blob([file]), fields.fileName || 'file');
|
|
73
|
+
} else if (typeof File !== 'undefined' && file instanceof File) {
|
|
74
|
+
formData.append('file', file);
|
|
75
|
+
} else {
|
|
76
|
+
throw new Error('In browser environment, file must be a Buffer or File object');
|
|
77
|
+
}
|
|
78
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
79
|
+
if (value === undefined || value === null) continue;
|
|
80
|
+
formData.append(name, typeof value === 'object' ? JSON.stringify(value) : String(value));
|
|
81
|
+
}
|
|
82
|
+
return { body: formData, headers: {} };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Node: build the multipart buffer by hand.
|
|
86
|
+
const boundary = `----formdata-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
87
|
+
const CRLF = '\r\n';
|
|
88
|
+
const fileName = fields.fileName || 'file';
|
|
89
|
+
const parts = [];
|
|
90
|
+
|
|
91
|
+
parts.push(Buffer.from(
|
|
92
|
+
`--${boundary}${CRLF}Content-Disposition: form-data; name="file"; filename="${fileName}"${CRLF}` +
|
|
93
|
+
`Content-Type: application/octet-stream${CRLF}${CRLF}`,
|
|
94
|
+
'utf8',
|
|
95
|
+
));
|
|
96
|
+
parts.push(Buffer.isBuffer(file) ? file : Buffer.from(file));
|
|
97
|
+
parts.push(Buffer.from(CRLF, 'utf8'));
|
|
98
|
+
|
|
99
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
100
|
+
if (value === undefined || value === null) continue;
|
|
101
|
+
const v = typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
102
|
+
parts.push(Buffer.from(
|
|
103
|
+
`--${boundary}${CRLF}Content-Disposition: form-data; name="${name}"${CRLF}${CRLF}${v}${CRLF}`,
|
|
104
|
+
'utf8',
|
|
105
|
+
));
|
|
106
|
+
}
|
|
107
|
+
parts.push(Buffer.from(`--${boundary}--${CRLF}`, 'utf8'));
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
body: Buffer.concat(parts),
|
|
111
|
+
headers: { 'content-type': `multipart/form-data; boundary=${boundary}` },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Per-user voicemail drop messages (voicemail-drop-plan.md §5, §6). A
|
|
117
|
+
* message is either an uploaded/recorded file or TTS-generated, scoped to a
|
|
118
|
+
* type (or personal/untyped), with one default per type.
|
|
119
|
+
*/
|
|
120
|
+
export class VoicemailDropsService {
|
|
121
|
+
constructor(sdk) {
|
|
122
|
+
this.sdk = sdk;
|
|
123
|
+
this.types = new VoicemailDropTypesService(sdk);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* List the current user's own voicemail drop messages plus all active
|
|
128
|
+
* types, with `hasMessage` flagged per type.
|
|
129
|
+
* @returns {Promise<{messages: Object[], types: Object[]}>}
|
|
130
|
+
*/
|
|
131
|
+
async listMine() {
|
|
132
|
+
return internalRequest(this.sdk, '/voicemailDrops/mine', 'GET');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Create a voicemail drop message — either an uploaded/recorded audio
|
|
137
|
+
* file (multipart, works in browser and Node) or a TTS message (plain
|
|
138
|
+
* JSON, no file needed).
|
|
139
|
+
* @param {Object} options
|
|
140
|
+
* @param {Object} [options.file] - Buffer or browser File; omit for TTS
|
|
141
|
+
* @param {string} options.name
|
|
142
|
+
* @param {string} [options.typeId]
|
|
143
|
+
* @param {string} [options.ttsText]
|
|
144
|
+
* @param {string} [options.ttsVoice]
|
|
145
|
+
* @param {boolean} [options.isDefault]
|
|
146
|
+
* @returns {Promise<Object>} the created row (status 'processing' until transcode completes)
|
|
147
|
+
*/
|
|
148
|
+
async create({ file, name, typeId, ttsText, ttsVoice, isDefault, fileName } = {}) {
|
|
149
|
+
this.sdk.validateParams(
|
|
150
|
+
{ name, typeId, ttsText, ttsVoice, isDefault, fileName },
|
|
151
|
+
{
|
|
152
|
+
name: { type: 'string', required: true },
|
|
153
|
+
typeId: { type: 'string', required: false },
|
|
154
|
+
ttsText: { type: 'string', required: false },
|
|
155
|
+
ttsVoice: { type: 'string', required: false },
|
|
156
|
+
isDefault: { type: 'boolean', required: false },
|
|
157
|
+
fileName: { type: 'string', required: false },
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (!file && !ttsText) {
|
|
162
|
+
throw new Error('create requires either file or ttsText');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (file) {
|
|
166
|
+
const { body, headers } = buildMultipart(file, {
|
|
167
|
+
fileName,
|
|
168
|
+
name,
|
|
169
|
+
typeId,
|
|
170
|
+
isDefault,
|
|
171
|
+
});
|
|
172
|
+
return internalRequest(
|
|
173
|
+
this.sdk,
|
|
174
|
+
'/voicemailDrops',
|
|
175
|
+
'POST',
|
|
176
|
+
{ body, headers },
|
|
177
|
+
true,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return internalRequest(this.sdk, '/voicemailDrops', 'POST', {
|
|
182
|
+
body: { name, typeId, ttsText, ttsVoice, isDefault },
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Update a voicemail drop message (rename, change type, set default).
|
|
188
|
+
* @param {string} id
|
|
189
|
+
* @param {Object} options
|
|
190
|
+
* @returns {Promise<Object>}
|
|
191
|
+
*/
|
|
192
|
+
async update(id, options = {}) {
|
|
193
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
194
|
+
return internalRequest(this.sdk, `/voicemailDrops/${id}`, 'PUT', {
|
|
195
|
+
body: { ...options },
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Remove (soft-delete) a voicemail drop message.
|
|
201
|
+
* @param {string} id
|
|
202
|
+
* @returns {Promise<{id: string, deleted: boolean}>}
|
|
203
|
+
*/
|
|
204
|
+
async remove(id) {
|
|
205
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
206
|
+
return internalRequest(this.sdk, `/voicemailDrops/${id}`, 'DELETE');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Get a short-lived signed preview URL for a message's audio.
|
|
211
|
+
* @param {string} id
|
|
212
|
+
* @returns {Promise<{url: string}>}
|
|
213
|
+
*/
|
|
214
|
+
async preview(id) {
|
|
215
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
216
|
+
return internalRequest(this.sdk, `/voicemailDrops/${id}/preview`, 'POST');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Admin: a user's message coverage per type.
|
|
221
|
+
* @param {string} userId
|
|
222
|
+
* @returns {Promise<{messages: Object[], types: Object[]}>}
|
|
223
|
+
*/
|
|
224
|
+
async forUser(userId) {
|
|
225
|
+
this.sdk.validateParams(
|
|
226
|
+
{ userId },
|
|
227
|
+
{ userId: { type: 'string', required: true } },
|
|
228
|
+
);
|
|
229
|
+
return internalRequest(this.sdk, `/voicemailDrops/users/${userId}`, 'GET');
|
|
230
|
+
}
|
|
231
|
+
}
|