import { Connection } from "../network";
import { Session } from "../sessions";
import { Logger, PromisedNetSockets } from "../extensions";
import { Api } from "../tl";
import type { AuthKey } from "../crypto/AuthKey";
import { EntityCache } from "../entityCache";
import type { ParseInterface } from "./messageParse";
import type { EventBuilder } from "../events/common";
import { MTProtoSender } from "../network";
import { ApiSenderPool } from "../network/ApiSenderPool";
import { FilePool, FilePoolOptions } from "../network/FilePool";
import { ProxyInterface } from "../network/connection/TCPMTProxy";
import { Semaphore } from "async-mutex";
import { LogLevel } from "../extensions/Logger";
import Deferred from "../extensions/Deferred";
import { UpdateManager } from "./UpdateManager";
export declare const PROD_DC_IPV4: {
readonly [id: number]: string;
};
export declare const PROD_DC_IPV6: {
readonly [id: number]: string;
};
export declare const TEST_DC_IPV4: {
readonly [id: number]: string;
};
export declare const TEST_DC_IPV6: {
readonly [id: number]: string;
};
/**
* Interface for creating a new client.
* All of these have a default value and you should only change those if you know what you are doing.
*/
export interface TelegramClientParams {
/** The connection instance to be used when creating a new connection to the servers. It must be a type.
* Defaults to {@link ConnectionTCPFull}.
*/
connection?: typeof Connection;
/**
* Whether to connect to the servers through IPv6 or not. By default this is false.
*/
useIPV6?: boolean;
/**
* Whether to connect to Telegram's test environment instead of production.
*
* When `true`:
* - The client starts from test DC2 (`149.154.167.40`). DC routing follows the same
* path as production: `help.GetConfig` is the runtime source of truth, with the
* built-in test seed table (DC1/DC2/DC3) used as a fallback.
* - You must use a test phone number of the form `99966<4 digits>`; the login
* code is the DC digit repeated 5 times (e.g. `22222` for DC2).
* - Test sessions are not interchangeable with production sessions.
*
* Defaults to `false`.
*/
testServers?: boolean;
/**
* The timeout in seconds to be used when connecting. This does nothing for now.
*/
timeout?: number;
/**
* How many times a request should be retried.
* Request are retried when Telegram is having internal issues (due to INTERNAL error or RPC_CALL_FAIL error),
* when there is a errors.FloodWaitError less than floodSleepThreshold, or when there's a migrate error.
* defaults to 5.
*/
requestRetries?: number;
/**
* How many times the connection should retry, either on the initial connection or when Telegram disconnects us.
* May be set to a negative or undefined value for infinite retries, but this is not recommended, since the program can get stuck in an infinite loop.
* defaults to 5
*/
connectionRetries?: number;
/**
* How many times to reconnect before giving up. This happens after the initial connection is finished
* defaults to infinity
*/
reconnectRetries?: number;
/**
* Proxy configuration for routing all connections through a proxy server.
*
* Supports two proxy types:
* - **MTProxy** (`{ MTProxy: true, ip, port, secret }`) — Telegram's own obfuscated proxy.
* Automatically switches the connection to {@link ConnectionTCPMTProxyAbridged}.
* - **SOCKS4/5** (`{ socksType: 4 | 5, ip, port }`) — general-purpose SOCKS proxy.
* SOCKS5 supports optional `username`/`password` authentication.
*
* @see {@link ProxyInterface} for detailed type definitions and examples.
*/
proxy?: ProxyInterface;
/**
* How many times we should retry borrowing a sender from another DC when it fails. defaults to 5
*/
downloadRetries?: number;
/** The delay in milliseconds to sleep between automatic reconnections. defaults to 1000*/
retryDelay?: number;
/**Whether reconnection should be retried connection_retries times automatically if Telegram disconnects us or not. defaults to true */
autoReconnect?: boolean;
/** does nothing for now */
sequentialUpdates?: boolean;
/** The threshold below which the library should automatically sleep on flood wait and slow mode wait errors (inclusive).
* For instance, if a FloodWaitError for 17s occurs and floodSleepThreshold is 20s, the library will sleep automatically.
* If the error was for 21s, it would raise FloodWaitError instead. defaults to 60 sec.*/
floodSleepThreshold?: number;
/**
* Device model to be sent when creating the initial connection. Defaults to os.type().toString().
*/
deviceModel?: string;
/**
* System version to be sent when creating the initial connection. defaults to os.release().toString() -.
*/
systemVersion?: string;
/**
* App version to be sent when creating the initial connection. Defaults to 1.0.
*/
appVersion?: string;
/**
* Language code to be sent when creating the initial connection. Defaults to 'en'.
*/
langCode?: string;
/**
* System lang code to be sent when creating the initial connection. Defaults to 'en'.
*/
systemLangCode?: string;
/**
* Instance of Logger to use.
* If a `Logger` is given, it'll be used directly. If nothing is given, the default logger will be used.
* To create your own Logger make sure you extends teleproto logger {@link Logger} and override `log` method.
*/
baseLogger?: Logger;
/**
* Limits how many downloads happen at the same time.
*/
maxConcurrentDownloads?: number;
/**
* Whether to check for tampering in messages or not.
*/
securityChecks?: boolean;
/**
* What type of network connection to use.
*/
networkSocket?: typeof PromisedNetSockets;
/**
* Callback for handling reCAPTCHA verification.
* It should return the token obtained after solving the CAPTCHA.
*/
reCaptchaCallback?: (siteKey: string) => Promise;
/**
* File-download pool tuning. Defaults follow tdesktop: 1→8 sessions per DC,
* 128 KB parts, 15 s idle release. See {@link FilePoolOptions}.
*/
downloadPool?: Partial;
}
export declare abstract class TelegramBaseClient {
/** The current teleproto version. */
__version__: string;
/** @hidden */
_config?: Api.Config;
/** @hidden */
_appConfig?: {
[key: string]: any;
};
/** @hidden */
_log: Logger;
/** @hidden */
_floodSleepThreshold: number;
session: Session;
apiHash: string;
apiId: number;
/** @hidden */
_requestRetries: number;
/** @hidden */
_downloadRetries: number;
/** @hidden */
_connectionRetries: number;
/** @hidden */
_reconnectRetries: number;
/** @hidden */
_retryDelay: number;
/** @hidden */
_timeout: number;
/** @hidden */
_autoReconnect: boolean;
/** @hidden */
_connection: typeof Connection;
/** @hidden */
_initRequest: Api.InitConnection;
/** @hidden */
_sender?: MTProtoSender;
/** @hidden */
_floodWaitedRequests: any;
/** @hidden */
_bot?: boolean;
/** @hidden */
_useIPV6: boolean;
/** @hidden */
_testServers: boolean;
/** @hidden */
_selfInputPeer?: Api.InputPeerUser;
/** @hidden */
_errorHandler?: (error: Error) => Promise;
/** @hidden */
_eventBuilders: [EventBuilder, CallableFunction][];
/** @hidden */
_entityCache: EntityCache;
/** @hidden */
_lastRequest?: number;
/** @hidden */
_parseMode?: ParseInterface;
/** @hidden */
_reCaptchaCallback?: (siteKey: string) => Promise;
/** @hidden */
_ALBUMS: Map;
/** @hidden */
_apiSenderPool: ApiSenderPool;
/** @hidden */
_filePool: FilePool;
/** @hidden */
_loopStarted: boolean;
/** @hidden */
_reconnecting: boolean;
/** @hidden */
_destroyed: boolean;
/** @hidden */
_isSwitchingDc: boolean;
/** @hidden */
protected _proxy?: ProxyInterface;
/** @hidden */
_semaphore: Semaphore;
/** @hidden */
_securityChecks: boolean;
networkSocket: typeof PromisedNetSockets;
_connectedDeferred: Deferred;
/** Centralised pts/qts/seq tracker and gap recovery driver. */
updateManager: UpdateManager;
constructor(session: string | Session, apiId: number, apiHash: string, clientParams: TelegramClientParams);
get floodSleepThreshold(): number;
set floodSleepThreshold(value: number);
set maxConcurrentDownloads(value: number);
_initSession(): Promise;
get connected(): boolean | undefined;
disconnect(): Promise;
/** @hidden */
_teardownUpdateState(): void;
get disconnected(): boolean;
_disconnect(): Promise;
/**
* Disconnects all senders and removes all handlers
* Disconnect is safer as it will not remove your event handlers
*/
destroy(): Promise;
/** @hidden */
_authKeyCallback(authKey: AuthKey, dcId: number): Promise;
/** @hidden */
_connectSender(sender: MTProtoSender, dcId: number): Promise;
/** @hidden */
_makeSender(dcId: number, onBreak: (dcId: number) => void, authKey?: AuthKey): MTProtoSender;
/** @hidden */
getSender(dcId: number): Promise;
getDC(dcId: number, download: boolean): Promise<{
id: number;
ipAddress: string;
port: number;
}>;
invoke(request: R): Promise;
setLogLevel(level: LogLevel): void;
get logger(): Logger;
/**
* Custom error handler for the client
* @example
* ```ts
* client.onError = async (error)=>{
* console.log("error is",error)
* }
* ```
*/
set onError(handler: (error: Error) => Promise);
}