Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/mtkruto/client/4_client.ts>Client

Cross-runtime JavaScript library for building Telegram clients
Go to Latest
class Client
import { Client } from "https://deno.land/x/mtkruto@0.1.141/client/4_client.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
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 | types.ChatForbidden | null>
private
[getEntity](peer: types.PeerChannel): Promise<types.Channel | types.ChannelForbidden | null>
private
[getEntity](peer: types.PeerUser | types.PeerChat | types.PeerChannel): Promise<
| types.User
| types.Chat
| types.ChatForbidden
| types.Channel
| types.ChannelForbidden
| null
>
addReaction(
chatId: number,
messageId: number,
reaction: Reaction,
): Promise<void>

Make a reaction to a message.

Answer a callback query. Bot-only.

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.
banChatMember(
chatId: ID,
memberId: ID,
): Promise<void>

Ban a member from a chat.

branch(
predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>,
falseHandler_: Middleware<UpdateIntersection<C>>,
)
command(commands:
| string
| RegExp
| (string | RegExp)[]
| { names: string | RegExp | (string | RegExp)[]; prefixes: string | string[]; }
, ...middleawre: Middleware<WithFilter<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.

deleteChatMemberMessages(chatId: ID, memberId: ID): Promise<void>

Delete all messages sent by a specific member of a chat.

deleteChatPhoto(chatId: number): Promise<void>

Delete a chat's photo.

deleteMessage(
chatId: ID,
messageId: number,
): Promise<void>

Delete a single message.

deleteMessages(
chatId: ID,
messageIds: number[],
): Promise<void>

Delete multiple messages.

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

Download a file.

editMessageReplyMarkup(
chatId: ID,
messageId: number,
): Promise<Message>

Edit a message's reply markup.

editMessageText(
chatId: ID,
messageId: number,
text: string,
): Promise<MessageText>

Edit a message's text.

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

Forward a single message.

forwardMessages(
from: ID,
to: ID,
messageIds: number[],
): Promise<Message[]>

Forward multiple messages.

getChat(chatId: ID): Promise<Chat>

Get a chat.

getChats(params?: GetChatsParams): Promise<Chat[]>

Get chats from a chat list. User-only.

getCustomEmojiDocuments(id: string | string[]): Promise<Document[]>

Get custom emoji documents for download.

getHistory(chatId: ID, params?: GetHistoryParams): Promise<Message[]>

Get chat history. User-only.

getMe(): Promise<User>

Get information on the currently authorized user.

getMessage(chatId: ID, messageId: number): Promise<Message | null>

Retrieve a single message.

getMessages(chatId: ID, messageIds: number[]): Promise<Message[]>

Retrieve multiple messages.

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.

Get network statistics. This might not always be available.

kickChatMember(chatId: ID, memberId: ID): Promise<void>

Kick a member from a chat. Same as a banChatMember call followed by unbanChatMember.

on<Q extends FilterQuery>(filter: Q, ...middleawre: Middleware<WithFilter<C, Q>>[])
pinMessage(
chatId: ID,
messageId: number,
): Promise<void>

Pin a message in a chat.

removeReaction(
chatId: number,
messageId: number,
reaction: Reaction,
): Promise<void>

Undo a reaction made to a message.

send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T)

Alias for invoke with its second parameter being true.

sendAnimation(
chatId: ID,
animation: FileSource,
): Promise<MessageAnimation>

Send an animation.

sendAudio(
chatId: ID,
audio: FileSource,
params?: SendAudioParams,
): Promise<MessageAudio>

Send an audio file.

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

Send a chat action.

sendContact(
chatId: ID,
firstName: string,
number: string,
): Promise<MessageContact>

Send a contact.

sendDice(chatId: ID, params?: SendDiceParams): Promise<MessageDice>

Send a dice.

sendDocument(
chatId: ID,
document: FileSource,
): Promise<MessageDocument>

Send a document.

sendLocation(
chatId: ID,
latitude: number,
longitude: number,
): Promise<MessageLocation>

Send a location.

sendMessage(
chatId: ID,
text: string,
): Promise<MessageText>

Send a text message.

sendPhoto(
chatId: ID,
photo: FileSource,
params?: SendPhotoParams,
): Promise<MessagePhoto>

Send a photo.

sendPoll(
chatId: ID,
question: string,
options: [string, string, ...string[]],
params?: SendPollParams,
): Promise<MessagePoll>

Send a poll.

sendVenue(
chatId: ID,
latitude: number,
longitude: number,
title: string,
address: string,
params?: SendVenueParams,
): Promise<MessageVenue>

Send a venue.

sendVideo(
chatId: ID,
video: FileSource,
params?: SendVideoParams,
): Promise<MessageVideo>

Send a video.

sendVideoNote(
chatId: ID,
videoNote: FileSource,
): Promise<MessageVideoNote>

Send a video note.

sendVoice(
chatId: ID,
voice: FileSource,
params?: SendVoiceParams,
): Promise<MessageVoice>

Send a voice message.

setAvailableReactions(chatId: ID, availableReactions: "none" | "all" | Reaction[]): Promise<void>

Set a chat's available reactions.

setChatMemberRights(
chatId: ID,
memberId: ID,
): Promise<void>

Set the rights of a chat member.

setChatPhoto(
chatId: number,
photo: FileSource,
): Promise<void>

Set a chat's photo.

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.

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

setMyDescription(params?: { description?: string; languageCode?: string; })

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

setMyName(params?: { name?: string; languageCode?: string; })

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

setMyShortDescription(params?: { shortDescription?: string; languageCode?: string; })

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

setReactions(
chatId: number,
messageId: number,
reactions: Reaction[],
): Promise<void>

Change reactions made to a message.

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

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

unbanChatMember(chatId: ID, memberId: ID): Promise<void>

Unban a member from a chat.

unpinMessage(chatId: ID, messageId: number): Promise<void>

Unpin a pinned message.

unpinMessages(chatId: ID): Promise<void>

Unpin all pinned messages.

upload(contents: Uint8Array, params?: UploadParams)

Upload a file.

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