UNPKG

rn-kore-bot-socket-lib-v77

Version:
216 lines (206 loc) 7.48 kB
import { EventEmitter } from 'events'; declare const RTM_EVENT: { CONNECTING: string; AUTHENTICATED: string; ON_OPEN: string; ON_DISCONNECT: string; ON_CLOSE: string; ON_ERROR: string; ON_MESSAGE: string; ON_FAILURE: string; PING: string; PONG: string; ERROR: string; RECONNECTING: string; UNABLE_TO_RTM_START: string; GET_HISTORY: string; GET_RESULT_VIEW_SETTINGS: string; ON_ACK: string; ON_EVENTS: string; ON_JWT_TOKEN_AUTHORIZED: string; }; declare const ConnectionState: { CONNECTING: number; CONNECTED: number; DISCONNECTED: number; }; declare const APP_STATE: { ACTIVE: string; SLEEP: string; }; interface BotConfigModel { botName: string; botId: string; clientId: string; clientSecret: string; botUrl: string; identity: string; jwtServerUrl: string; isWebHook: boolean; value_aud: string; isHeaderVisible: boolean; isFooterVisible: boolean; jwtToken?: string; } interface IBotClient { sendMessage(message: any, payload?: any, attachments?: any): any; reconnect(isReconnectionAttempt: boolean, resetReconnectAttemptCount?: boolean): any; setIsNetworkAvailable(setNetWork: boolean): any; initializeBotClient(model: BotConfigModel, isFirstTime: boolean): any; disconnect(): any; setSessionActive(isActive: boolean): any; setAppState(appState: string): any; checkSocketAndReconnect(): any; getBotUserIdentity(): any; getConnectionState(): any; getBotName(): string | undefined; getBotUrl(): string | undefined; getUserId(): string; getAccessToken(): string; getAuthorization(): string | undefined; getAppState(): string | undefined; sendEvent(eventName: any, isZenDeskEvent?: any): void; } declare class BotClient extends EventEmitter implements IBotClient { private pingInterval; private pingTimer?; private receivedLastPong; private timer?; private isConnecting; private jwtToken; private resultViewSettings; private webSocket?; private botUrl; private sessionActive; private appState; private isNetWorkAvailable; private botInfo; private customData; private userInfo; private authorization; private botCustomData; private isConnectAtleastOnce; private connectionState; private reconnectAttemptCount; private isReconnectAttemptRequired; private DATA_IDENTITY; private DATA_USERNAME; private RECONNECT_PARAM; private reconnectTimer?; private botConfig?; private isChangeToken?; constructor(); initializeBotClient(config: BotConfigModel, isFirstTime: boolean): void; getJwtToken: () => String; getAccessToken(): any; getUserId: () => any; getBotName: () => string | undefined; getBotUrl: () => string; getJwtServerUrl: () => string; getAuthorization: () => string | undefined; private connectToBot; private createJwtToken; private getWebhookMeta; private initialize; setSessionActive(isActive: boolean): void; setAppState(appState: string): void; getAppState(): string | undefined; setIsNetworkAvailable(isNetWorkAvailable: boolean): void; private connectWithJwToken; private getRtmUrl; private connect; private onMessage; private fetchWithRetries; getConnectionState(): number; disconnect(): void; private initSocketConnection; reconnect(isReconnectionAttempt: boolean, resetReconnectAttemptCount?: boolean): void; private refreshTokenAndReconnect; private getReconnectDelay; checkSocketAndReconnect(): void; private startSendingPing; private setTimer; private send; getBotAccessToken(): any; getResultViewSettings(): never[]; getBotUserId(): any; getBotUserIdentity(): any; getBotInfo(): any; sendMessage(message: any, payload?: any, attachments?: any): any; private onWebhookMessages; sendEvent(eventName: any, isZenDeskEvent?: any): void; } declare class KoreBotClient extends BotClient implements IBotClient { private static _instance; private constructor(); static getInstance(): KoreBotClient; static disconnectClient(): void; setSessionActive(isActive: boolean): void; setAppState(_appState: string): void; setIsNetworkAvailable(isNetWorkAvailable: boolean): void; checkSocketAndReconnect(): void; } declare class ActiveThemeAPI { private isSocketACtive; private fetchWithRetries; getThemeAPI(botConfig: BotConfigModel, callback?: (data?: any) => void): Promise<void>; private getAppTheme; } declare enum LogLevel { DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3 } interface LogEntry { timestamp: string; level: LogLevel; category: string; message: string; data?: any; error?: any; } declare class Logger { private static instance; private logLevel; private logs; private maxLogs; private constructor(); static getInstance(): Logger; setLogLevel(level: LogLevel): void; private log; logApiRequest(endpoint: string, method: string, data?: any): void; logApiSuccess(endpoint: string, method: string, responseData?: any, duration?: number): void; logApiError(endpoint: string, method: string, error: any, duration?: number): void; logWebSocketEvent(event: string, data?: any): void; logWebSocketError(event: string, error: any): void; logConnectionEvent(event: string, data?: any): void; logConnectionError(event: string, error: any): void; debug(message: string, data?: any): void; info(message: string, data?: any): void; warn(message: string, data?: any, error?: any): void; error(message: string, data?: any, error?: any): void; getLogs(level?: LogLevel): LogEntry[]; clearLogs(): void; } declare class ApiService { private baseUrl; private botClient; constructor(baseUrl: string, botClient: BotClient); private fetchWithRetries; getBotHistory(offset: number, limit: number, botConfig: BotConfigModel, onResponse: (response?: any) => void): Promise<void>; private processHistoryResponse; private createBotResponse; private createBotRequest; subscribePushNotifications(deviceId?: string): Promise<boolean>; unsubscribePushNotifications(deviceId?: string): Promise<boolean>; getJwtToken(config: BotConfigModel, isFirstTime: boolean | undefined, onResponse: (jwtToken: string) => void, onError: (error: any) => void): Promise<boolean>; getJwtGrant(jwtToken: String, isReconnectionAttempt: boolean, onStatus: any, onResponse: (response: any) => void, onError: (error: any) => void): Promise<boolean>; getRtmUrl(isReconnectionAttempt: boolean, onResponse: (response: any) => void, onError: (error: any) => void): Promise<void>; getSettings(onResponse: any): Promise<void>; getWebHookBotMeta(jwtToken: String, botId: string, onResponse: (response?: any) => void): Promise<void>; sendWebHookMessage(botConfig: BotConfigModel, isNewSession: Boolean, msg: String, onResponse: (response?: any) => void, payload?: string, attachments?: any): Promise<void>; private processWebHookResponse; getPollData(botConfig: BotConfigModel, pollId: string, onResponse: (response?: any) => void): Promise<void>; } export { APP_STATE, ActiveThemeAPI, ApiService, type BotConfigModel, ConnectionState, type LogEntry, LogLevel, Logger, RTM_EVENT, KoreBotClient as default };