/** * Polling Integration Manager * Manages integration with LongPollingManager * * @module client/managers/PollingIntegrationManager */ import type { RouteConfigManager } from './RouteConfigManager.js'; import type { RouteLifecycleManager } from './RouteLifecycleManager.js'; import type { TokensManager } from '../../transport/TokensManager.js'; import type { LongPollingManager } from '../../agents/LongPollingManager.js'; import type { Update } from '../../api/types/Update.generated.js'; import type { ILogger, LoggerOptions, ILoggerAware } from '../../types/logger.types.js'; /** * Configuration options for PollingIntegrationManager */ export interface PollingIntegrationManagerOptions extends LoggerOptions { /** Route configuration manager */ configManager: RouteConfigManager; /** Route lifecycle manager */ lifecycleManager: RouteLifecycleManager; /** Tokens manager */ tokensManager: TokensManager; /** Base URL for Telegram API */ baseUrl?: string; /** Update handler callback */ onUpdate?: (update: Update, routeId: string) => Promise; /** Error handler callback */ onError?: (error: Error, routeId: string) => void; } /** * Polling Integration Manager * Manages LongPollingManager integration and event handling * * Responsibilities: * - Create and configure LongPollingManager * - Subscribe to polling events * - Handle updates and route them to client * - Sync polling state with route status * - Provide polling statistics */ export declare class PollingIntegrationManager implements ILoggerAware { private readonly configManager; private readonly lifecycleManager; private readonly tokensManager; private readonly baseUrl; private readonly onUpdate?; private readonly onError?; private pollingManager?; /** Logger instance - mutable to support LoggerBinder.bind() */ logger?: ILogger; /** * Create a new PollingIntegrationManager instance * @param options - Configuration options */ constructor(options: PollingIntegrationManagerOptions); /** * Create LongPollingManager from route configurations * Filters routes in LongPolling mode and creates manager * * @returns Promise resolving to LongPollingManager instance * @throws {Error} If no routes configured for long polling */ createPollingManager(): Promise; /** * Set existing LongPollingManager instance * Useful when manager is created externally * * @param manager - LongPollingManager instance */ setPollingManager(manager: LongPollingManager): void; /** * Subscribe to LongPollingManager events * Syncs polling state with route status * * @param manager - LongPollingManager instance */ private subscribeToEvents; /** * Handle update from polling manager * Routes update to client's processUpdate handler * * @param update - Telegram update * @param routeId - Route identifier */ private handleUpdate; /** * Handle offset update from polling manager * Syncs offset with route status * * @param routeId - Route identifier * @param offset - New offset value */ private handleOffsetUpdate; /** * Handle worker failure * Deactivates route on permanent failure * * @param routeId - Route identifier * @param error - Error that caused the failure */ private handleWorkerFailed; /** * Handle error from polling manager * * @param error - Error object * @param routeId - Route identifier */ private handleError; /** * Start long polling * Starts the polling manager * * @throws {Error} If polling manager not set */ startPolling(): Promise; /** * Stop long polling * Stops the polling manager gracefully * * @throws {Error} If polling manager not set */ stopPolling(): Promise; /** * Check if polling is active for a specific route * * @param routeId - Route identifier * @returns True if polling worker is running for this route */ isPollingActive(routeId: string): boolean; /** * Get current offset for a route * * @param routeId - Route identifier * @returns Current offset or 0 */ getOffset(routeId: string): number; /** * Get polling statistics * * @returns Statistics object or undefined if manager not set */ getStats(): { totalWorkers: number; runningWorkers: number; stoppedWorkers: number; failedWorkers: number; } | undefined; /** * Get LongPollingManager instance * * @returns LongPollingManager or undefined */ getPollingManager(): LongPollingManager | undefined; /** * Check if polling manager is set * * @returns True if manager is set */ hasPollingManager(): boolean; }