/** * Route Lifecycle Manager * Manages route initialization, activation, deactivation, and hot reload * * @module client/managers/RouteLifecycleManager */ import type { RouteConfigManager } from './RouteConfigManager.js'; import type { BaseTelegramApi } from '../../api/BaseTelegramApi.generated.js'; import type { RouteStatus, RouteMode } from '../../types/route.types.js'; import type { ILogger, LoggerOptions, ILoggerAware } from '../../types/logger.types.js'; /** * Configuration options for RouteLifecycleManager */ export interface RouteLifecycleManagerOptions extends LoggerOptions { /** Route configuration manager */ configManager: RouteConfigManager; /** API client for webhook and bot info operations */ apiClient: BaseTelegramApi; /** * Base URL for webhooks (optional) * Combined with route's webhook.path to form full webhook URL * Example: 'https://example.com/webhooks' */ webhookBaseUrl?: string; } /** * Route Lifecycle Manager * Manages route initialization, activation, deactivation, and mode switching * * Responsibilities: * - Initialize routes (getMe, store bot info) * - Activate routes (set webhooks, prepare for polling) * - Deactivate routes (delete webhooks, stop polling) * - Switch between modes (webhook ↔ longPolling ↔ inactive) * - Hot reload routes (apply configuration changes) * - Manage route status */ export declare class RouteLifecycleManager implements ILoggerAware { private readonly configManager; private readonly apiClient; private readonly webhookBaseUrl?; /** Logger instance - mutable to support LoggerBinder.bind() */ logger?: ILogger; /** * Create a new RouteLifecycleManager instance * @param options - Configuration options */ constructor(options: RouteLifecycleManagerOptions); /** * Initialize a route * Calls getMe to fetch bot info and stores it in route config * * @param routeId - Route identifier (uses default if not specified) * @throws {Error} If route not found or initialization fails */ initRoute(routeId?: string): Promise; /** * Initialize all routes * Calls initRoute for each configured route */ initAllRoutes(): Promise; /** * Activate a route in specified mode * For webhook mode: calls setWebhook * For longPolling mode: prepares route status * For inactive mode: does nothing * * @param routeId - Route identifier * @param mode - Mode to activate (uses route's configured mode if not specified) * @throws {Error} If route not found or activation fails */ activateRoute(routeId: string, mode?: RouteMode): Promise; /** * Resolve webhook URL from route configuration * Priority: webhook.url > webhook.path + webhookBaseUrl * * @param routeId - Route identifier * @param webhook - Webhook configuration * @returns Resolved webhook URL * @throws {Error} If URL cannot be resolved */ private resolveWebhookUrl; /** * Activate webhook mode for a route * Calls setWebhook with route's webhook configuration * * @param routeId - Route identifier * @param route - Route configuration */ private activateWebhook; /** * Activate long polling mode for a route * Deletes webhook and prepares status for polling * * @param routeId - Route identifier * @param route - Route configuration */ private activateLongPolling; /** * Deactivate a route * For webhook mode: deletes webhook * For longPolling mode: marks as inactive (actual polling stop handled by PollingIntegrationManager) * * @param routeId - Route identifier * @throws {Error} If route not found or deactivation fails */ deactivateRoute(routeId: string): Promise; /** * Switch route to a different mode * Deactivates current mode and activates new mode * * @param routeId - Route identifier * @param newMode - New mode to activate * @throws {Error} If route not found or mode switch fails */ switchMode(routeId: string, newMode: RouteMode): Promise; /** * Get route status * * @param routeId - Route identifier * @returns Route status or undefined */ getStatus(routeId: string): RouteStatus | undefined; /** * Set route status * Use with caution - normally status is managed internally * * @param routeId - Route identifier * @param status - Route status */ setStatus(routeId: string, status: RouteStatus): void; /** * Hot reload a route * Applies configuration changes without full restart * If route is active, deactivates and reactivates it * * @param routeId - Route identifier * @throws {Error} If route not found or reload fails */ reloadRoute(routeId: string): Promise; /** * Hot reload all routes * Applies configuration changes to all routes */ reloadAllRoutes(): Promise; }