Skip to main content
Module

x/mtkruto/mod.ts>Client

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

Constructors

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

Constructs the client.

Type Parameters

optional
C extends Context = Context

Properties

protected
stateChangeHandler
api: Proxy
readonly
appVersion: string
readonly
deviceModel: string
invoke

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

readonly
langCode: string
readonly
langPack: string
readonly
parseMode: ParseMode
readonly
storage: Storage
readonly
systemLangCode: string
readonly
systemVersion: string

Methods

private
[getEntity](peer: types.PeerUser): Promise<types.User | null>
private
[getEntity](peer: types.PeerChat): Promise<types.Chat | null>
private
[getEntity](peer: types.PeerChannel): Promise<types.Channel | null>
private
[getMessageWithReply](chatId: ChatID, messageId: number): Promise<Message | null>
private
[getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?)
answerCallbackQuery(id: string, params?: AnswerCallbackQueryParams)

Answer a callback query. Bot-only.

answerInlineQuery(
id: string,
results: InlineQueryResult[],
params?: AnswerInlineQueryParams,
)

Answer an inline query. Bot-only.

authorize(params?: string | types.auth.ExportedAuthorization | AuthorizeUserParams)

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.
branch(
predicate: (ctx: C) => MaybePromise<boolean>,
trueHandler_: Middleware<C>,
falseHandler_: Middleware<C>,
)
checkGap(pts: number, ptsCount: number)
command(commands:
| string
| RegExp
| (string | RegExp)[]
| { names: string | RegExp | (string | RegExp)[]; prefixes: string | string[]; }
, ...middleawre: Middleware<FilterUpdate<C, "message", "text">>[]
)

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.

deleteMessage(
chatId: ChatID,
messageId: number,
params?: DeleteMessageParams,
): Promise<void>

Delete a single message.

deleteMessages(
chatId: ChatID,
messageIds: number[],
params?: DeleteMessagesParams,
): Promise<void>

Delete multiple messages.

download(fileId: string, params?: DownloadParams): Promise<AsyncGenerator<Uint8Array, void, unknown>>

Download a file.

editMessageText(
chatId: ChatID,
messageId: number,
text: string,
params?: EditMessageParams,
): Promise<With<Message, "text">>

Edit a message's text.

filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Middleware<C>[]): Composer<C>
forwardMessage(
from: ChatID,
to: ChatID,
messageId: number,
params?: ForwardMessagesParams,
): Promise<Message>

Forward a single message.

forwardMessages(
from: ChatID,
to: ChatID,
messageIds: number[],
params?: ForwardMessagesParams,
): Promise<Message[]>

Forward multiple messages.

getInputPeer(id: ChatID)
getMe(): Promise<User>

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[]): Promise<Omit<Message, "replyToMessage">[]>

Retrieve multiple messages.

getMyCommands(params?: GetMyCommandsParams): Promise<BotCommand[]>

Get the bot's commands in the given scope and/or language. Bot-only.

getMyDescription(params?: { languageCode?: string; }): Promise<string>

Get the bot's description in the given language. Bot-only.

getMyName(params?: { languageCode?: string; }): Promise<string>

Set the bot's name in the given language. Bot-only.

getMyShortDescription(params?: { languageCode?: string; }): Promise<string>

Get the bot's short description in the given language. Bot-only.

getUserAccessHash(userId: bigint)
on<T extends keyof Update, F extends string>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...middleawre: Middleware<FilterUpdate<C, T, F>>[])
processResult(result: ReadObject)
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T)

Alias for invoke with its second parameter being true.

sendChatAction(
chatId: ChatID,
action: ChatAction,
params?: { messageThreadId?: number; },
)

Send a chat action.

sendMessage(
chatId: ChatID,
text: string,
params?: SendMessageParams,
): Promise<With<Message, "text">>

Send a text message.

sendPhoto(
chatId: ChatID,
photo: FileSource,
params?: SendPhotoParams,
): Promise<With<Message, "photo">>

Send a photo.

sendPoll(
chatId: ChatID,
question: string,
options: [string, string, ...string[]],
params?: SendPollParams,
): Promise<With<Message, "poll">>

Send a poll.

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.

setMyCommands(commands: BotCommand[], params?: SetMyCommandsParams)

Set the bot's commands in the given scope and/or language. Bot-only.

setMyDescription(unnamed 0: { description?: string; languageCode?: string; })

Set the bot's description in the given language. Bot-only.

setMyName(unnamed 0: { name?: string; languageCode?: string; })

Set the bot's name in the given language. Bot-only.

setMyShortDescription(unnamed 0: { shortDescription?: string; languageCode?: string; })

Set the bot's short description in the given language. Bot-only.

start(params?: string | types.auth.ExportedAuthorization | AuthorizeUserParams)

Same as calling .connect() followed by .authorize(params) if the session didn't have an auth key.

upload(contents: Uint8Array, params?: UploadParams)

Upload a file.

use(...middleware: Middleware<C>[])