@voicenter-team/events-sdk 0.0.11 → 0.0.13

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,535 @@
1
+ import { DebouncedFuncLeading } from 'lodash';
2
+ import { io } from 'socket.io-client';
3
+ import { Socket } from 'socket.io-client';
4
+
5
+ /**
6
+ * Data structure for all dialers status event.
7
+ */
8
+ declare interface AllDialersStatusEvent extends CommonEventProperties {
9
+ // Array of Dialer objects
10
+ dialers: Dialer[]
11
+ }
12
+
13
+ /**
14
+ * Data structure for all extension status event.
15
+ */
16
+ declare interface AllExtensionStatusEvent extends CommonEventProperties {
17
+ // Array of Extension objects
18
+ extensions: Extension[]
19
+ }
20
+
21
+ /**
22
+ * Data structure for all users status event.
23
+ */
24
+ declare interface AllUsersStatusEvent extends CommonEventProperties {
25
+ // Array of User objects
26
+ users: User[]
27
+ }
28
+
29
+ declare class AuthClass {
30
+ private readonly eventsSdkClass;
31
+ constructor(eventsSdkClass: EventsSdkClass);
32
+ private delay;
33
+ lastLoginTimestamp: number | undefined;
34
+ token: string | undefined;
35
+ private storageKey;
36
+ login(options: EventsSdkOptions): Promise<void>;
37
+ updateLastLoginTimestamp(): void;
38
+ private checkLoginStatus;
39
+ private userLoginFunction;
40
+ private onLoginResponse;
41
+ handleTokenExpiry(): void;
42
+ private externalLogin;
43
+ private getSettings;
44
+ private refreshToken;
45
+ }
46
+
47
+ declare enum CallStatusEnum {
48
+ RINGING = "Ringing",
49
+ TALKING = "Talking",
50
+ DIALING = "Dialing",
51
+ HOLD = "Hold"
52
+ }
53
+
54
+ declare enum CallTypeEnum {
55
+ INCOMING = "Incoming",
56
+ OUTGOING = "Outgoing"
57
+ }
58
+
59
+ /**
60
+ * Base structure for all event types, containing common properties.
61
+ */
62
+ declare interface CommonEventProperties {
63
+ // Error code, 0 indicates no error
64
+ errorCode?: number
65
+ // Description of the error, "Ok" indicates successful connection
66
+ errorDesc?: string
67
+ // Server time at the moment of the event
68
+ serverTime: number
69
+ // Difference in time between server and client
70
+ serverTimeOffset: number
71
+ }
72
+
73
+ declare interface CustomData {
74
+ DoNotCallMeStatus?: string,
75
+ DoNotCallMeStatusCode?: DoNotCallMeStatusCodeEnum,
76
+ DoNotCallMeTokenName?: string,
77
+ DoNotCallMetransactionId?: string,
78
+ IsDoNotCallMe?: string
79
+ }
80
+
81
+ declare interface Dialer {
82
+ campaignID: number,
83
+ name: string,
84
+ typeID: number,
85
+ type: DialerType,
86
+ code: string,
87
+ calls: unknown,
88
+ statistics: unknown
89
+ }
90
+
91
+ /**
92
+ * Data structure for dialer event.
93
+ */
94
+ declare interface DialerEvent extends CommonEventProperties {
95
+ data: Dialer
96
+ eventName: EventNameEnum.DIALER
97
+ //reason: ExtensionEventReasonEnum // TODO: do research for dialer 'reason' prop
98
+ telephonyServerTime?: number
99
+ callerID?: string
100
+ ivrUniqueId?: string
101
+ dialStatus?: string
102
+ //cause?: ExtensionHangupCauseEnum // TODO: do research for dialer 'cause' prop
103
+ }
104
+
105
+ declare enum DialerType {
106
+ AUTOMATIC = "Automatic",
107
+ IVR = "IVR"
108
+ }
109
+
110
+ declare enum DirectionEnum {
111
+ INCOMING = "Incoming",
112
+ OUTGOING = "Outgoing",
113
+ SPY = "Spy",
114
+ CLICK2CALL = "Click2call"
115
+ }
116
+
117
+ declare enum DoNotCallMeStatusCodeEnum {
118
+ RESPONSE_FROM_API_VALID = "RESPONSE_FROM_API_VALID",
119
+ RESPONSE_FROM_API_INVALID = "RESPONSE_FROM_API_INVALID"
120
+ }
121
+
122
+ /**
123
+ * Defines a registry of callback functions for each event type.
124
+ * Each key is an event type name, and the value is a function that takes the specific event data type as an argument.
125
+ * This registry is used to manage and invoke event-specific callbacks.
126
+ */
127
+ declare type EventCallbackRegistry = {
128
+ [K in EventTypeNames]: (data: EventDataMap[K]) => void
129
+ }
130
+
131
+ /**
132
+ * Mapping of event names to their respective data structures.
133
+ */
134
+ declare interface EventDataMap {
135
+ [EventsEnum_2.ALL_EXTENSION_STATUS]: AllExtensionStatusEvent
136
+ [EventsEnum_2.ALL_DIALER_STATUS]: AllDialersStatusEvent
137
+ [EventsEnum_2.ALL_USERS_STATUS]: AllUsersStatusEvent
138
+ [EventsEnum_2.QUEUE_EVENT]: QueueEvent
139
+ [EventsEnum_2.EXTENSION_EVENT]: ExtensionEvent
140
+ [EventsEnum_2.DIALER_EVENT]: DialerEvent
141
+ [EventsEnum_2.LOGIN_SUCCESS]: LoginSuccessEvent
142
+ [EventsEnum_2.LOGIN_STATUS]: LoginStatusEvent
143
+ [EventsEnum_2.KEEP_ALIVE_RESPONSE]: KeepAliveResponseEvent
144
+ [EventsEnum_2.ONLINE_STATUS_EVENT]: OnlineStatusEvent
145
+ }
146
+
147
+ /**
148
+ * All the eventNames that can be received from the server. Exists only in EXTENSION_EVENT and QueueEvent
149
+ */
150
+ declare enum EventNameEnum {
151
+ EXTENSION = 'extension',
152
+ QUEUE = 'queue',
153
+ DIALER = 'dialer',
154
+ }
155
+
156
+ /**
157
+ * All events that can be received from the server.
158
+ */
159
+ export declare enum EventsEnum {
160
+ ALL_DIALER_STATUS = "AllDialersStatus",
161
+ ALL_EXTENSION_STATUS = "AllExtensionsStatus",
162
+ ALL_USERS_STATUS = "AllUsersStatus",
163
+ CONNECT = "connect",
164
+ DISCONNECT = "disconnect",
165
+ EXTENSION_EVENT = "ExtensionEvent",
166
+ KEEP_ALIVE = "keepalive",
167
+ KEEP_ALIVE_RESPONSE = "keepaliveResponse",
168
+ LOGIN_STATUS = "loginStatus",
169
+ LOGIN_SUCCESS = "loginSuccess",
170
+ QUEUE_EVENT = "QueueEvent",
171
+ ONLINE_STATUS_EVENT = "onlineStatusEvent",
172
+ DIALER_EVENT = "DialerEvent"
173
+ }
174
+
175
+ /**
176
+ * All events that can be received from the server.
177
+ */
178
+ declare enum EventsEnum_2 {
179
+ ALL_DIALER_STATUS = 'AllDialersStatus',
180
+ ALL_EXTENSION_STATUS = 'AllExtensionsStatus',
181
+ ALL_USERS_STATUS = 'AllUsersStatus',
182
+ CONNECT = 'connect',
183
+ DISCONNECT = 'disconnect',
184
+ EXTENSION_EVENT = 'ExtensionEvent',
185
+ KEEP_ALIVE = 'keepalive',
186
+ KEEP_ALIVE_RESPONSE = 'keepaliveResponse',
187
+ // This type of event will be sent only in case of a successful connection.
188
+ // The event describes the list of monitored queues on this active connection.
189
+ // The list of monitored queues will only be sent if the login connection was made with account credentials or account token.
190
+ // If the login connection type is by user credentials, only the user’s extension assigned queues will return.
191
+ LOGIN_STATUS = 'loginStatus',
192
+ // This type of event will be sent in the initial login connection request in case of a successful connection only.
193
+ // In case of wrong username or password or token, you will receive a 401 (“Unauthorized”) or 500 (“Unexpected token”) http error.
194
+ LOGIN_SUCCESS = 'loginSuccess',
195
+ QUEUE_EVENT = 'QueueEvent',
196
+ ONLINE_STATUS_EVENT = 'onlineStatusEvent',
197
+ DIALER_EVENT = 'DialerEvent',
198
+ }
199
+
200
+ /**
201
+ * This is a generic type for callback functions used in event handling.
202
+ * It takes a generic event name and defines a callback function that receives wrapped socket event data for that specific event.
203
+ */
204
+ declare type EventSpecificCallback<T extends EventTypeNames> = (data: WrappedSocketEvent<T>) => void
205
+
206
+ declare class EventsSdkClass {
207
+ constructor(options: EventsSdkOptions);
208
+ private argumentOptions;
209
+ readonly options: EventsSdkOptions;
210
+ servers: Server[];
211
+ server: Server;
212
+ socket: SocketTyped | undefined;
213
+ authClass: AuthClass;
214
+ socketIoClass: SocketIoClass;
215
+ reconnectOptions: ReconnectOptions;
216
+ retryConnection: DebouncedFuncLeading<(server?: ServerParameter, skipLogin?: boolean) => void>;
217
+ private listeners;
218
+ private allListeners;
219
+ on<T extends EventTypeNames>(event: T, callback: EventSpecificCallback<T>): void;
220
+ on(event: '*', callback: (data: GenericEventWrapper) => void): void;
221
+ off<T extends EventTypeNames>(event: T, callback: EventSpecificCallback<T>): void;
222
+ off(event: '*', callback: (data: GenericEventWrapper) => void): void;
223
+ emit<T extends EventTypeNames>(event: T, data: EventTypeData<T>): void;
224
+ connect(server?: ServerParameter, skipLogin?: boolean): void;
225
+ disconnect(): void;
226
+ clearKeepAliveInterval(): void;
227
+ private findCurrentServer;
228
+ private findNextAvailableServer;
229
+ private findMaxPriorityServer;
230
+ private findMinPriorityServer;
231
+ getServerWithHighestPriority(servers: Server[]): Server;
232
+ init(): Promise<boolean>;
233
+ private getServers;
234
+ }
235
+ export default EventsSdkClass;
236
+
237
+ declare interface EventsSdkOptions {
238
+ isNewStack?: boolean;
239
+ servers: Server[];
240
+ loginUrl: string;
241
+ fallbackServer: Server;
242
+ refreshTokenUrl?: string;
243
+ refreshToken?: string;
244
+ token: string;
245
+ tokenExpiry?: Date;
246
+ loginType: LoginType;
247
+ forceNew?: boolean;
248
+ reconnectionDelay: number;
249
+ reconnectionDelayMax?: number;
250
+ maxReconnectAttempts: number;
251
+ timeout?: number;
252
+ keepAliveTimeout: number;
253
+ idleInterval?: number;
254
+ protocol: string;
255
+ transports?: string[];
256
+ upgrade?: boolean;
257
+ serverFetchStrategy?: string;
258
+ serverType?: number;
259
+ useLogger?: boolean;
260
+ loggerSocketConnection?: string;
261
+ loggerServer?: string;
262
+ loggerConfig?: LoggerConfig;
263
+ loggerConnectOptions?: LoggerConnectOptions;
264
+ email: string;
265
+ password: string;
266
+ username: string;
267
+ }
268
+
269
+ declare type EventTypeData<T extends EventsEnum_2> = EventDataMap[T]
270
+
271
+ /**
272
+ * Represents the set of all possible event type names as keys from the EventDataMap.
273
+ * This type is used to define event listeners and handlers.
274
+ */
275
+ declare type EventTypeNames = keyof EventDataMap
276
+
277
+ /**
278
+ * This type represents a mapping of listener event names to their corresponding wrapped socket event data structures.
279
+ * Each key is an event name, and the value is the wrapped socket event data for that event
280
+ */
281
+ declare type EventWrappedSocketDataMap = {
282
+ [K in EventTypeNames]: WrappedSocketEvent<K>
283
+ }
284
+
285
+ declare interface Extension {
286
+ calls: ExtensionCall[],
287
+ userID: number,
288
+ userName: string,
289
+ number: number,
290
+ extenUser: string,
291
+ accountID: number,
292
+ topAccountID: number,
293
+ summery: Summery,
294
+ onlineUserID: number,
295
+ representative: number,
296
+ representativeStatus: number,
297
+ lastCallEventEpoch: number,
298
+ lastAnsweredCallEventEpoch: number,
299
+ lastHangupCallEpoch: number,
300
+ representativeUpdated: number,
301
+ peerStatus: unknown,
302
+ currentCall?: ExtensionCall,
303
+ }
304
+
305
+ declare interface ExtensionCall {
306
+ callStarted: number,
307
+ calldurationinterval: number,
308
+ callAnswered: number,
309
+ answered: number,
310
+ callername: string,
311
+ callerphone: string,
312
+ outgoingcallername?: string,
313
+ outgoingcallerphone?: string,
314
+ callstatus: CallStatusEnum,
315
+ customdata: CustomData,
316
+ direction: DirectionEnum,
317
+ ivrid: string,
318
+ recording: Recording,
319
+ did: string,
320
+ relatedIvrUniqueIDs?: string[],
321
+ callType?: CallTypeEnum,
322
+ ip: string,
323
+ isInternal: boolean
324
+ blcServerID: number,
325
+ isOpensips: boolean,
326
+ channel: string,
327
+ channel2: string,
328
+ queueID?: number,
329
+ isSpyed?: boolean,
330
+ blcServerId?: number,
331
+ originalCallerID?: string,
332
+ originalCallerName?: string,
333
+ actualDialedNumber?: number
334
+ }
335
+
336
+ /**
337
+ * Data structure for extension event.
338
+ */
339
+ declare interface ExtensionEvent extends CommonEventProperties {
340
+ data: Extension
341
+ eventName: EventNameEnum.EXTENSION
342
+ reason: ExtensionEventReasonEnum
343
+ telephonyServerTime?: number
344
+ callerID?: string
345
+ ivrUniqueId?: string
346
+ dialStatus?: string
347
+ cause?: ExtensionHangupCauseEnum
348
+ }
349
+
350
+ /**
351
+ * All the reasons for the extension event, e.g. a new call is ringing or dialing from an extension.
352
+ */
353
+ declare enum ExtensionEventReasonEnum {
354
+ // A new call is ringing or dialing from an extension.
355
+ NEW_CALL = 'NEWCALL',
356
+ // A call was answered at an extension.
357
+ ANSWER = 'ANSWER',
358
+ // A call was placed on hold.
359
+ HOLD = 'HOLD',
360
+ // A call is no longer on hold.
361
+ UNHOLD = 'UNHOLD',
362
+ // When a call was ended. It is not necessarily means that the call was answered.
363
+ HANGUP = 'HANGUP',
364
+ // When the extension online user updated his\her user status(Login, Break, Logout, etc.)
365
+ USER_STATUS_UPDATE = 'userStatusUpdate',
366
+ }
367
+
368
+ declare enum ExtensionHangupCauseEnum {
369
+ NORMAL_HANGUP = 'Normal hangup',
370
+ USER_BUSY = 'User busy',
371
+ CALL_REJECTED = 'Call Rejected',
372
+ UNALLOCATED_NUMBER = 'Unallocated (unassigned) number',
373
+ UNKNOWN = 'Unknown',
374
+ NO_USER_RESPONDING = 'No user responding',
375
+ USER_ALERTING = 'User alerting, no answer',
376
+ ANSWERED_ELSEWHERE = 'Answered elsewhere'
377
+ }
378
+
379
+ /**
380
+ * A generic type that represents the structure of any event data wrapped in a socket event format.
381
+ * This type is used in the handling of all event types, providing a consistent structure for event data processing.
382
+ */
383
+ declare type GenericEventWrapper = EventWrappedSocketDataMap[EventTypeNames]
384
+
385
+ /**
386
+ * Data structure for keep alive response event.
387
+ */
388
+ declare interface KeepAliveResponseEvent extends CommonEventProperties {
389
+ isOk: boolean
390
+ }
391
+
392
+ declare interface LoggerConfig {
393
+ logToConsole?: boolean;
394
+ overloadGlobalConsole?: boolean;
395
+ namespace?: string;
396
+ socketEmitInterval?: number;
397
+ }
398
+
399
+ declare interface LoggerConnectOptions {
400
+ reconnection?: boolean;
401
+ reconnectionDelay?: number;
402
+ reconnectionAttempts?: number;
403
+ perMessageDeflate?: boolean;
404
+ upgrade?: boolean;
405
+ transports?: string[];
406
+ debug?: boolean;
407
+ }
408
+
409
+ /**
410
+ * Data structure for login status event.
411
+ */
412
+ declare interface LoginStatusEvent extends CommonEventProperties {
413
+ // Array of Queue objects
414
+ queues: Queue[]
415
+ }
416
+
417
+ declare type LoginSuccessEvent = CommonEventProperties
418
+
419
+ declare enum LoginType {
420
+ USER = "User",
421
+ TOKEN = "Token"
422
+ }
423
+
424
+ declare interface OnlineStatusEvent {
425
+ isSocketConnected: boolean
426
+ }
427
+
428
+ declare interface Queue {
429
+ QueueID: number,
430
+ QueueName: string,
431
+ Calls: QueueCall[],
432
+ UserId?: number,
433
+ DistributorID?: number,
434
+ IsDistributedQueue?: boolean,
435
+ AnsweredAgent?: string,
436
+ }
437
+
438
+ declare interface QueueCall {
439
+ CallerID: string,
440
+ CallerName: string,
441
+ IvrUniqueID: string,
442
+ JoinTimeStamp: number,
443
+ calldurationinterval: number,
444
+ ivrid: string,
445
+ isDistributedQueue?: boolean
446
+ }
447
+
448
+ /**
449
+ * Data structure for queue event.
450
+ */
451
+ declare interface QueueEvent extends CommonEventProperties {
452
+ eventName: EventNameEnum.QUEUE,
453
+ reason: QueueEventReasonEnum,
454
+ telephonyServerTime: number,
455
+ ivrUniqueId: string,
456
+ data: Queue
457
+ }
458
+
459
+ declare enum QueueEventReasonEnum {
460
+ ANSWER = 'ANSWER',
461
+ ABANDONED = 'ABANDONED',
462
+ EXIT = 'EXIT',
463
+ JOIN = 'JOIN'
464
+ }
465
+
466
+ declare interface ReconnectOptions {
467
+ retryCount: number;
468
+ maxReconnectAttempts: number;
469
+ reconnectionDelay: number;
470
+ minReconnectionDelay: number;
471
+ maxReconnectionDelay: number;
472
+ }
473
+
474
+ declare interface Recording {
475
+ Filename: string,
476
+ Options: string,
477
+ ApproximateURL: string,
478
+ IsMuted: number
479
+ }
480
+
481
+ declare interface Server {
482
+ Priority: number;
483
+ Domain: string;
484
+ URLID: number;
485
+ Version: string;
486
+ }
487
+
488
+ declare enum ServerParameter {
489
+ DEFAULT = "default",
490
+ NEXT = "next",
491
+ PREVIOUS = "previous"
492
+ }
493
+
494
+ declare class SocketIoClass {
495
+ private readonly eventsSdkClass;
496
+ constructor(eventsSdkClass: EventsSdkClass);
497
+ io: SocketTyped | undefined;
498
+ ioFunction: TypedSocketIo | undefined;
499
+ lastEventTimestamp: number;
500
+ doReconnect: boolean;
501
+ private keepAliveInterval;
502
+ private keepReconnectInterval;
503
+ private connected;
504
+ getSocketIoFunction(Client: string): void;
505
+ initSocketConnection(): void;
506
+ initSocketEvents(): void;
507
+ clearKeepAliveInterval(): void;
508
+ initKeepAlive(): void;
509
+ closeAllConnections(): void;
510
+ private onKeepAliveResponse;
511
+ private onConnect;
512
+ private onDisconnect;
513
+ }
514
+
515
+ declare type SocketTyped = Socket<EventCallbackRegistry, Record<EventsEnum, any>>
516
+
517
+ declare interface Summery {
518
+ representative: string
519
+ }
520
+
521
+ declare type TypedSocketIo = (...args: Parameters<typeof io>) => any;
522
+
523
+ declare interface User {
524
+ userID: number,
525
+ userName: string,
526
+ accountID: number
527
+
528
+ }
529
+
530
+ declare type WrappedSocketEvent<T extends EventsEnum_2> = {
531
+ name: T
532
+ data: EventDataMap[T]
533
+ }
534
+
535
+ export { }