@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/README.md +48 -1
- package/base.js +43 -12
- package/index.js +21 -3
- package/package.json +5 -2
- package/proto/transcription.proto +207 -0
- package/services/ai/SttStream.js +311 -0
- package/services/ai/playbooks.js +958 -0
- package/services/ai.js +773 -52
- package/services/engagementMetrics.js +6 -2
- package/services/objects.js +12 -3
- package/services/phoneNumbers.js +88 -3
- package/services/sipEndpoints.js +105 -33
- package/services/storage.js +176 -6
- package/services/taskRouter/MetricsService.js +111 -0
- package/services/taskRouter/TaskRouterService.js +12 -0
- package/services/taskRouter/TaskService.js +838 -0
- package/services/taskRouter/WorkerService.js +394 -0
- package/services/taskRouter.js +6 -0
- package/services/video.js +145 -5
- package/services/voice.js +124 -67
- package/services/workflows.js +34 -7
|
@@ -0,0 +1,958 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playbooks Service - Manage AI-driven playbook sessions for guided workflows
|
|
3
|
+
*/
|
|
4
|
+
export class PlaybooksService {
|
|
5
|
+
constructor(sdk) {
|
|
6
|
+
this.sdk = sdk;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// ========================================
|
|
10
|
+
// Playbook CRUD Methods
|
|
11
|
+
// ========================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a new playbook
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} options - Playbook creation options
|
|
17
|
+
* @param {string} options.name - Name of the playbook
|
|
18
|
+
* @param {string} [options.recordTypeId] - Record type ID for tracking
|
|
19
|
+
* @returns {Promise<Object>} Created playbook with id
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const playbook = await sdk.ai.playbooks.createPlaybook({
|
|
23
|
+
* name: 'Sales Discovery Call'
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
async createPlaybook({ name, recordTypeId }) {
|
|
27
|
+
this.sdk.validateParams(
|
|
28
|
+
{ name },
|
|
29
|
+
{
|
|
30
|
+
name: { type: 'string', required: true },
|
|
31
|
+
recordTypeId: { type: 'string', required: false },
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const params = {
|
|
36
|
+
body: { name, recordTypeId },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const result = await this.sdk._fetch('/ai/playbooks', 'POST', params);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get a playbook by ID
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} options - Options
|
|
47
|
+
* @param {string} options.playbookId - The ID of the playbook
|
|
48
|
+
* @returns {Promise<Object>} Playbook object with goals
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const playbook = await sdk.ai.playbooks.getPlaybook({
|
|
52
|
+
* playbookId: 'pb_123456'
|
|
53
|
+
* });
|
|
54
|
+
*/
|
|
55
|
+
async getPlaybook({ playbookId }) {
|
|
56
|
+
this.sdk.validateParams(
|
|
57
|
+
{ playbookId },
|
|
58
|
+
{
|
|
59
|
+
playbookId: { type: 'string', required: true },
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const result = await this.sdk._fetch(`/ai/playbooks/${playbookId}`, 'GET');
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* List playbooks
|
|
69
|
+
*
|
|
70
|
+
* @param {Object} [options={}] - Query options
|
|
71
|
+
* @param {number} [options.limit=100] - Maximum number of results
|
|
72
|
+
* @param {string} [options.orderBy='createdAt'] - Field to order by
|
|
73
|
+
* @param {string} [options.orderDirection='DESC'] - Order direction
|
|
74
|
+
* @param {boolean} [options.isPublished] - Filter by published status
|
|
75
|
+
* @param {string} [options.recordTypeId] - Filter by record type
|
|
76
|
+
* @returns {Promise<Object>} Object with results array
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* const playbooks = await sdk.ai.playbooks.listPlaybooks({
|
|
80
|
+
* isPublished: true,
|
|
81
|
+
* limit: 50
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
84
|
+
async listPlaybooks({
|
|
85
|
+
limit,
|
|
86
|
+
orderBy,
|
|
87
|
+
orderDirection,
|
|
88
|
+
isPublished,
|
|
89
|
+
recordTypeId,
|
|
90
|
+
} = {}) {
|
|
91
|
+
const params = {
|
|
92
|
+
query: { limit, orderBy, orderDirection, isPublished, recordTypeId },
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const result = await this.sdk._fetch('/ai/playbooks', 'GET', params);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Update a playbook
|
|
101
|
+
*
|
|
102
|
+
* @param {Object} options - Update options
|
|
103
|
+
* @param {string} options.playbookId - The ID of the playbook
|
|
104
|
+
* @param {string} [options.name] - New name
|
|
105
|
+
* @param {boolean} [options.isPublished] - Published status
|
|
106
|
+
* @param {string} [options.recordTypeId] - Record type ID
|
|
107
|
+
* @returns {Promise<Object>} Updated playbook object
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* const updated = await sdk.ai.playbooks.updatePlaybook({
|
|
111
|
+
* playbookId: 'pb_123456',
|
|
112
|
+
* name: 'Updated Sales Call',
|
|
113
|
+
* isPublished: true
|
|
114
|
+
* });
|
|
115
|
+
*/
|
|
116
|
+
async updatePlaybook({ playbookId, name, isPublished, recordTypeId }) {
|
|
117
|
+
this.sdk.validateParams(
|
|
118
|
+
{ playbookId },
|
|
119
|
+
{
|
|
120
|
+
playbookId: { type: 'string', required: true },
|
|
121
|
+
name: { type: 'string', required: false },
|
|
122
|
+
isPublished: { type: 'boolean', required: false },
|
|
123
|
+
recordTypeId: { type: 'string', required: false },
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const params = {
|
|
128
|
+
body: { name, isPublished, recordTypeId },
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const result = await this.sdk._fetch(
|
|
132
|
+
`/ai/playbooks/${playbookId}`,
|
|
133
|
+
'PUT',
|
|
134
|
+
params,
|
|
135
|
+
);
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Delete a playbook (soft delete)
|
|
141
|
+
*
|
|
142
|
+
* @param {Object} options - Delete options
|
|
143
|
+
* @param {string} options.playbookId - The ID of the playbook
|
|
144
|
+
* @returns {Promise<Object>} Success response
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* await sdk.ai.playbooks.deletePlaybook({
|
|
148
|
+
* playbookId: 'pb_123456'
|
|
149
|
+
* });
|
|
150
|
+
*/
|
|
151
|
+
async deletePlaybook({ playbookId }) {
|
|
152
|
+
this.sdk.validateParams(
|
|
153
|
+
{ playbookId },
|
|
154
|
+
{
|
|
155
|
+
playbookId: { type: 'string', required: true },
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const result = await this.sdk._fetch(
|
|
160
|
+
`/ai/playbooks/${playbookId}`,
|
|
161
|
+
'DELETE',
|
|
162
|
+
);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ========================================
|
|
167
|
+
// Playbook Goal CRUD Methods
|
|
168
|
+
// ========================================
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Create a playbook goal
|
|
172
|
+
*
|
|
173
|
+
* @param {Object} options - Goal creation options
|
|
174
|
+
* @param {string} options.playbookId - The ID of the playbook
|
|
175
|
+
* @param {string} options.goal - Goal description
|
|
176
|
+
* @param {string} [options.description] - Detailed description
|
|
177
|
+
* @param {Object} [options.criteria] - Goal criteria as JSON
|
|
178
|
+
* @param {string} [options.scoreType='boolean'] - Score type ('boolean' or 'scale')
|
|
179
|
+
* @param {number} [options.weight=0] - Goal weight (0-100)
|
|
180
|
+
* @param {boolean} [options.requiredForPass=false] - Whether required for pass
|
|
181
|
+
* @param {string} [options.recordTypeId] - Record type ID
|
|
182
|
+
* @returns {Promise<Object>} Created goal with id
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* const goal = await sdk.ai.playbooks.createPlaybookGoal({
|
|
186
|
+
* playbookId: 'pb_123456',
|
|
187
|
+
* goal: 'Identify customer pain points',
|
|
188
|
+
* description: 'Agent should discover at least 2 pain points',
|
|
189
|
+
* scoreType: 'scale',
|
|
190
|
+
* weight: 25
|
|
191
|
+
* });
|
|
192
|
+
*/
|
|
193
|
+
async createPlaybookGoal({
|
|
194
|
+
playbookId,
|
|
195
|
+
playbookGoalTypeId,
|
|
196
|
+
goal,
|
|
197
|
+
description,
|
|
198
|
+
criteria,
|
|
199
|
+
scoreType,
|
|
200
|
+
weight,
|
|
201
|
+
requiredForPass,
|
|
202
|
+
recordTypeId,
|
|
203
|
+
}) {
|
|
204
|
+
this.sdk.validateParams(
|
|
205
|
+
{
|
|
206
|
+
playbookId,
|
|
207
|
+
playbookGoalTypeId,
|
|
208
|
+
goal,
|
|
209
|
+
description,
|
|
210
|
+
criteria,
|
|
211
|
+
scoreType,
|
|
212
|
+
weight,
|
|
213
|
+
requiredForPass,
|
|
214
|
+
recordTypeId,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
playbookId: { type: 'string', required: true },
|
|
218
|
+
playbookGoalTypeId: { type: 'string', required: true },
|
|
219
|
+
goal: { type: 'string', required: true },
|
|
220
|
+
description: { type: 'string', required: false },
|
|
221
|
+
criteria: { type: 'object', required: false },
|
|
222
|
+
scoreType: { type: 'string', required: false },
|
|
223
|
+
weight: { type: 'number', required: false },
|
|
224
|
+
requiredForPass: { type: 'boolean', required: false },
|
|
225
|
+
recordTypeId: { type: 'string', required: false },
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const params = {
|
|
230
|
+
body: {
|
|
231
|
+
playbookGoalTypeId,
|
|
232
|
+
goal,
|
|
233
|
+
description,
|
|
234
|
+
criteria,
|
|
235
|
+
scoreType,
|
|
236
|
+
weight,
|
|
237
|
+
requiredForPass,
|
|
238
|
+
recordTypeId,
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const result = await this.sdk._fetch(
|
|
243
|
+
`/ai/playbooks/${playbookId}/goals`,
|
|
244
|
+
'POST',
|
|
245
|
+
params,
|
|
246
|
+
);
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Get a playbook goal by ID
|
|
252
|
+
*
|
|
253
|
+
* @param {Object} options - Options
|
|
254
|
+
* @param {string} options.playbookId - The ID of the playbook
|
|
255
|
+
* @param {string} options.goalId - The ID of the goal
|
|
256
|
+
* @returns {Promise<Object>} Goal object
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* const goal = await sdk.ai.playbooks.getPlaybookGoal({
|
|
260
|
+
* playbookId: 'pb_123456',
|
|
261
|
+
* goalId: 'goal_789'
|
|
262
|
+
* });
|
|
263
|
+
*/
|
|
264
|
+
async getPlaybookGoal({ playbookId, goalId }) {
|
|
265
|
+
this.sdk.validateParams(
|
|
266
|
+
{ playbookId, goalId },
|
|
267
|
+
{
|
|
268
|
+
playbookId: { type: 'string', required: true },
|
|
269
|
+
goalId: { type: 'string', required: true },
|
|
270
|
+
},
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const result = await this.sdk._fetch(
|
|
274
|
+
`/ai/playbooks/${playbookId}/goals/${goalId}`,
|
|
275
|
+
'GET',
|
|
276
|
+
);
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* List playbook goals
|
|
282
|
+
*
|
|
283
|
+
* @param {Object} options - Options
|
|
284
|
+
* @param {string} options.playbookId - The ID of the playbook
|
|
285
|
+
* @returns {Promise<Object>} Object with results array
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* const goals = await sdk.ai.playbooks.listPlaybookGoals({
|
|
289
|
+
* playbookId: 'pb_123456'
|
|
290
|
+
* });
|
|
291
|
+
*/
|
|
292
|
+
async listPlaybookGoals({ playbookId }) {
|
|
293
|
+
this.sdk.validateParams(
|
|
294
|
+
{ playbookId },
|
|
295
|
+
{
|
|
296
|
+
playbookId: { type: 'string', required: true },
|
|
297
|
+
},
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const result = await this.sdk._fetch(
|
|
301
|
+
`/ai/playbooks/${playbookId}/goals`,
|
|
302
|
+
'GET',
|
|
303
|
+
);
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Update a playbook goal
|
|
309
|
+
*
|
|
310
|
+
* @param {Object} options - Update options
|
|
311
|
+
* @param {string} options.goalId - The ID of the goal
|
|
312
|
+
* @param {string} [options.goal] - Goal description
|
|
313
|
+
* @param {string} [options.description] - Detailed description
|
|
314
|
+
* @param {Object} [options.criteria] - Goal criteria as JSON
|
|
315
|
+
* @param {string} [options.scoreType] - Score type ('boolean' or 'scale')
|
|
316
|
+
* @param {number} [options.weight] - Goal weight (0-100)
|
|
317
|
+
* @param {boolean} [options.requiredForPass] - Whether required for pass
|
|
318
|
+
* @param {string} [options.recordTypeId] - Record type ID
|
|
319
|
+
* @returns {Promise<Object>} Updated goal object
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* const updated = await sdk.ai.playbooks.updatePlaybookGoal({
|
|
323
|
+
* goalId: 'goal_789',
|
|
324
|
+
* weight: 30,
|
|
325
|
+
* description: 'Updated description'
|
|
326
|
+
* });
|
|
327
|
+
*/
|
|
328
|
+
async updatePlaybookGoal({
|
|
329
|
+
goalId,
|
|
330
|
+
playbookGoalTypeId,
|
|
331
|
+
goal,
|
|
332
|
+
description,
|
|
333
|
+
criteria,
|
|
334
|
+
scoreType,
|
|
335
|
+
weight,
|
|
336
|
+
requiredForPass,
|
|
337
|
+
recordTypeId,
|
|
338
|
+
}) {
|
|
339
|
+
this.sdk.validateParams(
|
|
340
|
+
{
|
|
341
|
+
goalId,
|
|
342
|
+
playbookGoalTypeId,
|
|
343
|
+
goal,
|
|
344
|
+
description,
|
|
345
|
+
criteria,
|
|
346
|
+
scoreType,
|
|
347
|
+
weight,
|
|
348
|
+
requiredForPass,
|
|
349
|
+
recordTypeId,
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
goalId: { type: 'string', required: true },
|
|
353
|
+
playbookGoalTypeId: { type: 'string', required: true },
|
|
354
|
+
goal: { type: 'string', required: false },
|
|
355
|
+
description: { type: 'string', required: false },
|
|
356
|
+
criteria: { type: 'object', required: false },
|
|
357
|
+
scoreType: { type: 'string', required: false },
|
|
358
|
+
weight: { type: 'number', required: false },
|
|
359
|
+
requiredForPass: { type: 'boolean', required: false },
|
|
360
|
+
recordTypeId: { type: 'string', required: false },
|
|
361
|
+
},
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
const params = {
|
|
365
|
+
body: {
|
|
366
|
+
playbookGoalTypeId,
|
|
367
|
+
goal,
|
|
368
|
+
description,
|
|
369
|
+
criteria,
|
|
370
|
+
scoreType,
|
|
371
|
+
weight,
|
|
372
|
+
requiredForPass,
|
|
373
|
+
recordTypeId,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const result = await this.sdk._fetch(
|
|
378
|
+
`/ai/playbooks/goals/${goalId}`,
|
|
379
|
+
'PUT',
|
|
380
|
+
params,
|
|
381
|
+
);
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Delete a playbook goal (soft delete)
|
|
387
|
+
*
|
|
388
|
+
* @param {Object} options - Delete options
|
|
389
|
+
* @param {string} options.goalId - The ID of the goal
|
|
390
|
+
* @returns {Promise<Object>} Success response
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* await sdk.ai.playbooks.deletePlaybookGoal({
|
|
394
|
+
* goalId: 'goal_789'
|
|
395
|
+
* });
|
|
396
|
+
*/
|
|
397
|
+
async deletePlaybookGoal({ goalId }) {
|
|
398
|
+
this.sdk.validateParams(
|
|
399
|
+
{ goalId },
|
|
400
|
+
{
|
|
401
|
+
goalId: { type: 'string', required: true },
|
|
402
|
+
},
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
const result = await this.sdk._fetch(
|
|
406
|
+
`/ai/playbooks/goals/${goalId}`,
|
|
407
|
+
'DELETE',
|
|
408
|
+
);
|
|
409
|
+
return result;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Reorder playbook goals
|
|
414
|
+
*
|
|
415
|
+
* @param {Object} options - Reorder options
|
|
416
|
+
* @param {string} options.playbookId - The ID of the playbook
|
|
417
|
+
* @param {string[]} options.goalOrder - Array of goal IDs in desired order
|
|
418
|
+
* @returns {Promise<Object>} Success response
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* await sdk.ai.playbooks.reorderPlaybookGoals({
|
|
422
|
+
* playbookId: 'pb_123',
|
|
423
|
+
* goalOrder: ['goal_3', 'goal_1', 'goal_2']
|
|
424
|
+
* });
|
|
425
|
+
*/
|
|
426
|
+
async reorderPlaybookGoals({ playbookId, goalOrder }) {
|
|
427
|
+
this.sdk.validateParams(
|
|
428
|
+
{ playbookId, goalOrder },
|
|
429
|
+
{
|
|
430
|
+
playbookId: { type: 'string', required: true },
|
|
431
|
+
goalOrder: { type: 'array', required: true },
|
|
432
|
+
},
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
const params = {
|
|
436
|
+
body: {
|
|
437
|
+
goalOrder,
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const result = await this.sdk._fetch(
|
|
442
|
+
`/ai/playbooks/${playbookId}/goals/reorder`,
|
|
443
|
+
'PUT',
|
|
444
|
+
params,
|
|
445
|
+
);
|
|
446
|
+
return result;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// ========================================
|
|
450
|
+
// Playbook Goal Type CRUD Methods
|
|
451
|
+
// ========================================
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Create a playbook goal type
|
|
455
|
+
*
|
|
456
|
+
* @param {Object} options - Goal type creation options
|
|
457
|
+
* @param {string} options.name - Name of the goal type
|
|
458
|
+
* @param {string} [options.description] - Description
|
|
459
|
+
* @param {Array} [options.keywords] - Keywords array for matching
|
|
460
|
+
* @param {string} [options.recommendedPhase] - Recommended phase ('early', 'middle', 'late', 'any')
|
|
461
|
+
* @param {string} [options.recordTypeId] - Record type ID
|
|
462
|
+
* @returns {Promise<Object>} Created goal type with id
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* const goalType = await sdk.ai.playbooks.createPlaybookGoalType({
|
|
466
|
+
* name: 'Opening/Greeting',
|
|
467
|
+
* description: 'Initial greeting and rapport building',
|
|
468
|
+
* keywords: ['hello', 'hi', 'good morning', 'thanks for taking the call'],
|
|
469
|
+
* recommendedPhase: 'early'
|
|
470
|
+
* });
|
|
471
|
+
*/
|
|
472
|
+
async createPlaybookGoalType({
|
|
473
|
+
name,
|
|
474
|
+
description,
|
|
475
|
+
keywords,
|
|
476
|
+
recommendedPhase,
|
|
477
|
+
recordTypeId,
|
|
478
|
+
}) {
|
|
479
|
+
this.sdk.validateParams(
|
|
480
|
+
{ name },
|
|
481
|
+
{
|
|
482
|
+
name: { type: 'string', required: true },
|
|
483
|
+
description: { type: 'string', required: false },
|
|
484
|
+
keywords: { type: 'array', required: false },
|
|
485
|
+
recommendedPhase: { type: 'string', required: false },
|
|
486
|
+
recordTypeId: { type: 'string', required: false },
|
|
487
|
+
},
|
|
488
|
+
);
|
|
489
|
+
|
|
490
|
+
const params = {
|
|
491
|
+
body: { name, description, keywords, recommendedPhase, recordTypeId },
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const result = await this.sdk._fetch(
|
|
495
|
+
'/ai/playbooks/goalTypes',
|
|
496
|
+
'POST',
|
|
497
|
+
params,
|
|
498
|
+
);
|
|
499
|
+
return result;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Get a playbook goal type by ID
|
|
504
|
+
*
|
|
505
|
+
* @param {Object} options - Options
|
|
506
|
+
* @param {string} options.goalTypeId - The ID of the goal type
|
|
507
|
+
* @returns {Promise<Object>} Goal type object
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* const goalType = await sdk.ai.playbooks.getPlaybookGoalType({
|
|
511
|
+
* goalTypeId: 'gt_123456'
|
|
512
|
+
* });
|
|
513
|
+
*/
|
|
514
|
+
async getPlaybookGoalType({ goalTypeId }) {
|
|
515
|
+
this.sdk.validateParams(
|
|
516
|
+
{ goalTypeId },
|
|
517
|
+
{
|
|
518
|
+
goalTypeId: { type: 'string', required: true },
|
|
519
|
+
},
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
const result = await this.sdk._fetch(
|
|
523
|
+
`/ai/playbooks/goalTypes/${goalTypeId}`,
|
|
524
|
+
'GET',
|
|
525
|
+
);
|
|
526
|
+
return result;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* List playbook goal types
|
|
531
|
+
*
|
|
532
|
+
* @param {Object} [options={}] - Query options
|
|
533
|
+
* @param {number} [options.limit=100] - Maximum number of results
|
|
534
|
+
* @param {string} [options.orderBy='createdAt'] - Field to order by
|
|
535
|
+
* @param {string} [options.orderDirection='DESC'] - Order direction
|
|
536
|
+
* @param {string} [options.recommendedPhase] - Filter by recommended phase
|
|
537
|
+
* @param {string} [options.recordTypeId] - Filter by record type
|
|
538
|
+
* @returns {Promise<Object>} Object with results array
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* const goalTypes = await sdk.ai.playbooks.listPlaybookGoalTypes({
|
|
542
|
+
* recommendedPhase: 'early',
|
|
543
|
+
* limit: 50
|
|
544
|
+
* });
|
|
545
|
+
*/
|
|
546
|
+
async listPlaybookGoalTypes({
|
|
547
|
+
limit,
|
|
548
|
+
orderBy,
|
|
549
|
+
orderDirection,
|
|
550
|
+
recommendedPhase,
|
|
551
|
+
recordTypeId,
|
|
552
|
+
} = {}) {
|
|
553
|
+
const params = {
|
|
554
|
+
query: { limit, orderBy, orderDirection, recommendedPhase, recordTypeId },
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const result = await this.sdk._fetch(
|
|
558
|
+
'/ai/playbooks/goalTypes',
|
|
559
|
+
'GET',
|
|
560
|
+
params,
|
|
561
|
+
);
|
|
562
|
+
return result;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Update a playbook goal type
|
|
567
|
+
*
|
|
568
|
+
* @param {Object} options - Update options
|
|
569
|
+
* @param {string} options.goalTypeId - The ID of the goal type
|
|
570
|
+
* @param {string} [options.name] - Name of the goal type
|
|
571
|
+
* @param {string} [options.description] - Description
|
|
572
|
+
* @param {Array} [options.keywords] - Keywords array
|
|
573
|
+
* @param {string} [options.recommendedPhase] - Recommended phase
|
|
574
|
+
* @param {string} [options.recordTypeId] - Record type ID
|
|
575
|
+
* @returns {Promise<Object>} Updated goal type object
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* const updated = await sdk.ai.playbooks.updatePlaybookGoalType({
|
|
579
|
+
* goalTypeId: 'gt_123456',
|
|
580
|
+
* description: 'Updated description',
|
|
581
|
+
* keywords: ['hello', 'hi', 'greetings']
|
|
582
|
+
* });
|
|
583
|
+
*/
|
|
584
|
+
async updatePlaybookGoalType({
|
|
585
|
+
goalTypeId,
|
|
586
|
+
name,
|
|
587
|
+
description,
|
|
588
|
+
keywords,
|
|
589
|
+
recommendedPhase,
|
|
590
|
+
recordTypeId,
|
|
591
|
+
}) {
|
|
592
|
+
this.sdk.validateParams(
|
|
593
|
+
{ goalTypeId },
|
|
594
|
+
{
|
|
595
|
+
goalTypeId: { type: 'string', required: true },
|
|
596
|
+
name: { type: 'string', required: false },
|
|
597
|
+
description: { type: 'string', required: false },
|
|
598
|
+
keywords: { type: 'array', required: false },
|
|
599
|
+
recommendedPhase: { type: 'string', required: false },
|
|
600
|
+
recordTypeId: { type: 'string', required: false },
|
|
601
|
+
},
|
|
602
|
+
);
|
|
603
|
+
|
|
604
|
+
const params = {
|
|
605
|
+
body: { name, description, keywords, recommendedPhase, recordTypeId },
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const result = await this.sdk._fetch(
|
|
609
|
+
`/ai/playbooks/goalTypes/${goalTypeId}`,
|
|
610
|
+
'PUT',
|
|
611
|
+
params,
|
|
612
|
+
);
|
|
613
|
+
return result;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Delete a playbook goal type (soft delete)
|
|
618
|
+
*
|
|
619
|
+
* @param {Object} options - Delete options
|
|
620
|
+
* @param {string} options.goalTypeId - The ID of the goal type
|
|
621
|
+
* @returns {Promise<Object>} Success response
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* await sdk.ai.playbooks.deletePlaybookGoalType({
|
|
625
|
+
* goalTypeId: 'gt_123456'
|
|
626
|
+
* });
|
|
627
|
+
*/
|
|
628
|
+
async deletePlaybookGoalType({ goalTypeId }) {
|
|
629
|
+
this.sdk.validateParams(
|
|
630
|
+
{ goalTypeId },
|
|
631
|
+
{
|
|
632
|
+
goalTypeId: { type: 'string', required: true },
|
|
633
|
+
},
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
const result = await this.sdk._fetch(
|
|
637
|
+
`/ai/playbooks/goalTypes/${goalTypeId}`,
|
|
638
|
+
'DELETE',
|
|
639
|
+
);
|
|
640
|
+
return result;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// ========================================
|
|
644
|
+
// Playbook Session Methods
|
|
645
|
+
// ========================================
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Create a new playbook session
|
|
649
|
+
*
|
|
650
|
+
* Initializes a new session for a published playbook, returning the session ID and
|
|
651
|
+
* associated goals that need to be achieved.
|
|
652
|
+
*
|
|
653
|
+
* @param {Object} options - Session creation options
|
|
654
|
+
* @param {string} options.playbookId - The ID of the playbook to create a session for
|
|
655
|
+
* @param {string} [options.transcriptionSessionId] - Optional transcription session ID to associate
|
|
656
|
+
* @param {string} [options.method='ai'] - Method used for the session ('ai' or other custom methods)
|
|
657
|
+
* @param {string} [options.userId] - User ID for the session (defaults to authenticated user)
|
|
658
|
+
* @param {string} [options.recordTypeId] - Record type ID for tracking
|
|
659
|
+
* @returns {Promise<Object>} Session object with id, playbookId, method, and goals array
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
* // Create a new playbook session
|
|
663
|
+
* const session = await sdk.ai.playbooks.createSession({
|
|
664
|
+
* playbookId: 'pb_123456',
|
|
665
|
+
* method: 'ai',
|
|
666
|
+
* userId: 'user_789'
|
|
667
|
+
* });
|
|
668
|
+
* console.log(session.id); // 'pbs_abc123'
|
|
669
|
+
* console.log(session.goals); // Array of goals for this playbook
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* // Create session with transcription
|
|
673
|
+
* const session = await sdk.ai.playbooks.createSession({
|
|
674
|
+
* playbookId: 'pb_sales_call',
|
|
675
|
+
* transcriptionSessionId: 'trans_xyz',
|
|
676
|
+
* method: 'ai'
|
|
677
|
+
* });
|
|
678
|
+
*/
|
|
679
|
+
async createSession({
|
|
680
|
+
playbookId,
|
|
681
|
+
transcriptionSessionId,
|
|
682
|
+
method,
|
|
683
|
+
userId,
|
|
684
|
+
recordTypeId,
|
|
685
|
+
sipCallId,
|
|
686
|
+
taskId,
|
|
687
|
+
workerId,
|
|
688
|
+
}) {
|
|
689
|
+
this.sdk.validateParams(
|
|
690
|
+
{ playbookId, sipCallId, taskId, workerId },
|
|
691
|
+
{
|
|
692
|
+
playbookId: { type: 'string', required: true },
|
|
693
|
+
transcriptionSessionId: { type: 'string', required: false },
|
|
694
|
+
method: { type: 'string', required: false },
|
|
695
|
+
userId: { type: 'string', required: false },
|
|
696
|
+
recordTypeId: { type: 'string', required: false },
|
|
697
|
+
sipCallId: { type: 'string', required: false },
|
|
698
|
+
taskId: { type: 'string', required: false },
|
|
699
|
+
workerId: { type: 'string', required: false },
|
|
700
|
+
},
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
const params = {
|
|
704
|
+
body: {
|
|
705
|
+
transcriptionSessionId,
|
|
706
|
+
method,
|
|
707
|
+
userId,
|
|
708
|
+
recordTypeId,
|
|
709
|
+
sipCallId,
|
|
710
|
+
taskId,
|
|
711
|
+
workerId,
|
|
712
|
+
},
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
const result = await this.sdk._fetch(
|
|
716
|
+
`/ai/playbooks/sessions/${playbookId}`,
|
|
717
|
+
'POST',
|
|
718
|
+
params,
|
|
719
|
+
);
|
|
720
|
+
return result;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Get a playbook session
|
|
725
|
+
*
|
|
726
|
+
* Returns the session data including the playbook name and all goals
|
|
727
|
+
* (ordered by playbook goal order), each merged with any logged session
|
|
728
|
+
* goal data (achieved, score, reason, confidence, evidence).
|
|
729
|
+
*
|
|
730
|
+
* Supports lookup by sessionId, or by taskId + workerId, or by taskId + userId.
|
|
731
|
+
*
|
|
732
|
+
* @param {Object} options - Get session options
|
|
733
|
+
* @param {string} [options.sessionId] - The ID of the session
|
|
734
|
+
* @param {string} [options.taskId] - The task ID (used with workerId or userId)
|
|
735
|
+
* @param {string} [options.workerId] - The worker ID (used with taskId)
|
|
736
|
+
* @param {string} [options.userId] - The user ID (used with taskId)
|
|
737
|
+
* @returns {Promise<Object>} Session object with playbookName and goals array
|
|
738
|
+
*
|
|
739
|
+
* @example
|
|
740
|
+
* // Lookup by session ID
|
|
741
|
+
* const session = await sdk.ai.playbooks.getSession({
|
|
742
|
+
* sessionId: 'pbs_abc123'
|
|
743
|
+
* });
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* // Lookup by taskId + workerId
|
|
747
|
+
* const session = await sdk.ai.playbooks.getSession({
|
|
748
|
+
* taskId: 'task_123',
|
|
749
|
+
* workerId: 'worker_456'
|
|
750
|
+
* });
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
753
|
+
* // Lookup by taskId + userId
|
|
754
|
+
* const session = await sdk.ai.playbooks.getSession({
|
|
755
|
+
* taskId: 'task_123',
|
|
756
|
+
* userId: 'user_789'
|
|
757
|
+
* });
|
|
758
|
+
*/
|
|
759
|
+
async getSession({ sessionId, taskId, workerId, userId }) {
|
|
760
|
+
this.sdk.validateParams(
|
|
761
|
+
{ sessionId, taskId, workerId, userId },
|
|
762
|
+
{
|
|
763
|
+
sessionId: { type: 'string', required: false },
|
|
764
|
+
taskId: { type: 'string', required: false },
|
|
765
|
+
workerId: { type: 'string', required: false },
|
|
766
|
+
userId: { type: 'string', required: false },
|
|
767
|
+
},
|
|
768
|
+
);
|
|
769
|
+
|
|
770
|
+
if (sessionId) {
|
|
771
|
+
const result = await this.sdk._fetch(
|
|
772
|
+
`/ai/playbooks/sessions/${sessionId}`,
|
|
773
|
+
'GET',
|
|
774
|
+
);
|
|
775
|
+
return result;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
const query = {};
|
|
779
|
+
if (taskId) query.taskId = taskId;
|
|
780
|
+
if (workerId) query.workerId = workerId;
|
|
781
|
+
if (userId) query.userId = userId;
|
|
782
|
+
|
|
783
|
+
const result = await this.sdk._fetch(
|
|
784
|
+
`/ai/playbooks/sessions`,
|
|
785
|
+
'GET',
|
|
786
|
+
{ query },
|
|
787
|
+
);
|
|
788
|
+
return result;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Complete a playbook session
|
|
793
|
+
*
|
|
794
|
+
* Marks a playbook session as complete with final scores and metrics.
|
|
795
|
+
*
|
|
796
|
+
* @param {Object} options - Session completion options
|
|
797
|
+
* @param {string} options.sessionId - The ID of the session to complete
|
|
798
|
+
* @param {boolean} options.passed - Whether the session passed overall criteria
|
|
799
|
+
* @param {number} options.totalScore - Total score achieved in the session
|
|
800
|
+
* @param {number} options.achievedGoals - Number of goals achieved
|
|
801
|
+
* @param {number} options.totalGoals - Total number of goals in the playbook
|
|
802
|
+
* @returns {Promise<Object>} Completion result with playbookSessionId
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
* // Complete a playbook session
|
|
806
|
+
* const result = await sdk.ai.playbooks.completeSession({
|
|
807
|
+
* sessionId: 'pbs_abc123',
|
|
808
|
+
* passed: true,
|
|
809
|
+
* totalScore: 85,
|
|
810
|
+
* achievedGoals: 4,
|
|
811
|
+
* totalGoals: 5
|
|
812
|
+
* });
|
|
813
|
+
* console.log(result.playbookSessionId); // 'pbs_abc123'
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* // Mark session as failed
|
|
817
|
+
* await sdk.ai.playbooks.completeSession({
|
|
818
|
+
* sessionId: 'pbs_xyz789',
|
|
819
|
+
* passed: false,
|
|
820
|
+
* totalScore: 45,
|
|
821
|
+
* achievedGoals: 2,
|
|
822
|
+
* totalGoals: 5
|
|
823
|
+
* });
|
|
824
|
+
*/
|
|
825
|
+
async completeSession({
|
|
826
|
+
sessionId,
|
|
827
|
+
passed,
|
|
828
|
+
totalScore,
|
|
829
|
+
achievedGoals,
|
|
830
|
+
totalGoals,
|
|
831
|
+
}) {
|
|
832
|
+
this.sdk.validateParams(
|
|
833
|
+
{ sessionId },
|
|
834
|
+
{
|
|
835
|
+
sessionId: { type: 'string', required: true },
|
|
836
|
+
passed: { type: 'boolean', required: false },
|
|
837
|
+
totalScore: { type: 'number', required: false },
|
|
838
|
+
achievedGoals: { type: 'number', required: false },
|
|
839
|
+
totalGoals: { type: 'number', required: false },
|
|
840
|
+
},
|
|
841
|
+
);
|
|
842
|
+
|
|
843
|
+
const params = {
|
|
844
|
+
body: {
|
|
845
|
+
passed,
|
|
846
|
+
totalScore,
|
|
847
|
+
achievedGoals,
|
|
848
|
+
totalGoals,
|
|
849
|
+
},
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
const result = await this.sdk._fetch(
|
|
853
|
+
`/ai/playbooks/sessions/${sessionId}/complete`,
|
|
854
|
+
'PUT',
|
|
855
|
+
params,
|
|
856
|
+
);
|
|
857
|
+
return result;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Log a goal achievement or failure for a playbook session
|
|
862
|
+
*
|
|
863
|
+
* Records whether a specific goal within a playbook session was achieved,
|
|
864
|
+
* along with supporting evidence and scoring information.
|
|
865
|
+
*
|
|
866
|
+
* @param {Object} options - Goal logging options
|
|
867
|
+
* @param {string} options.sessionId - The ID of the session
|
|
868
|
+
* @param {string} options.goalId - The ID of the goal to log
|
|
869
|
+
* @param {boolean} options.achieved - Whether the goal was achieved
|
|
870
|
+
* @param {number} [options.score=0] - Score for this goal
|
|
871
|
+
* @param {string} [options.reason] - Explanation for why goal was/wasn't achieved
|
|
872
|
+
* @param {number} [options.confidence] - Confidence level (0-1) in the assessment
|
|
873
|
+
* @param {Array} [options.evidence] - Array of evidence items supporting the assessment
|
|
874
|
+
* @returns {Promise<Object>} Result with playbookSessionId
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* // Log a successful goal achievement
|
|
878
|
+
* await sdk.ai.playbooks.logGoal({
|
|
879
|
+
* sessionId: 'pbs_abc123',
|
|
880
|
+
* goalId: 'goal_456',
|
|
881
|
+
* achieved: true,
|
|
882
|
+
* score: 10,
|
|
883
|
+
* reason: 'Customer clearly expressed interest in the product',
|
|
884
|
+
* confidence: 0.95,
|
|
885
|
+
* evidence: [
|
|
886
|
+
* { type: 'transcript', text: 'I would love to learn more about this' },
|
|
887
|
+
* { type: 'transcript', text: 'When can we schedule a demo?' }
|
|
888
|
+
* ]
|
|
889
|
+
* });
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* // Log a failed goal
|
|
893
|
+
* await sdk.ai.playbooks.logGoal({
|
|
894
|
+
* sessionId: 'pbs_abc123',
|
|
895
|
+
* goalId: 'goal_789',
|
|
896
|
+
* achieved: false,
|
|
897
|
+
* score: 0,
|
|
898
|
+
* reason: 'Product pricing was not discussed during the call',
|
|
899
|
+
* confidence: 0.88
|
|
900
|
+
* });
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* // Log goal with partial achievement
|
|
904
|
+
* await sdk.ai.playbooks.logGoal({
|
|
905
|
+
* sessionId: 'pbs_abc123',
|
|
906
|
+
* goalId: 'goal_discovery',
|
|
907
|
+
* achieved: true,
|
|
908
|
+
* score: 7,
|
|
909
|
+
* reason: 'Identified 2 out of 3 key pain points',
|
|
910
|
+
* confidence: 0.85,
|
|
911
|
+
* evidence: [
|
|
912
|
+
* { painPoint: 'cost_reduction', mentioned: true },
|
|
913
|
+
* { painPoint: 'efficiency', mentioned: true },
|
|
914
|
+
* { painPoint: 'scalability', mentioned: false }
|
|
915
|
+
* ]
|
|
916
|
+
* });
|
|
917
|
+
*/
|
|
918
|
+
async logGoal({
|
|
919
|
+
sessionId,
|
|
920
|
+
goalId,
|
|
921
|
+
achieved,
|
|
922
|
+
score,
|
|
923
|
+
reason,
|
|
924
|
+
confidence,
|
|
925
|
+
evidence,
|
|
926
|
+
}) {
|
|
927
|
+
this.sdk.validateParams(
|
|
928
|
+
{ sessionId, goalId },
|
|
929
|
+
{
|
|
930
|
+
sessionId: { type: 'string', required: true },
|
|
931
|
+
goalId: { type: 'string', required: true },
|
|
932
|
+
achieved: { type: 'boolean', required: false },
|
|
933
|
+
score: { type: 'number', required: false },
|
|
934
|
+
reason: { type: 'string', required: false },
|
|
935
|
+
confidence: { type: 'number', required: false },
|
|
936
|
+
evidence: { type: 'array', required: false },
|
|
937
|
+
},
|
|
938
|
+
);
|
|
939
|
+
|
|
940
|
+
const params = {
|
|
941
|
+
body: {
|
|
942
|
+
goalId,
|
|
943
|
+
achieved,
|
|
944
|
+
score,
|
|
945
|
+
reason,
|
|
946
|
+
confidence,
|
|
947
|
+
evidence,
|
|
948
|
+
},
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
const result = await this.sdk._fetch(
|
|
952
|
+
`/ai/playbooks/sessions/${sessionId}/goal`,
|
|
953
|
+
'POST',
|
|
954
|
+
params,
|
|
955
|
+
);
|
|
956
|
+
return result;
|
|
957
|
+
}
|
|
958
|
+
}
|