Class TelegramWorkerPort<Custom>Abstract

Type Parameters

Hierarchy (View Summary)

Implements

Constructors

Properties

appConfig: AppConfigManagerProxy

App config manager

changePrimaryDc: (newDc: number) => Promise<void>

Change the primary DC

computeNewPasswordHash: (
    algo: TypePasswordKdfAlgo,
    password: string,
) => Promise<Uint8Array>

Compute new password hash for the given algorithm and password

computeSrpParams: (
    request: RawPassword,
    password: string,
) => Promise<RawInputCheckPasswordSRP>

Compute SRP parameters for the given password

destroy_: () => Promise<void>

Type declaration

    • (): 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>

disconnect: () => Promise<void>

Terminate any connections to the Telegram servers, but keep the client usable

exportSession: () => Promise<string>

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

getApiCredentials: () => Promise<{ hash: string; id: number }>

Get the API credentials for use in authorization methods

getMtprotoMessageId: () => Promise<Long>

Generate a new time-based MTProto message ID

getPoolSize: (kind: ConnectionKind, dcId?: number) => Promise<number>

Get the number of connections of the given kind

getPrimaryDcId: () => Promise<number>

Get the primary DC ID

handleClientUpdate: (updates: TypeUpdates, noDispatch?: boolean) => void

Handle an update sent by the server in response to an RPC call

Type declaration

    • (updates: TypeUpdates, noDispatch?: boolean): void
    • Parameters

      • updates: TypeUpdates

        Updates to handle

      • OptionalnoDispatch: boolean

        Whether the updates inside should not be dispatched as events

      Returns void

importSession: (
    session: string | InputStringSessionData,
    force?: boolean,
) => Promise<void>

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).

Type declaration

    • (session: string | InputStringSessionData, force?: boolean): Promise<void>
    • Parameters

      • session: string | InputStringSessionData

        Session string to import

      • Optionalforce: boolean

        Whether to overwrite existing session

      Returns Promise<void>

Logger for the client

notifyChannelClosed: (channelId: number) => Promise<boolean>

Notify the client that a channel has been closed

notifyChannelOpened: (channelId: number, pts?: number) => Promise<boolean>

Notify the client that a channel has been opened

notifyLoggedIn: (auth: RawUser | TypeAuthorization) => Promise<RawUser>

Notify the client that the user has logged in

notifyLoggedOut: () => Promise<void>

Notify the client that the user has logged out

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

prepare: () => Promise<void>

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.

recreateDc: (dcId: number) => Promise<void>

ADVANCED Recreate the given DC, forcefully using the IP taken from server config.

startUpdatesLoop: () => Promise<void>

Start the updates loop

stopSignal: AbortSignal = ...

Signal that will be aborted when the client is destroyed

stopUpdatesLoop: () => Promise<void>

Stop the updates loop

storage: TelegramStorageProxy

Storage manager

timers: TimersManager

Timers manager

workerId: string

Methods

  • Call an RPC method

    Type Parameters

    • T extends RpcMethod

    Parameters

    Returns Promise<RpcCallReturn[T["_"]]>

  • 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

    Parameters

    • terminate: boolean = false

    Returns Promise<void>

  • Type Parameters

    • T extends string | number | symbol

    Parameters

    Returns Promise<ReturnType<Custom[T]>>