Skip to main content
Module

x/mtkruto/mod.ts>Client

[WIP] Cross-runtime JavaScript library for building Telegram clients
Go to Latest
class Client
import { Client } from "https://deno.land/x/mtkruto@0.0.985/mod.ts";

Constructors

new
Client(
storage?: Storage,
apiId?: number | null,
apiHash?: string | null,
params?: ClientParams,
cdn?,
)

Constructs the client.

Properties

private
auth: { key: Uint8Array; id: bigint; } | null
private
readonly
autoStart: boolean
private
autoStarted: boolean
private
connectionInited: boolean
private
lastMsgId: bigint
private
promises: Map<bigint, { resolve: (obj: ReadObject) => void; reject: (err: ReadObject) => void; }>
private
readonly
optional
publicKeys: PublicKeys
private
sessionId
private
state: { salt: bigint; seqNo: number; }
private
storageInited: boolean
private
toAcknowledge: Set<bigint>
private
updateApplicationMutex: Mutex
private
updateGapRecoveryMutex: Mutex
private
updateProcessLock: Mutex
private
optional
updateState: types.UpdatesState
readonly
appVersion: string
readonly
deviceModel: string
readonly
langCode: string
readonly
langPack: string
readonly
parseMode: ParseMode
readonly
systemLangCode: string
readonly
systemVersion: string
updateHandler: UpdateHandler

Methods

private
applyUpdate(update: types.TypeUpdate | types.TypeUpdates): Promise<void>
private
applyUpdateNoGap(update: types.TypeUpdate, usePts?): Promise<void>
private
downloadInner(location: types.TypeInputFileLocation, dcId?: number)
private
fetchState(source: string)
private
getLocalState()
private
pingLoop()
private
processChats(chats: types.TypeChat[])
private
processUpdates(updates: types.TypeUpdate | types.TypeUpdates, release?: MutexInterface.Releaser)
private
processUsers(users: types.TypeUser[])
private
receiveLoop()
private
recoverChannelUpdateGap(channelId: bigint, source: string)
private
recoverUpdateGap(source: string)
private
setAuth(key: Uint8Array)
private
setUpdateStateDate(date: number)
private
updatesToMessages(chatId: ChatID, updates: types.TypeUpdates)

Calls initConnection and authorizes the client with one of the following:

  • Bot token (string)
  • Exported authorization (types.AuthExportedAuthorization)
  • User authorization handlers (AuthorizeUserParams)

if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling updates.getState.

Notes:

  1. Requires the apiId and apiHash paramters to be passed when constructing the client.
  2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
  3. The parameters passed to the initConnection call can be configured with the last parameter of the constructor.

Loads the session if setDc was not called, initializes and connnects a ClientPlain to generate auth key if there was none, and connects the client. Before establishing the connection, the session is saved.

download(fileId: string)

Download a file.

editMessageText(
chatId: ChatID,
messageId: number,
text: string,
)

Edit a message's text.

forwardMessage(
from: ChatID,
to: ChatID,
messageId: number,
)

Forward a single message.

forwardMessages(
from: ChatID,
to: ChatID,
messageIds: number[],
)

Forward multiple messages.

Get information on the currently authorized user.

getMessage(chatId: ChatID, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>

Retrieve a single message.

getMessages(chatId_: ChatID, messageIds: number[])

Retrieve multiple messages.

invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>

Invokes a function waiting and returning its reply if the second parameter is not true. Requires the client to be connected.

invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait: true): Promise<void>
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T)

Alias for invoke with its second parameter being true.

sendMessage(
chatId: ChatID,
text: string,
)

Send a text message.

setDc(dc: DC)

Sets the DC and resets the auth key stored in the session provider if the stored DC was not the same as the dc parameter.

Same as calling .connect() followed by .authorize(params).

[getEntity](peer: types.PeerUser): Promise<types.User | null>
[getEntity](peer: types.PeerChat): Promise<types.Chat | null>