Documentation - v0.27.1
    Preparing search index...

    Interface ITelegramClient

    interface ITelegramClient {
        appConfig: PublicPart<AppConfigManager>;
        log: Logger;
        onConnectionState: Emitter<ConnectionState>;
        onError: Emitter<Error>;
        onRawUpdate: Emitter<RawUpdateInfo>;
        onServerUpdate: Emitter<TypeUpdates>;
        platform: ICorePlatform;
        stopSignal: AbortSignal;
        storage: PublicPart<TelegramStorageManager>;
        timers: Pick<TimersManager, "create" | "cancel" | "exists">;
        call<T extends RpcMethod>(
            message: MustEqual<T, RpcMethod>,
            params?: RpcCallOptions,
        ): Promise<RpcCallReturn[T["_"]]>;
        changePrimaryDc(newDc: number): Promise<void>;
        computeNewPasswordHash(
            algo: TypePasswordKdfAlgo,
            password: string,
        ): Promise<Uint8Array<ArrayBufferLike>>;
        computeSrpParams(
            request: RawPassword,
            password: string,
        ): Promise<RawInputCheckPasswordSRP>;
        connect(): Promise<void>;
        destroy(): Promise<void>;
        disconnect(): Promise<void>;
        exportSession(): Promise<string>;
        getApiCredentials(): Promise<{ hash: string; id: number }>;
        getMtprotoMessageId(): Promise<Long>;
        getPoolSize(kind: ConnectionKind, dcId?: number): Promise<number>;
        getPrimaryDcId(): Promise<number>;
        handleClientUpdate(updates: TypeUpdates, noDispatch?: boolean): void;
        importSession(
            session: string | InputStringSessionData,
            force?: boolean,
        ): Promise<void>;
        notifyChannelClosed(channelId: number): Promise<boolean>;
        notifyChannelOpened(channelId: number, pts?: number): Promise<boolean>;
        notifyLoggedIn(auth: RawUser | TypeAuthorization): Promise<RawUser>;
        notifyLoggedOut(): Promise<void>;
        prepare(): Promise<void>;
        recreateDc(dcId: number): Promise<void>;
        startUpdatesLoop(): Promise<void>;
        stopUpdatesLoop(): Promise<void>;
    }
    Index

    Properties

    appConfig: PublicPart<AppConfigManager>

    App config manager

    log: Logger

    Logger for the client

    onConnectionState: Emitter<ConnectionState>

    Emitted when the connection state changes

    onError: Emitter<Error>

    Emitted when an error occurs

    onRawUpdate: Emitter<RawUpdateInfo>

    Emitted when an update is received from the server. Requires updates loop to be running

    onServerUpdate: Emitter<TypeUpdates>

    Emitted when a low-level Updates updates is received

    platform: ICorePlatform

    Platform used by the client

    stopSignal: AbortSignal

    Signal that will be aborted when the client is destroyed

    Storage manager

    timers: Pick<TimersManager, "create" | "cancel" | "exists">

    Timers manager

    Methods

    • Initialize the connection to the primary DC.

      You shouldn't usually call this method directly as it is called implicitly the first time you call call.

      Returns Promise<void>

    • Destroy the client and all its resources.

      This will terminate any connections to the Telegram servers, free all the resources, and make the client no longer usable

      Returns Promise<void>

    • Export current session to a single LONG string, containing all the needed information.

      Warning! Anyone with this string will be able to authorize as you and do anything. Treat this as your password, and never give it away!

      In case you have accidentally leaked this string, make sure to revoke this session in account settings: "Privacy & Security" > "Active sessions" > find the one containing mtcute > Revoke, or, in case this is a bot, revoke bot token with @BotFather

      Returns Promise<string>

    • Import the session from the given session string.

      Note that the session will only be imported in case the storage is missing authorization (i.e. does not contain auth key for the primary DC), otherwise it will be ignored (unless force).

      Parameters

      • session: string | InputStringSessionData

        Session string to import

      • Optionalforce: boolean

        Whether to overwrite existing session

      Returns Promise<void>

    • Notify the client that a channel has been opened

      Parameters

      • channelId: number
      • Optionalpts: number

      Returns Promise<boolean>

    • ADVANCED

      Do all the preparations, but don't connect just yet. Useful when you want to do some preparations before connecting, like setting up session.

      Call connect to actually connect.

      Returns Promise<void>