@vvlad1973/telegram-bot-client 2.0.0 → 2.0.2

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.
@@ -5,9 +5,8 @@
5
5
  * @module agents/workers/WorkerClientFactory
6
6
  */
7
7
  'use strict';
8
- import { TelegramTransport } from '../../transport/TelegramTransport.js';
9
8
  import { TelegramBotClient } from '../../client/TelegramBotClient.js';
10
- import { TokensManager } from '../../transport/TokensManager.js';
9
+ import { RouteMode } from '../../types/route.types.js';
11
10
  /**
12
11
  * Worker Client Factory
13
12
  * Creates and initializes transport and client for worker thread
@@ -18,22 +17,22 @@ export class WorkerClientFactory {
18
17
  */
19
18
  static createClient(config) {
20
19
  const { token, routeId, baseUrl, httpOptions } = config;
21
- // Create tokens manager
22
- const tokensManager = new TokensManager();
23
- tokensManager.addToken(routeId, token);
24
- tokensManager.setDefaultToken(routeId);
25
- // Create transport
26
- const transport = new TelegramTransport({
27
- tokens: tokensManager,
20
+ // Create client with route configuration
21
+ const client = new TelegramBotClient({
22
+ routes: {
23
+ token,
24
+ mode: RouteMode.LongPolling
25
+ },
26
+ defaultRouteId: routeId,
27
+ apiUrl: baseUrl,
28
28
  httpClientOptions: {
29
- baseUrl: baseUrl,
30
29
  timeout: httpOptions?.timeout,
31
30
  retries: httpOptions?.retries,
32
31
  retryDelay: httpOptions?.retryDelay,
33
32
  },
34
33
  });
35
- // Create client
36
- const client = new TelegramBotClient({ transport });
34
+ // Access transport through client's private property
35
+ const transport = client.transport;
37
36
  return { transport, client };
38
37
  }
39
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerClientFactory.js","sourceRoot":"","sources":["../../../src/agents/workers/WorkerClientFactory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,CAAC;AAEb,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OA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C;QACzC,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC;YACnC,MAAM,EAAE;gBACN,KAAK;gBACL,IAAI,EAAE,SAAS,CAAC,WAAW;aAC5B;YACD,cAAc,EAAE,OAAO;YACvB,MAAM,EAAE,OAAO;YACf,iBAAiB,EAAE;gBACjB,OAAO,EAAE,WAAW,EAAE,OAAO;gBAC7B,OAAO,EAAE,WAAW,EAAE,OAAO;gBAC7B,UAAU,EAAE,WAAW,EAAE,UAAU;aACpC;SACF,CAAC,CAAC;QAEH,qDAAqD;QACrD,MAAM,SAAS,GAAI,MAAsD,CAAC,SAAS,CAAC;QAEpF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAC/B,CAAC;CACF"}
@@ -9,6 +9,7 @@ import { parentPort, workerData } from 'worker_threads';
9
9
  import { PollingLoop } from './PollingLoop.js';
10
10
  import { WorkerCommandHandler } from './WorkerCommandHandler.js';
11
11
  import { TelegramBotClient } from '../../client/TelegramBotClient.js';
12
+ import { RouteMode } from '../../types/route.types.js';
12
13
  /**
13
14
  * Mock transport for testing
14
15
  */
@@ -49,7 +50,7 @@ const config = workerData.config;
49
50
  if (!config) {
50
51
  throw new Error('Worker config not provided in workerData');
51
52
  }
52
- const { routeId, timeout, limit, allowedUpdates, offset, mockUpdates } = config;
53
+ const { timeout, limit, allowedUpdates, offset, mockUpdates } = config;
53
54
  /**
54
55
  * Send message to main thread
55
56
  */
@@ -60,12 +61,26 @@ function sendMessage(msg) {
60
61
  * Create mock transport and client
61
62
  * For testing, we create a client with minimal route configuration
62
63
  */
63
- const transport = new MockTransport(mockUpdates || []);
64
- const client = new TelegramBotClient({ transport });
64
+ const mockTransport = new MockTransport(mockUpdates || []);
65
+ // Create client with dummy route configuration
66
+ // Note: when routes is an object (not array/Map), the routeId becomes 'default'
67
+ const client = new TelegramBotClient({
68
+ routes: {
69
+ token: config.token,
70
+ mode: RouteMode.LongPolling
71
+ }
72
+ });
73
+ // Replace the transport in client with mock transport (for testing purposes only)
74
+ // This is a hack but necessary for testing in worker thread
75
+ client.transport = mockTransport;
76
+ // Access the mock transport
77
+ const transport = mockTransport;
78
+ // Override routeId to 'default' since that's what's created from single route object
79
+ const actualRouteId = 'default';
65
80
  const pollingLoop = new PollingLoop({
66
81
  client,
67
82
  transport,
68
- routeId,
83
+ routeId: actualRouteId,
69
84
  timeout,
70
85
  limit,
71
86
  allowedUpdates,
@@ -74,7 +89,7 @@ const pollingLoop = new PollingLoop({
74
89
  });
75
90
  const commandHandler = new WorkerCommandHandler({
76
91
  pollingLoop,
77
- routeId,
92
+ routeId: actualRouteId,
78
93
  sendMessage,
79
94
  });
80
95
  /**
@@ -88,7 +103,7 @@ parentPort?.on('message', (msg) => {
88
103
  const err = error instanceof Error ? error : new Error(String(error));
89
104
  sendMessage({
90
105
  type: 'error',
91
- routeId,
106
+ routeId: actualRouteId,
92
107
  message: `Command handler error: ${err.message}`,
93
108
  stack: err.stack,
94
109
  });
@@ -101,7 +116,7 @@ process.on('unhandledRejection', (reason) => {
101
116
  const err = reason instanceof Error ? reason : new Error(String(reason));
102
117
  sendMessage({
103
118
  type: 'error',
104
- routeId,
119
+ routeId: actualRouteId,
105
120
  message: `Unhandled rejection: ${err.message}`,
106
121
  stack: err.stack,
107
122
  });
@@ -112,7 +127,7 @@ process.on('unhandledRejection', (reason) => {
112
127
  process.on('uncaughtException', (error) => {
113
128
  sendMessage({
114
129
  type: 'error',
115
- routeId,
130
+ routeId: actualRouteId,
116
131
  message: `Uncaught exception: ${error.message}`,
117
132
  stack: error.stack,
118
133
  });
@@ -1 +1 @@
1
- {"version":3,"file":"long-polling-worker-test.js","sourceRoot":"","sources":["../../../src/agents/workers/long-polling-worker-test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,CAAC;AAEb,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAA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AAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACzE,WAAW,CAAC;QACV,IAAI,EAAE,OAAO;QACb,OAAO;QACP,OAAO,EAAE,wBAAwB,GAAG,CAAC,OAAO,EAAE;QAC9C,KAAK,EAAE,GAAG,CAAC,KAAK;KACjB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAY,EAAE,EAAE;IAC/C,WAAW,CAAC;QACV,IAAI,EAAE,OAAO;QACb,OAAO;QACP,OAAO,EAAE,uBAAuB,KAAK,CAAC,OAAO,EAAE;QAC/C,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"long-polling-worker-test.js","sourceRoot":"","sources":["../../../src/agents/workers/long-polling-worker-test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,CAAC;AAEb,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIvD;;GAEG;AACH,MAAM,aAAa;IACT,YAAY,GAAG,CAAC,CAAC;IACjB,WAAW,CAAW;IACtB,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,WAAqB;QAC/B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,OAAO,CAAI,OAAgC;QAC/C,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC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,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACzE,WAAW,CAAC;QACV,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,aAAa;QACtB,OAAO,EAAE,wBAAwB,GAAG,CAAC,OAAO,EAAE;QAC9C,KAAK,EAAE,GAAG,CAAC,KAAK;KACjB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAY,EAAE,EAAE;IAC/C,WAAW,CAAC;QACV,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,aAAa;QACtB,OAAO,EAAE,uBAAuB,KAAK,CAAC,OAAO,EAAE;QAC/C,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { File } from './File.generated';
1
2
  import { Success } from './Success.generated';
2
- export interface GetFileResponseSuccess extends Success<boolean> {
3
+ export interface GetFileResponseSuccess extends Success<File> {
3
4
  }
@@ -1 +1 @@
1
- {"version":3,"file":"GetFileResponseSuccess.generated.js","sourceRoot":"","sources":["../../../src/api/types/GetFileResponseSuccess.generated.ts"],"names":[],"mappings":"AAEmE,CAAC"}
1
+ {"version":3,"file":"GetFileResponseSuccess.generated.js","sourceRoot":"","sources":["../../../src/api/types/GetFileResponseSuccess.generated.ts"],"names":[],"mappings":"AAGgE,CAAC"}
@@ -1,13 +1,19 @@
1
1
  /**
2
- * Telegram Bot Client with update processing, middleware, and event system
2
+ * Telegram Bot Client with route management, middleware, and event system
3
3
  *
4
4
  * @module client/TelegramBotClient
5
5
  */
6
6
  import type { Update } from '../api/types/index.js';
7
7
  import { BaseTelegramApi } from '../api/BaseTelegramApi.generated.js';
8
- import type { ITransport } from '../types/transport.types.js';
9
8
  import type { ContentTypeSuffix } from '../constants.js';
10
9
  import type { ILogger, LoggerOptions, ILoggerAware } from '../types/logger.types.js';
10
+ import type { RouteConfig, RouteMode } from '../types/route.types.js';
11
+ import type { HttpClientOptions } from '../types/http-client.types.js';
12
+ import type { IQueueProvider } from '../types/queue.types.js';
13
+ import { TelegramHttpClient } from '../transport/TelegramHttpClient.js';
14
+ import { RouteConfigManager } from './managers/RouteConfigManager.js';
15
+ import { RouteLifecycleManager } from './managers/RouteLifecycleManager.js';
16
+ import { PollingIntegrationManager } from './managers/PollingIntegrationManager.js';
11
17
  /**
12
18
  * Middleware function type
13
19
  */
@@ -33,38 +39,61 @@ export interface UpdateFilter {
33
39
  * Configuration options for TelegramBotClient
34
40
  */
35
41
  export interface TelegramBotClientOptions extends LoggerOptions {
36
- /** Transport instance for API communication */
37
- transport: ITransport;
42
+ /** Route configurations - can be single route, array, or Map */
43
+ routes: RouteConfig | RouteConfig[] | Map<string, RouteConfig>;
44
+ /** Default route ID (optional, defaults to first route) */
45
+ defaultRouteId?: string;
46
+ /** API base URL (default: https://api.telegram.org) */
47
+ apiUrl?: string;
48
+ /** Base URL for webhook templating (combined with webhook.path) */
49
+ webhookBaseUrl?: string;
50
+ /** Queue provider for queue-based mode (optional) */
51
+ queueProvider?: IQueueProvider;
52
+ /** HTTP client options */
53
+ httpClientOptions?: HttpClientOptions;
38
54
  }
39
55
  /**
40
- * TelegramBotClient extends BaseTelegramApi with update processing capabilities
56
+ * TelegramBotClient with Composition Pattern architecture
41
57
  *
42
58
  * Features:
43
59
  * - All Telegram API methods from BaseTelegramApi
60
+ * - Multi-route (multi-token) support
61
+ * - Route lifecycle management
44
62
  * - Update processing with middleware support
45
63
  * - Event-based subscriptions
46
64
  * - Filter-based update routing
47
65
  * - Message and callback wrappers
48
66
  * - LoggerTree integration support
67
+ * - Queue integration for production deployments
49
68
  *
50
69
  * @example
51
70
  * ```typescript
52
- * import { TelegramBotClient, TelegramTransport } from '@vvlad1973/telegram-bot-client';
71
+ * import { TelegramBotClient, RouteMode } from '@vvlad1973/telegram-bot-client';
53
72
  *
54
- * const transport = new TelegramTransport({
55
- * tokens: { default: 'BOT_TOKEN' }
73
+ * const bot = new TelegramBotClient({
74
+ * routes: { token: 'BOT_TOKEN', mode: RouteMode.LongPolling }
56
75
  * });
57
76
  *
58
- * const bot = new TelegramBotClient({ transport });
77
+ * await bot.init();
59
78
  *
60
79
  * bot.on('message.text', (wrapper) => {
61
80
  * wrapper.replyMessage('Echo: ' + wrapper.text);
62
81
  * });
82
+ *
83
+ * await bot.startPolling();
63
84
  * ```
64
85
  */
65
86
  export declare class TelegramBotClient extends BaseTelegramApi implements ILoggerAware {
87
+ /** Route configuration manager */
88
+ private readonly configManager;
89
+ /** Route lifecycle manager */
90
+ private readonly lifecycleManager;
91
+ /** Polling integration manager */
92
+ private readonly pollingIntegrationManager;
66
93
  /** Transport instance for API communication */
67
94
  private readonly transport;
95
+ /** Tokens manager */
96
+ private readonly tokensManager;
68
97
  /** Logger instance - mutable to support LoggerBinder.bind() */
69
98
  logger?: ILogger;
70
99
  /** Middleware stack */
@@ -73,11 +102,19 @@ export declare class TelegramBotClient extends BaseTelegramApi implements ILogge
73
102
  private totalReceived;
74
103
  /** Cache for deserialized filters (key: serialized filter string, value: deserialized filter) */
75
104
  private filterCache;
105
+ /**
106
+ * Public access to managers (readonly)
107
+ */
108
+ readonly managers: {
109
+ readonly config: RouteConfigManager;
110
+ readonly lifecycle: RouteLifecycleManager;
111
+ readonly polling: PollingIntegrationManager;
112
+ };
76
113
  /**
77
114
  * Create a new TelegramBotClient instance
78
- * @param options - Client configuration options (or transport for backward compatibility)
115
+ * @param options - Client configuration options
79
116
  */
80
- constructor(options: TelegramBotClientOptions | ITransport);
117
+ constructor(options: TelegramBotClientOptions);
81
118
  /**
82
119
  * Implementation of abstract callApi method from BaseTelegramApi
83
120
  * Delegates to transport.request() method
@@ -89,6 +126,53 @@ export declare class TelegramBotClient extends BaseTelegramApi implements ILogge
89
126
  * @returns Promise with API response
90
127
  */
91
128
  protected callApi<T>(methodName: string, params: Record<string, unknown>, routeId?: string, contentType?: keyof typeof ContentTypeSuffix): Promise<T>;
129
+ /**
130
+ * Initialize route (calls getMe and stores bot info)
131
+ * Delegates to RouteLifecycleManager
132
+ *
133
+ * @param routeId - Route identifier (optional, uses default if not specified)
134
+ * @returns Promise that resolves when route is initialized
135
+ */
136
+ init(routeId?: string): Promise<void>;
137
+ /**
138
+ * Activate route (set to specified mode)
139
+ * Delegates to RouteLifecycleManager
140
+ *
141
+ * @param routeId - Route identifier (optional, uses default if not specified)
142
+ * @param mode - Route mode (optional, uses configured mode from route config)
143
+ * @returns Promise that resolves when route is activated
144
+ */
145
+ activate(routeId?: string, mode?: RouteMode): Promise<void>;
146
+ /**
147
+ * Deactivate route (set to inactive mode)
148
+ * Delegates to RouteLifecycleManager
149
+ *
150
+ * @param routeId - Route identifier (optional, uses default if not specified)
151
+ * @returns Promise that resolves when route is deactivated
152
+ */
153
+ deactivate(routeId?: string): Promise<void>;
154
+ /**
155
+ * Start long polling for all routes configured with LongPolling mode
156
+ * Delegates to PollingIntegrationManager
157
+ *
158
+ * @returns Promise that resolves when polling is started
159
+ */
160
+ startPolling(): Promise<void>;
161
+ /**
162
+ * Stop long polling
163
+ * Delegates to PollingIntegrationManager
164
+ *
165
+ * @returns Promise that resolves when polling is stopped
166
+ */
167
+ stopPolling(): Promise<void>;
168
+ /**
169
+ * Set or update route configuration
170
+ * Delegates to RouteConfigManager
171
+ *
172
+ * @param id - Route identifier
173
+ * @param config - Route configuration
174
+ */
175
+ setRoute(id: string, config: RouteConfig): void;
92
176
  /**
93
177
  * Serialize filter to unique string key
94
178
  * Handles RegExp serialization properly
@@ -223,7 +307,7 @@ export declare class TelegramBotClient extends BaseTelegramApi implements ILogge
223
307
  * Process incoming update with middleware and event emission
224
308
  *
225
309
  * @param update - Telegram Update object
226
- * @param _context - Optional context object (e.g., { routeId: 'bot1' })
310
+ * @param context - Optional context object (e.g., { routeId: 'bot1' })
227
311
  * @returns Wrapped object (MessageWrapper, CallbackQueryWrapper, or raw data)
228
312
  *
229
313
  * @example
@@ -247,7 +331,7 @@ export declare class TelegramBotClient extends BaseTelegramApi implements ILogge
247
331
  * await client.processUpdate(update, { routeId: 'bot1' });
248
332
  * ```
249
333
  */
250
- processUpdate(update: Update, _context?: {
334
+ processUpdate(update: Update, context?: {
251
335
  routeId?: string;
252
336
  [key: string]: unknown;
253
337
  }): Promise<unknown>;
@@ -268,7 +352,7 @@ export declare class TelegramBotClient extends BaseTelegramApi implements ILogge
268
352
  * const buffer = await httpClient.downloadFile(url, { timeout: 60000 });
269
353
  * ```
270
354
  */
271
- getHttpClient(): any;
355
+ getHttpClient(): TelegramHttpClient;
272
356
  /**
273
357
  * Get bot token for specified route
274
358
  * Useful for constructing file download URLs and other operations
@@ -288,4 +372,159 @@ export declare class TelegramBotClient extends BaseTelegramApi implements ILogge
288
372
  * ```
289
373
  */
290
374
  getToken(routeId?: string): string;
375
+ /**
376
+ * Shutdown the client and close all resources (transport, polling, etc.)
377
+ * Should be called before application shutdown
378
+ *
379
+ * @returns Promise that resolves when all resources are closed
380
+ */
381
+ shutdown(): Promise<void>;
382
+ }
383
+ declare module './TelegramBotClient.js' {
384
+ interface TelegramBotClient {
385
+ /**
386
+ * Subscribe to an event
387
+ *
388
+ * Inherited from EventEmitter via BaseApi.
389
+ * TelegramBotClient supports the following event types:
390
+ * - Message types: 'message.text', 'message.photo', 'message.video', etc.
391
+ * - Commands: '/start', '/help', etc.
392
+ * - Update types: 'callback_query', 'inline_query', etc.
393
+ * - Wildcard: '*' for all updates
394
+ * - Filters: Use onFilter() for complex filtering
395
+ *
396
+ * @param eventName - Event name or filter
397
+ * @param listener - Event listener function
398
+ * @returns This client instance for chaining
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * // Subscribe to text messages
403
+ * bot.on('message.text', (wrapper: MessageWrapper) => {
404
+ * console.log('Text:', wrapper.text);
405
+ * });
406
+ *
407
+ * // Subscribe to commands
408
+ * bot.on('/start', (params, wrapper) => {
409
+ * wrapper.replyMessage('Welcome!');
410
+ * });
411
+ *
412
+ * // Subscribe to callback queries
413
+ * bot.on('callback_query', (wrapper: CallbackQueryWrapper) => {
414
+ * wrapper.answer('Button clicked!');
415
+ * });
416
+ *
417
+ * // Subscribe to all updates
418
+ * bot.on('*', (type, wrapper) => {
419
+ * console.log('Update type:', type);
420
+ * });
421
+ * ```
422
+ */
423
+ on(eventName: string | symbol, listener: (...args: any[]) => void): this;
424
+ /**
425
+ * Subscribe to an event (one time only)
426
+ *
427
+ * Inherited from EventEmitter via BaseApi.
428
+ *
429
+ * @param eventName - Event name
430
+ * @param listener - Event listener function
431
+ * @returns This client instance for chaining
432
+ */
433
+ once(eventName: string | symbol, listener: (...args: any[]) => void): this;
434
+ /**
435
+ * Remove event listener
436
+ *
437
+ * Inherited from EventEmitter via BaseApi.
438
+ *
439
+ * @param eventName - Event name
440
+ * @param listener - Event listener function to remove
441
+ * @returns This client instance for chaining
442
+ */
443
+ off(eventName: string | symbol, listener: (...args: any[]) => void): this;
444
+ /**
445
+ * Remove all listeners for an event, or all events
446
+ *
447
+ * Inherited from EventEmitter via BaseApi.
448
+ *
449
+ * @param eventName - Event name (optional, if not provided removes all listeners)
450
+ * @returns This client instance for chaining
451
+ */
452
+ removeAllListeners(eventName?: string | symbol): this;
453
+ /**
454
+ * Emit an event
455
+ *
456
+ * Inherited from EventEmitter via BaseApi.
457
+ *
458
+ * @param eventName - Event name
459
+ * @param args - Event arguments
460
+ * @returns true if the event had listeners, false otherwise
461
+ */
462
+ emit(eventName: string | symbol, ...args: any[]): boolean;
463
+ /**
464
+ * Get array of event names
465
+ *
466
+ * Inherited from EventEmitter via BaseApi.
467
+ *
468
+ * @returns Array of event names
469
+ */
470
+ eventNames(): (string | symbol)[];
471
+ /**
472
+ * Get listener count for an event
473
+ *
474
+ * Inherited from EventEmitter via BaseApi.
475
+ *
476
+ * @param eventName - Event name
477
+ * @returns Number of listeners
478
+ */
479
+ listenerCount(eventName: string | symbol): number;
480
+ /**
481
+ * Get listeners for an event
482
+ *
483
+ * Inherited from EventEmitter via BaseApi.
484
+ *
485
+ * @param eventName - Event name
486
+ * @returns Array of listener functions
487
+ */
488
+ listeners(eventName: string | symbol): ((...args: any[]) => void)[];
489
+ /**
490
+ * Add event listener (alias for on)
491
+ *
492
+ * Inherited from EventEmitter via BaseApi.
493
+ *
494
+ * @param eventName - Event name
495
+ * @param listener - Event listener function
496
+ * @returns This client instance for chaining
497
+ */
498
+ addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
499
+ /**
500
+ * Remove event listener (alias for off)
501
+ *
502
+ * Inherited from EventEmitter via BaseApi.
503
+ *
504
+ * @param eventName - Event name
505
+ * @param listener - Event listener function to remove
506
+ * @returns This client instance for chaining
507
+ */
508
+ removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
509
+ /**
510
+ * Prepend event listener (add to beginning of listeners array)
511
+ *
512
+ * Inherited from EventEmitter via BaseApi.
513
+ *
514
+ * @param eventName - Event name
515
+ * @param listener - Event listener function
516
+ * @returns This client instance for chaining
517
+ */
518
+ prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
519
+ /**
520
+ * Prepend one-time event listener (add to beginning of listeners array)
521
+ *
522
+ * Inherited from EventEmitter via BaseApi.
523
+ *
524
+ * @param eventName - Event name
525
+ * @param listener - Event listener function
526
+ * @returns This client instance for chaining
527
+ */
528
+ prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
529
+ }
291
530
  }