-
Notifications
You must be signed in to change notification settings - Fork 33
/
types.d.ts
365 lines (326 loc) · 11.4 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import { EventEmitter } from 'events';
import TypedEmitter from 'typed-emitter';
export as namespace TaskRouter;
export class Worker extends (EventEmitter as new () => TypedEmitter<WorkerEvents>) {
constructor(token: string, options?: WorkerOptions);
readonly accountSid: string;
readonly activities: Map<string, Activity>;
readonly activity: Activity;
readonly activitySid: string;
readonly available: boolean;
readonly attributes: Record<string, any>;
readonly channels: Map<string, Channel>;
readonly connectActivitySid: string;
readonly dateCreated: Date;
readonly dateStatusChanged: Date;
readonly dateUpdated: Date;
readonly disconnectActivitySid: string;
readonly name: string;
readonly reservations: Map<string, Reservation>;
readonly sid: string;
readonly workspaceSid: string;
readonly workerSid: string;
readonly workerActivitySid: string;
readonly dateActivityChanged: Date;
readonly friendlyName: string;
version: string;
createTask(to: string, from: string, workflowSid: string, taskQueueSid: string, options?: TaskOptions): Promise<string>;
disconnect(): void;
setAttributes(attributes: any): Promise<Worker>;
updateToken(newToken: string): void;
fetchLatestVersion(): Promise<Worker>;
}
export class Supervisor extends Worker {
monitor(taskSid: string, reservationSid: string, extraParams: Object): Promise<void>;
setWorkerAttributes(workerSid: string, attributes: Record<string, any>): Promise<Worker>;
setWorkerActivity(workerSid: string, activitySid: string, options?: ActivityOptions): Promise<Worker>;
}
interface WorkerEvents {
activityUpdated: (worker: Worker) => void;
attributesUpdated: (worker: Worker) => void;
disconnected: (worker: Worker) => void;
error: (error: Error) => void;
ready: (worker: Worker) => void;
reservationCreated: (reservation: Reservation) => void;
reservationFailed: (reservation: Reservation) => void;
tokenExpired: () => void;
tokenUpdated: () => void;
}
export interface Activity {
readonly accountSid: string;
readonly available: boolean;
readonly dateCreated: Date;
readonly dateUpdated: Date;
readonly isCurrent: boolean;
readonly name: string;
readonly sid: string;
readonly workspaceSid: string;
setAsCurrent(options?: ActivityOptions): Promise<Activity>;
}
export class Channel extends (EventEmitter as new () => TypedEmitter<ChannelEvents>) {
readonly accountSid: string;
readonly assignedTasks: number;
readonly available: boolean;
readonly availableCapacityPercentage: number;
readonly capacity: number;
readonly lastReservedTime: Date;
readonly dateCreated: Date;
readonly dateUpdated: Date;
readonly sid: string;
readonly taskChannelSid: string;
readonly taskChannelUniqueName: string;
readonly workerSid: string;
readonly workspaceSid: string;
}
interface ChannelEvents {
availabilityUpdated: (channel: Channel) => void;
capacityUpdated: (channel: Channel) => void;
}
export class Task extends (EventEmitter as new () => TypedEmitter<TaskEvents>) {
readonly addOns: Object;
readonly age: number;
readonly attributes: Record<string, any>;
readonly dateCreated: Date;
readonly dateUpdated: Date;
readonly priority: number;
readonly queueName: string;
readonly queueSid: string;
readonly reason: string;
readonly sid: string;
readonly status: "pending" | "reserved" | "assigned" | "canceled" | "completed" | "wrapping";
readonly taskChannelSid: string;
readonly taskChannelUniqueName: string;
readonly timeout: number;
readonly transfers: Transfers;
readonly workflowName: string;
readonly workflowSid: string;
readonly routingTarget: string;
readonly version: string;
readonly virtualStartTime: Date;
complete(reason: string): Promise<Task>;
hold(targetWorkerSid: string, onHold: boolean, options?: TaskHoldOptions): Promise<Task>;
kick(workerSid: string): Promise<Task>;
setAttributes(attributes: Object): Promise<Task>;
setVirtualStartTime(date: Date): Promise<Task>;
transfer(to: string, options: TransferOptions): Promise<Task>;
wrapUp(options: WrappingOptions): Promise<Task>;
updateParticipant(options: TaskParticipantOptions): Promise<Task>;
fetchLatestVersion(): Promise<Task>;
}
interface TaskEvents {
canceled: (task: Task) => void;
completed: (task: Task) => void;
transferInitiated: (outgoingTransfer: OutgoingTransfer) => void;
updated: (task: Task) => void;
wrapup: (task: Task) => void;
}
export class Reservation extends (EventEmitter as new () => TypedEmitter<ReservationEvents>) {
readonly accountSid: string;
readonly dateCreated: Date;
readonly dateUpdated: Date;
readonly sid: string;
readonly status: "pending" | "accepted" | "rejected" | "timeout" | "canceled" | "rescinded" | "wrapping" | "completed";
readonly task: Task;
readonly timeout: number;
readonly workerSid: string;
readonly workspaceSid: string;
readonly canceledReasonCode?: number;
readonly version: string;
accept(): Promise<Reservation>;
complete(): Promise<Reservation>;
wrap(): Promise<Reservation>;
call(from: string, url: string, options?: CallOptions): Promise<Reservation>;
conference(options?: ConferenceOptions): Promise<Reservation>;
dequeue(options?: DequeueOptions): Promise<Reservation>;
redirect(callSid: string, url: string, options?: RedirectOptions): Promise<Reservation>;
reject(options?: RejectOptions): Promise<Reservation>;
updateParticipant(options: ReservationParticipantOptions): Promise<Reservation>;
fetchLatestVersion(): Promise<Reservation>;
}
interface ReservationEvents {
accepted: (reservation: Reservation) => void;
canceled: (reservation: Reservation) => void;
completed: (reservation: Reservation) => void;
rejected: (reservation: Reservation) => void;
rescinded: (reservation: Reservation) => void;
timeout: (reservation: Reservation) => void;
wrapup: (reservation: Reservation) => void;
}
export interface TaskQueue {
readonly sid: string;
readonly queueSid: string;
readonly queueName: string;
readonly accountSid: string;
readonly workplaceSid: string;
readonly name: string;
readonly assignmentActivityName: string;
readonly reservationActivityName: string;
readonly assignmentActivitySid: string;
readonly reservationActivitySid: string;
readonly targetWorkers: string;
readonly maxReservedWorkers: number;
readonly taskOrder: string;
dateCreated: Date;
dateUpdated: Date;
}
export class TaskRouterEventHandler {
constructor(worker: Worker, options?: Object);
getTREventsToHandlerMapping(): {[key: string]: string};
}
type FetchTaskQueuesParams = {
AfterSid?: string;
FriendlyName?: string;
Ordering?: "DateUpdated:asc" | "DateUpdated:desc"
WorkerSid?: string;
}
type FetchWorkersParams = {
AfterSid?: string;
FriendlyName?: string;
ActivitySid?: string;
ActivityName?: string;
TargetWorkersExpression?: string;
Ordering?: "DateStatusChanged:asc" | "DateStatusChanged:desc"
MaxWorkers?: number;
};
export class Workspace {
constructor(jwt: string, options?: Object, workspaceSid?: string);
readonly workspaceSid: string;
updateToken(newToken: string): void;
fetchWorker(workerSid: string): Promise<Worker>;
fetchWorkers(params?: FetchWorkersParams): Promise<Map<string, Worker>>;
fetchTaskQueue(queueSid: string): Promise<TaskQueue>;
fetchTaskQueues(params?: FetchTaskQueuesParams): Promise<Map<string, TaskQueue>>;
}
export interface Transfers {
readonly incoming: IncomingTransfer | null;
readonly outgoing: OutgoingTransfer | null;
}
export interface IncomingTransfer {
readonly dateCreated: Date;
readonly dateUpdated: Date;
readonly mode: "WARM" | "COLD";
readonly reservationSid: string;
readonly sid: string;
readonly status: "INITIATED" | "FAILED" | "COMPLETE" | "CANCELED";
readonly to: string;
readonly type: "QUEUE" | "WORKER";
readonly workerSid: string;
}
export interface OutgoingTransfer extends EventEmitter {
readonly dateCreated: Date;
readonly dateUpdated: Date;
readonly mode: "WARM" | "COLD";
readonly reservationSid: string;
readonly sid: string;
readonly status: "INITIATED" | "FAILED" | "COMPLETED" | "CANCELED";
readonly to: string;
readonly transferFailedReason: string;
readonly type: "QUEUE" | "WORKER";
readonly workerSid: string;
cancel(): Promise<OutgoingTransfer>;
}
export interface CallOptions {
readonly accept?: boolean;
readonly record?: boolean;
readonly statusCallbackUrl?: string;
readonly to?: string;
readonly timeout?: number;
}
export interface DequeueOptions {
from?:string;
to?:string;
postWorkActivitySid?:string;
record?:string;
timeout?:number;
statusCallbackUrl?:string;
statusCallbackEvents?:string;
}
export interface ConferenceOptions {
to?:string;
from?:string;
timeout?:number;
statusCallback?:string;
statusCallbackMethod?:string;
statusCallbackEvent?:string;
record?:string;
muted?:boolean;
beep?:string | boolean;
startConferenceOnEnter?:boolean;
endConferenceOnExit?:boolean;
endConferenceOnCustomerExit?:boolean;
beepOnCustomerEntrance?:boolean;
waitUrl?:string;
waitMethod?:string;
earlyMedia?:boolean;
maxParticipants?:number;
conferenceStatusCallback?:string;
conferenceStatusCallbackMethod?:string;
conferenceStatusCallbackEvent?:string;
conferenceRecord?:string | boolean;
conferenceTrim?:string;
recordingChannels?:string;
recordingStatusCallback?:string;
recordingStatusCallbackMethod?:string;
conferenceRecordingStatusCallback?:string;
conferenceRecordingStatusCallbackMethod?:string;
region?:string;
sipAuthUsername?:string;
sipAuthPassword?:string;
transcribe?:boolean;
transcriptionConfiguration?:string;
}
export interface RedirectOptions {
accept?:boolean;
}
export interface RejectOptions {
activitySid: string;
}
export interface TransferOptions {
attributes?: Object;
mode?: "COLD" | "WARM";
priority?: number;
}
export interface TaskParticipantOptions extends TaskHoldOptions {
hold: boolean;
}
export interface WrappingOptions {
reason: string;
}
export interface ReservationParticipantOptions {
endConferenceOnExit?: boolean;
mute?: boolean;
beepOnExit?: boolean;
}
export interface WorkerOptions {
connectActivitySid?: string;
closeExistingSessions?: boolean;
setWorkerOfflineIfDisconnected?: boolean
logLevel?: "error" | "warn" | "info" | "debug" | "trace" | "silent";
ebServer?: string;
wsServer?: string;
eventHandlerClass?: typeof TaskRouterEventHandler;
region?: string;
enableVersionCheck?: boolean;
}
export interface WorkspaceOptions {
region?: string;
pageSize?: number;
logLevel?: "error" | "warn" | "info" | "debug" | "trace" | "silent";
}
export interface TaskOptions {
attributes?: any;
taskChannelUniqueName?: string;
taskChannelSid?: string;
}
export interface ActivityOptions {
rejectPendingReservations?: boolean;
}
export interface TaskHoldOptions {
holdUrl?: string;
holdMethod?: string;
}
export interface TaskTransferOptions {
attributes?: any;
mode?: "WARM" | "COLD";
priority?: string;
}