@unboundcx/sdk 2.8.6 → 2.8.8

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,846 @@
1
+ export class TaskService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ /**
7
+ * Create a new task in the task router system
8
+ * Creates a task for routing to available workers based on skills and queue assignment.
9
+ * Tasks can be phone calls, chats, emails, or other custom types.
10
+ *
11
+ * @param {Object} options - Parameters
12
+ * @param {string} options.type - The type of task: 'chat', 'phoneCall', 'email', or 'other' (required)
13
+ * @param {string} options.queueId - The queue ID to route the task to (required)
14
+ * @param {string|string[]} [options.requiredSkills] - Required skill IDs that workers must have (single ID or array)
15
+ * @param {string|string[]} [options.optionalSkills] - Optional skill IDs that are preferred but not required (single ID or array)
16
+ * @param {string|string[]} [options.skills] - Alias for requiredSkills (single ID or array)
17
+ * @param {number} [options.priority=0] - Task priority (higher values = higher priority)
18
+ * @param {string} [options.subject] - Subject or title for the task (defaults to "New {type}" if not provided)
19
+ * @param {string} [options.cdrId] - Call detail record ID to associate with this task (for voice tasks)
20
+ * @param {string} [options.peopleId] - Person ID associated with this task
21
+ * @param {string} [options.companyId] - Company ID associated with this task
22
+ * @param {boolean} [options.createEngagement=false] - Whether to automatically create an engagement session for this task
23
+ * @param {string} [options.relatedObject] - Related object type for metadata tracking (automatically set if createEngagement is true)
24
+ * @param {string} [options.relatedId] - Related object ID for metadata tracking (automatically set if createEngagement is true)
25
+ * @returns {Promise<Object>} Object containing the created task information
26
+ * @returns {string} result.id - The unique identifier for the created task
27
+ *
28
+ * @example
29
+ * // Create a basic phone call task
30
+ * const task = await sdk.taskRouter.task.create({
31
+ * type: 'phoneCall',
32
+ * queueId: 'queue123'
33
+ * });
34
+ * console.log(task.id); // "task789"
35
+ *
36
+ * @example
37
+ * // Create a chat task with required skills
38
+ * const task = await sdk.taskRouter.task.create({
39
+ * type: 'chat',
40
+ * queueId: 'queue123',
41
+ * requiredSkills: ['skill456', 'skill789'],
42
+ * priority: 5,
43
+ * subject: 'Customer support inquiry'
44
+ * });
45
+ *
46
+ * @example
47
+ * // Create a voice task with CDR and auto-engagement
48
+ * const task = await sdk.taskRouter.task.create({
49
+ * type: 'phoneCall',
50
+ * queueId: 'queue123',
51
+ * cdrId: 'cdr456',
52
+ * peopleId: 'person789',
53
+ * companyId: 'company123',
54
+ * createEngagement: true,
55
+ * subject: 'Inbound sales call'
56
+ * });
57
+ *
58
+ * @example
59
+ * // Create an email task with metadata
60
+ * const task = await sdk.taskRouter.task.create({
61
+ * type: 'email',
62
+ * queueId: 'queue123',
63
+ * optionalSkills: 'skill999',
64
+ * relatedObject: 'supportTicket',
65
+ * relatedId: 'ticket123'
66
+ * });
67
+ */
68
+ async create(options = {}) {
69
+ const {
70
+ type,
71
+ queueId,
72
+ requiredSkills,
73
+ optionalSkills,
74
+ skills,
75
+ priority,
76
+ subject,
77
+ peopleId,
78
+ companyId,
79
+ createEngagement,
80
+ relatedObject,
81
+ relatedId,
82
+ cdrId,
83
+ sipCallId,
84
+ aiChatSessionId,
85
+ } = options;
86
+
87
+ this.sdk.validateParams(
88
+ {
89
+ type,
90
+ queueId,
91
+ requiredSkills,
92
+ optionalSkills,
93
+ skills,
94
+ priority,
95
+ subject,
96
+ cdrId,
97
+ peopleId,
98
+ companyId,
99
+ createEngagement,
100
+ relatedObject,
101
+ relatedId,
102
+ sipCallId,
103
+ aiChatSessionId,
104
+ },
105
+ {
106
+ type: { type: 'string', required: true },
107
+ queueId: { type: 'string', required: true },
108
+ // requiredSkills: { type: ['string', 'array'], required: false },
109
+ // optionalSkills: { type: ['string', 'array'], required: false },
110
+ // skills: { type: ['string', 'array'], required: false },
111
+ priority: { type: 'number', required: false },
112
+ subject: { type: 'string', required: false },
113
+ cdrId: { type: 'string', required: false },
114
+ peopleId: { type: 'string', required: false },
115
+ companyId: { type: 'string', required: false },
116
+ createEngagement: { type: 'boolean', required: false },
117
+ relatedObject: { type: 'string', required: false },
118
+ relatedId: { type: 'string', required: false },
119
+ sipCallId: { type: 'string', required: false },
120
+ aiChatSessionId: { type: 'string', required: false },
121
+ },
122
+ );
123
+
124
+ const params = {
125
+ body: {
126
+ type,
127
+ queueId,
128
+ },
129
+ };
130
+
131
+ if (requiredSkills !== undefined) {
132
+ params.body.requiredSkills = requiredSkills;
133
+ }
134
+
135
+ if (optionalSkills !== undefined) {
136
+ params.body.optionalSkills = optionalSkills;
137
+ }
138
+
139
+ if (skills !== undefined) {
140
+ params.body.skills = skills;
141
+ }
142
+
143
+ if (priority !== undefined) {
144
+ params.body.priority = priority;
145
+ }
146
+
147
+ if (subject !== undefined) {
148
+ params.body.subject = subject;
149
+ }
150
+
151
+ if (cdrId !== undefined) {
152
+ params.body.cdrId = cdrId;
153
+ }
154
+
155
+ if (peopleId !== undefined) {
156
+ params.body.peopleId = peopleId;
157
+ }
158
+
159
+ if (companyId !== undefined) {
160
+ params.body.companyId = companyId;
161
+ }
162
+
163
+ if (createEngagement !== undefined) {
164
+ params.body.createEngagement = createEngagement;
165
+ }
166
+
167
+ if (relatedObject !== undefined) {
168
+ params.body.relatedObject = relatedObject;
169
+ }
170
+
171
+ if (relatedId !== undefined) {
172
+ params.body.relatedId = relatedId;
173
+ }
174
+
175
+ if (sipCallId !== undefined) {
176
+ params.body.sipCallId = sipCallId;
177
+ }
178
+
179
+ if (aiChatSessionId !== undefined) {
180
+ params.body.aiChatSessionId = aiChatSessionId;
181
+ }
182
+
183
+ const result = await this.sdk._fetch('/taskRouter/tasks', 'POST', params);
184
+ return result;
185
+ }
186
+
187
+ /**
188
+ * Create a call to connect a user to a task
189
+ * Creates an outbound call to a user's extension to connect them with an active task.
190
+ * The task must have an associated CDR (call detail record) with a bridge ID.
191
+ * The task cannot be in 'completed' or 'wrapUp' status.
192
+ *
193
+ * @param {Object} options - Parameters
194
+ * @param {string} options.taskId - The task ID to create a call for (required)
195
+ * @param {string} [options.userId] - The user ID to call. If not provided, uses the authenticated user's ID
196
+ * @returns {Promise<Object>} Object containing the task, user, and bridge information
197
+ * @returns {string} result.taskId - The task ID that was connected
198
+ * @returns {string} result.userId - The user ID that was called
199
+ * @returns {string} result.bridgeId - The bridge ID used to connect the call
200
+ *
201
+ * @example
202
+ * // Create a call to connect authenticated user to a task
203
+ * const result = await sdk.taskRouter.task.createCall({
204
+ * taskId: 'task123'
205
+ * });
206
+ * console.log(result.taskId); // "task123"
207
+ * console.log(result.bridgeId); // "bridge456"
208
+ *
209
+ * @example
210
+ * // Create a call to connect specific user to a task
211
+ * const result = await sdk.taskRouter.task.createCall({
212
+ * taskId: 'task123',
213
+ * userId: 'user789'
214
+ * });
215
+ * console.log(result.userId); // "user789"
216
+ */
217
+ async createCall(options = {}) {
218
+ const { taskId, userId } = options;
219
+
220
+ this.sdk.validateParams(
221
+ { taskId, userId },
222
+ {
223
+ taskId: { type: 'string', required: true },
224
+ userId: { type: 'string', required: false },
225
+ },
226
+ );
227
+
228
+ const params = {
229
+ body: {
230
+ taskId,
231
+ },
232
+ };
233
+
234
+ if (userId !== undefined) {
235
+ params.body.userId = userId;
236
+ }
237
+
238
+ const result = await this.sdk._fetch(
239
+ '/taskRouter/tasks/callWorker',
240
+ 'PUT',
241
+ params,
242
+ );
243
+ return result;
244
+ }
245
+
246
+ /**
247
+ * Accept an assigned task
248
+ * When a worker accepts a task that has been assigned to them, this changes the task status to 'connected'.
249
+ * The worker must match the task assignment. If userId is not provided, uses the authenticated user's ID.
250
+ *
251
+ * @param {Object} options - Parameters
252
+ * @param {string} options.taskId - The task ID to accept (required)
253
+ * @param {string} [options.userId] - The user ID accepting the task. If not provided, uses the authenticated user's ID
254
+ * @returns {Promise<Object>} Object containing the task and worker information
255
+ * @returns {string} result.taskId - The task ID that was accepted
256
+ * @returns {string} result.workerId - The worker ID that accepted the task
257
+ * @returns {string} result.userId - The user ID that accepted the task
258
+ * @returns {string} result.workerSipCallId - The sipCallId of the worker who accepted the task
259
+ *
260
+ * @example
261
+ * // Accept a task as authenticated user
262
+ * const result = await sdk.taskRouter.task.accept({ taskId: 'task123' });
263
+ * console.log(result.taskId); // "task123"
264
+ * console.log(result.workerId); // "worker456"
265
+ *
266
+ * @example
267
+ * // Accept a task for specific user
268
+ * const result = await sdk.taskRouter.task.accept({
269
+ * taskId: 'task123',
270
+ * userId: 'user789'
271
+ * });
272
+ * @example
273
+ * // Accept a task for specific user with a sipCallId
274
+ * const result = await sdk.taskRouter.task.accept({
275
+ * taskId: 'task123',
276
+ * userId: 'user789'
277
+ * workerSipCallId: "a19ka-ada9a-adkadi198"
278
+ * });
279
+ */
280
+ async accept(options = {}) {
281
+ const { taskId, userId, workerId, workerSipCallId } = options;
282
+
283
+ this.sdk.validateParams(
284
+ { taskId, userId, workerSipCallId, workerId },
285
+ {
286
+ taskId: { type: 'string', required: true },
287
+ userId: { type: 'string', required: false },
288
+ workerSipCallId: { type: 'string', required: false },
289
+ workerId: { type: 'string', required: false },
290
+ },
291
+ );
292
+
293
+ const params = {
294
+ body: {
295
+ taskId,
296
+ },
297
+ };
298
+
299
+ if (userId) {
300
+ params.body.userId = userId;
301
+ }
302
+ if (workerId) {
303
+ params.body.workerId = workerId;
304
+ }
305
+ if (workerSipCallId) {
306
+ params.body.workerSipCallId = workerSipCallId;
307
+ }
308
+
309
+ const result = await this.sdk._fetch(
310
+ '/taskRouter/tasks/accept',
311
+ 'PUT',
312
+ params,
313
+ );
314
+ return result;
315
+ }
316
+
317
+ /**
318
+ * Reject an assigned task
319
+ * When a worker rejects a task that has been assigned to them, the task is returned to the queue for reassignment.
320
+ * The worker must match the task assignment. If userId is not provided, uses the authenticated user's ID.
321
+ *
322
+ * @param {Object} options - Parameters
323
+ * @param {string} options.taskId - The task ID to reject (required)
324
+ * @param {string} [options.userId] - The user ID rejecting the task. If not provided, uses the authenticated user's ID
325
+ * @returns {Promise<Object>} Object containing the task and worker information
326
+ * @returns {string} result.taskId - The task ID that was rejected
327
+ * @returns {string} result.workerId - The worker ID that rejected the task
328
+ * @returns {string} result.userId - The user ID that rejected the task
329
+ *
330
+ * @example
331
+ * // Reject a task as authenticated user
332
+ * const result = await sdk.taskRouter.task.reject({ taskId: 'task123' });
333
+ * console.log(result.taskId); // "task123"
334
+ *
335
+ * @example
336
+ * // Reject a task for specific user
337
+ * const result = await sdk.taskRouter.task.reject({
338
+ * taskId: 'task123',
339
+ * userId: 'user789'
340
+ * });
341
+ */
342
+ async reject(options = {}) {
343
+ const { taskId, userId } = options;
344
+
345
+ this.sdk.validateParams(
346
+ { taskId, userId },
347
+ {
348
+ taskId: { type: 'string', required: true },
349
+ userId: { type: 'string', required: false },
350
+ },
351
+ );
352
+
353
+ const params = {
354
+ body: {
355
+ taskId,
356
+ },
357
+ };
358
+
359
+ if (userId) {
360
+ params.body.userId = userId;
361
+ }
362
+
363
+ const result = await this.sdk._fetch(
364
+ '/taskRouter/tasks/reject',
365
+ 'PUT',
366
+ params,
367
+ );
368
+ return result;
369
+ }
370
+
371
+ /**
372
+ * Change task priority
373
+ * Modify the priority of a task to increase or decrease its routing priority.
374
+ * Priority can be set to a specific value, increased, or decreased.
375
+ *
376
+ * @param {Object} options - Parameters
377
+ * @param {string} options.taskId - The task ID to modify (required)
378
+ * @param {string} [options.action='set'] - The action to perform: 'set', 'increase', or 'decrease' (default: 'set')
379
+ * @param {number} [options.value=0] - The priority value to set, increase by, or decrease by (default: 0)
380
+ * @returns {Promise<Object>} Object containing the task ID and new priority
381
+ * @returns {string} result.taskId - The task ID that was modified
382
+ * @returns {number} result.priority - The new priority value (cannot be less than 0)
383
+ *
384
+ * @example
385
+ * // Set task priority to 10
386
+ * const result = await sdk.taskRouter.task.changePriority({
387
+ * taskId: 'task123',
388
+ * action: 'set',
389
+ * value: 10
390
+ * });
391
+ * console.log(result.priority); // 10
392
+ *
393
+ * @example
394
+ * // Increase task priority by 5
395
+ * const result = await sdk.taskRouter.task.changePriority({
396
+ * taskId: 'task123',
397
+ * action: 'increase',
398
+ * value: 5
399
+ * });
400
+ *
401
+ * @example
402
+ * // Decrease task priority by 3
403
+ * const result = await sdk.taskRouter.task.changePriority({
404
+ * taskId: 'task123',
405
+ * action: 'decrease',
406
+ * value: 3
407
+ * });
408
+ */
409
+ async changePriority(options = {}) {
410
+ const { taskId, action = 'set', value = 0 } = options;
411
+
412
+ this.sdk.validateParams(
413
+ { taskId, action, value },
414
+ {
415
+ taskId: { type: 'string', required: true },
416
+ action: { type: 'string', required: false },
417
+ value: { type: 'number', required: false },
418
+ },
419
+ );
420
+
421
+ const params = {
422
+ body: {
423
+ taskId,
424
+ action,
425
+ value,
426
+ },
427
+ };
428
+
429
+ const result = await this.sdk._fetch(
430
+ '/taskRouter/tasks/priority',
431
+ 'PUT',
432
+ params,
433
+ );
434
+ return result;
435
+ }
436
+
437
+ /**
438
+ * Toggle task hold status
439
+ * Place a connected task on hold or resume a held task.
440
+ * If the task is currently 'connected', it will be set to 'hold'.
441
+ * If the task is currently 'hold', it will be set back to 'connected'.
442
+ *
443
+ * @param {Object} options - Parameters
444
+ * @param {string} options.taskId - The task ID to hold/resume (required)
445
+ * @returns {Promise<Object>} Object containing the task ID and new status
446
+ * @returns {string} result.taskId - The task ID that was modified
447
+ * @returns {string} result.status - The new status ('hold' or 'connected')
448
+ *
449
+ * @example
450
+ * // Put a connected task on hold
451
+ * const result = await sdk.taskRouter.task.hold({ taskId: 'task123' });
452
+ * console.log(result.status); // "hold"
453
+ *
454
+ * @example
455
+ * // Resume a held task
456
+ * const result = await sdk.taskRouter.task.hold({ taskId: 'task123' });
457
+ * console.log(result.status); // "connected"
458
+ */
459
+ async hold(options = {}) {
460
+ const { taskId } = options;
461
+
462
+ this.sdk.validateParams(
463
+ { taskId },
464
+ {
465
+ taskId: { type: 'string', required: true },
466
+ },
467
+ );
468
+
469
+ const params = {
470
+ body: {
471
+ taskId,
472
+ },
473
+ };
474
+
475
+ const result = await this.sdk._fetch(
476
+ '/taskRouter/tasks/hold',
477
+ 'PUT',
478
+ params,
479
+ );
480
+ return result;
481
+ }
482
+
483
+ /**
484
+ * Update task skill requirements
485
+ * Add or remove required or optional skills from a task while it's pending, assigned, connected, or on hold.
486
+ * This allows dynamic modification of routing requirements based on task progression.
487
+ *
488
+ * @param {Object} options - Parameters
489
+ * @param {string} options.taskId - The task ID to modify (required)
490
+ * @param {string|string[]} options.skills - Skill ID or array of skill IDs to add/remove (required)
491
+ * @param {string} options.action - The action to perform: 'add' or 'remove' (required)
492
+ * @param {boolean} [options.required=false] - Whether to modify required skills (true) or optional skills (false). Default: false
493
+ * @returns {Promise<Object>} Object containing the task ID and update parameters
494
+ * @returns {string} result.taskId - The task ID that was modified
495
+ * @returns {Object} result.params - The update parameters that were applied
496
+ *
497
+ * @example
498
+ * // Add required skills to a task
499
+ * const result = await sdk.taskRouter.task.updateSkills({
500
+ * taskId: 'task123',
501
+ * skills: ['skill456', 'skill789'],
502
+ * action: 'add',
503
+ * required: true
504
+ * });
505
+ *
506
+ * @example
507
+ * // Remove optional skills from a task
508
+ * const result = await sdk.taskRouter.task.updateSkills({
509
+ * taskId: 'task123',
510
+ * skills: 'skill999',
511
+ * action: 'remove',
512
+ * required: false
513
+ * });
514
+ *
515
+ * @example
516
+ * // Add optional skills (default behavior)
517
+ * const result = await sdk.taskRouter.task.updateSkills({
518
+ * taskId: 'task123',
519
+ * skills: ['skill111'],
520
+ * action: 'add'
521
+ * });
522
+ */
523
+ async updateSkills(options = {}) {
524
+ const { taskId, skills, action, required = false } = options;
525
+
526
+ this.sdk.validateParams(
527
+ { taskId, skills, action, required },
528
+ {
529
+ taskId: { type: 'string', required: true },
530
+ skills: { type: ['string', 'array'], required: true },
531
+ action: { type: 'string', required: true },
532
+ required: { type: 'boolean', required: false },
533
+ },
534
+ );
535
+
536
+ const params = {
537
+ body: {
538
+ taskId,
539
+ skills,
540
+ action,
541
+ required,
542
+ },
543
+ };
544
+
545
+ const result = await this.sdk._fetch(
546
+ '/taskRouter/tasks/skills',
547
+ 'PUT',
548
+ params,
549
+ );
550
+ return result;
551
+ }
552
+
553
+ /**
554
+ * Move task to wrap-up status
555
+ * Transitions a connected or held task to 'wrapUp' status, indicating the worker is completing post-task activities.
556
+ * This status allows workers to complete notes, dispositions, or other follow-up work before completing the task.
557
+ *
558
+ * @param {Object} options - Parameters
559
+ * @param {string} options.taskId - The task ID to move to wrap-up (required)
560
+ * @returns {Promise<Object>} Object containing the task ID and new status
561
+ * @returns {string} result.taskId - The task ID that was modified
562
+ * @returns {string} result.status - The new status ('wrapUp')
563
+ *
564
+ * @example
565
+ * // Move a connected task to wrap-up
566
+ * const result = await sdk.taskRouter.task.wrapUp({ taskId: 'task123' });
567
+ * console.log(result.status); // "wrapUp"
568
+ *
569
+ * @example
570
+ * // Move a held task to wrap-up
571
+ * const result = await sdk.taskRouter.task.wrapUp({ taskId: 'task456' });
572
+ * console.log(result.taskId); // "task456"
573
+ */
574
+ async wrapUp(options = {}) {
575
+ const { taskId } = options;
576
+
577
+ this.sdk.validateParams(
578
+ { taskId },
579
+ {
580
+ taskId: { type: 'string', required: true },
581
+ },
582
+ );
583
+
584
+ const params = {
585
+ body: {
586
+ taskId,
587
+ },
588
+ };
589
+
590
+ const result = await this.sdk._fetch(
591
+ '/taskRouter/tasks/wrapUp',
592
+ 'PUT',
593
+ params,
594
+ );
595
+ return result;
596
+ }
597
+
598
+ /**
599
+ * Extend wrap-up time for a task
600
+ * Extends the wrap-up timer for a task that is currently in 'wrapUp' status.
601
+ * This gives the worker additional time to complete post-task activities before the task is automatically completed.
602
+ * If extend time is not provided, the queue's default wrapUpExtend value is used (typically 30 seconds).
603
+ *
604
+ * @param {Object} options - Parameters
605
+ * @param {string} options.taskId - The task ID to extend wrap-up time for (required)
606
+ * @param {number} [options.extend] - Number of seconds to extend the wrap-up timer. If not provided, uses the queue's default wrapUpExtend value (typically 30 seconds)
607
+ * @returns {Promise<Object>} Object containing the task ID and extend duration
608
+ * @returns {string} result.taskId - The task ID that was extended
609
+ * @returns {number} result.extend - The number of seconds the wrap-up was extended by
610
+ *
611
+ * @example
612
+ * // Extend wrap-up time by queue default (typically 30 seconds)
613
+ * const result = await sdk.taskRouter.task.wrapUpExtend({ taskId: 'task123' });
614
+ * console.log(result.extend); // 30
615
+ *
616
+ * @example
617
+ * // Extend wrap-up time by 60 seconds
618
+ * const result = await sdk.taskRouter.task.wrapUpExtend({
619
+ * taskId: 'task123',
620
+ * extend: 60
621
+ * });
622
+ * console.log(result.extend); // 60
623
+ *
624
+ * @example
625
+ * // Give worker more time to complete notes
626
+ * const result = await sdk.taskRouter.task.wrapUpExtend({
627
+ * taskId: 'task456',
628
+ * extend: 120
629
+ * });
630
+ * console.log(result.taskId); // "task456"
631
+ */
632
+ async wrapUpExtend(options = {}) {
633
+ const { taskId, extend } = options;
634
+
635
+ this.sdk.validateParams(
636
+ { taskId, extend },
637
+ {
638
+ taskId: { type: 'string', required: true },
639
+ extend: { type: 'number', required: false },
640
+ },
641
+ );
642
+
643
+ const params = {
644
+ body: {
645
+ taskId,
646
+ },
647
+ };
648
+
649
+ if (extend !== undefined) {
650
+ params.body.extend = extend;
651
+ }
652
+
653
+ const result = await this.sdk._fetch(
654
+ '/taskRouter/tasks/wrapUp/extend',
655
+ 'PUT',
656
+ params,
657
+ );
658
+ return result;
659
+ }
660
+
661
+ /**
662
+ * Complete a task
663
+ * Marks a task as completed, ending its lifecycle in the task router.
664
+ * Can be called from any status except 'completed'.
665
+ *
666
+ * @param {Object} options - Parameters
667
+ * @param {string} options.taskId - The task ID to complete (required)
668
+ * @returns {Promise<Object>} Object containing the task ID and new status
669
+ * @returns {string} result.taskId - The task ID that was completed
670
+ * @returns {string} result.status - The new status ('completed')
671
+ *
672
+ * @example
673
+ * // Complete a task in wrap-up status
674
+ * const result = await sdk.taskRouter.task.complete({ taskId: 'task123' });
675
+ * console.log(result.status); // "completed"
676
+ *
677
+ * @example
678
+ * // Complete a task directly from connected status
679
+ * const result = await sdk.taskRouter.task.complete({ taskId: 'task456' });
680
+ * console.log(result.taskId); // "task456"
681
+ */
682
+ async complete(options = {}) {
683
+ const { taskId } = options;
684
+
685
+ this.sdk.validateParams(
686
+ { taskId },
687
+ {
688
+ taskId: { type: 'string', required: true },
689
+ },
690
+ );
691
+
692
+ const params = {
693
+ body: {
694
+ taskId,
695
+ },
696
+ };
697
+
698
+ const result = await this.sdk._fetch(
699
+ '/taskRouter/tasks/complete',
700
+ 'PUT',
701
+ params,
702
+ );
703
+ return result;
704
+ }
705
+
706
+ /**
707
+ * Status Change task event
708
+ * Automated event anytime the status of a task is changed.
709
+ *
710
+ * @param {Object} options - Parameters
711
+ * @param {string} options.taskId - The task ID to complete (required)
712
+ * @param {string} options.status - The new status (required)
713
+ * @param {string} options.previousStatus - The previous status (required)
714
+ * @returns {Promise<Object>} Object containing the task ID and new status
715
+ * @returns {string} result.taskId - The task ID that was completed
716
+ *
717
+ * @example
718
+ * const result = await sdk.taskRouter.task.statusEvent({ taskId: 'task123', status: 'completed', previousStatus: 'wrapUp' });
719
+ * console.log(result.taskId); // "085000202601400010000345713108739"
720
+ *
721
+ */
722
+ async statusEvent(options = {}) {
723
+ const { taskId, status, previousStatus } = options;
724
+
725
+ this.sdk.validateParams(
726
+ { taskId, status, previousStatus },
727
+ {
728
+ taskId: { type: 'string', required: true },
729
+ status: { type: 'string', required: true },
730
+ previousStatus: { type: 'string', required: true },
731
+ },
732
+ );
733
+
734
+ const params = {
735
+ body: {
736
+ taskId,
737
+ status,
738
+ previousStatus,
739
+ },
740
+ };
741
+
742
+ const result = await this.sdk._fetch(
743
+ '/taskRouter/tasks/statusEvent',
744
+ 'PUT',
745
+ params,
746
+ );
747
+ return result;
748
+ }
749
+
750
+ /**
751
+ * Update task details
752
+ * Updates the subject, disposition, or other metadata of an existing task.
753
+ * This allows you to modify task information while it's in progress.
754
+ * At least one of subject or disposition must be provided.
755
+ *
756
+ * @param {Object} options - Parameters
757
+ * @param {string} options.taskId - The task ID to update (required)
758
+ * @param {string} [options.subject] - The new subject/title for the task
759
+ * @param {string} [options.summary] - The overall summary for the task
760
+ * @param {string} [options.disposition] - The disposition code or outcome for the task (e.g., 'resolved', 'escalated', 'callback-scheduled')
761
+ * @returns {Promise<Object>} Object containing the task ID
762
+ * @returns {string} result.taskId - The task ID that was updated
763
+ *
764
+ * @example
765
+ * // Update task subject
766
+ * const result = await sdk.taskRouter.task.update({
767
+ * taskId: 'task123',
768
+ * subject: 'Updated customer inquiry about billing'
769
+ * });
770
+ * console.log(result.taskId); // "task123"
771
+ *
772
+ * @example
773
+ * // Update task disposition
774
+ * const result = await sdk.taskRouter.task.update({
775
+ * taskId: 'task456',
776
+ * disposition: 'resolved'
777
+ * });
778
+ * console.log(result.taskId); // "task456"
779
+ *
780
+ * @example
781
+ * // Update both subject and disposition
782
+ * const result = await sdk.taskRouter.task.update({
783
+ * taskId: 'task789',
784
+ * subject: 'Technical support - printer issue',
785
+ * disposition: 'escalated'
786
+ * });
787
+ * console.log(result.taskId); // "task789"
788
+ */
789
+ async update(options = {}) {
790
+ const {
791
+ taskId,
792
+ subject,
793
+ disposition,
794
+ sipCallId,
795
+ cdrId,
796
+ summary,
797
+ sentiment,
798
+ } = options;
799
+
800
+ this.sdk.validateParams(
801
+ { taskId, subject, disposition, sipCallId, cdrId, summary, sentiment },
802
+ {
803
+ taskId: { type: 'string', required: true },
804
+ subject: { type: 'string', required: false },
805
+ disposition: { type: 'string', required: false },
806
+ cdrId: { type: 'string', required: false },
807
+ sipCallId: { type: 'string', required: false },
808
+ summary: { type: 'string', required: false },
809
+ sentiment: { type: 'object', required: false },
810
+ },
811
+ );
812
+
813
+ const params = {
814
+ body: {
815
+ taskId,
816
+ },
817
+ };
818
+
819
+ if (subject !== undefined) {
820
+ params.body.subject = subject;
821
+ }
822
+
823
+ if (summary !== undefined) {
824
+ params.body.summary = summary;
825
+ }
826
+
827
+ if (disposition !== undefined) {
828
+ params.body.disposition = disposition;
829
+ }
830
+
831
+ if (cdrId !== undefined) {
832
+ params.body.cdrId = cdrId;
833
+ }
834
+
835
+ if (sipCallId !== undefined) {
836
+ params.body.sipCallId = sipCallId;
837
+ }
838
+
839
+ if (sentiment !== undefined) {
840
+ params.body.sentiment = sentiment;
841
+ }
842
+
843
+ const result = await this.sdk._fetch('/taskRouter/tasks/', 'PUT', params);
844
+ return result;
845
+ }
846
+ }