/** * @module transport/TelegramHttpClient * @description HTTP client implementation using Native Fetch API for Telegram Bot API */ import { IHttpClient, HttpClientOptions, HttpRequestOptions, TelegramResponse } from '../types/http-client.types.js'; import type { ILogger, LoggerOptions, ILoggerAware } from '../types/logger.types.js'; /** * HTTP error class for Telegram API errors * @deprecated Use TelegramApiError from errors module instead */ export declare class TelegramHttpError extends Error { readonly statusCode?: number | undefined; readonly errorCode?: number | undefined; readonly retryAfter?: number | undefined; constructor(message: string, statusCode?: number | undefined, errorCode?: number | undefined, retryAfter?: number | undefined); } /** * HTTP client implementation using Native Fetch API * Provides automatic retries, exponential backoff, and timeout handling */ export declare class TelegramHttpClient implements IHttpClient, ILoggerAware { /** Telegram Bot API version */ static readonly apiVersion: string; private readonly baseUrl; private readonly timeout; private readonly retries; private readonly retryDelay; private readonly exponentialBackoff; private readonly userAgent; /** Logger instance - mutable to support LoggerBinder.bind() */ logger?: ILogger; /** Instance accessor for API version */ get apiVersion(): string; /** * Create a new TelegramHttpClient instance * @param options - HTTP client configuration options with optional logger */ constructor(options?: HttpClientOptions & LoggerOptions); /** * Execute an HTTP request to Telegram Bot API * @param token - Bot token * @param method - API method name (e.g., 'sendMessage') * @param params - Request parameters * @param options - Request-specific options * @returns Promise with API response (full Telegram response object with ok and result fields) */ request(token: string, method: string, params?: object, options?: HttpRequestOptions): Promise>; /** * Calculate retry delay with exponential backoff * @param attempt - Current attempt number (0-based) * @param baseDelay - Base delay in milliseconds * @returns Delay in milliseconds */ private calculateRetryDelay; /** * Build HTTP headers for the request * @param contentType - Content type for the request * @param customHeaders - Custom headers to include * @returns Headers object */ private buildHeaders; /** * Build request body based on content type * @param params - Request parameters * @param contentType - Content type for the request * @returns Request body */ private buildBody; /** * Build multipart/form-data body * @param params - Request parameters * @returns FormData object */ private buildMultipartBody; /** * Flatten nested parameters for form-urlencoded * @param params - Parameters to flatten * @returns Flattened parameters */ private flattenParams; /** * Delay execution for specified milliseconds * @param ms - Milliseconds to delay * @returns Promise that resolves after the delay */ private delay; /** * Download file from URL as ArrayBuffer * Uses the same retry/timeout logic as API requests * * @param url - File URL to download * @param options - Request options (timeout, retries, etc.) * @returns File content as ArrayBuffer * * @example * ```typescript * const buffer = await httpClient.downloadFile( * 'https://example.com/file.pdf', * { timeout: 60000, retries: 5 } * ); * ``` */ downloadFile(url: string, options?: HttpRequestOptions): Promise; /** * Download file from URL as ReadableStream * Note: Streams don't support retries - use downloadFile for retry logic * * @param url - File URL to download * @param options - Request options (only timeout is used) * @returns File content as ReadableStream * * @example * ```typescript * const stream = await httpClient.downloadFileStream(url); * // Pipe to file (Node.js) * import { pipeline } from 'stream/promises'; * import { Readable } from 'stream'; * await pipeline(Readable.fromWeb(stream), fs.createWriteStream('file.pdf')); * ``` */ downloadFileStream(url: string, options?: HttpRequestOptions): Promise; }