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
extends ClientAbstract
import { Client } from "https://deno.land/x/mtkruto@0.1.157/client/4_client.ts";

Constructors

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

Constructs the client.

Type Parameters

optional
C extends Context = Context

Properties

protected
stateChangeHandler: (connected: boolean) => void
api: Api
readonly
appVersion: string
readonly
deviceModel: string
invoke: { <T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>; <T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait: true): Promise<void>; <T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait?: boolean): Promise<T | void>; use(handler: InvokeErrorHandler<Client<C>>): void; }

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
messageStorage: Storage
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,
params?: AddReactionParams,
): Promise<void>

Make a reaction to a message.

addStoriesToHighlights(chatId: ID, storyIds: number[]): Promise<void>

Add multiple stories to highlights. User-only.

addStoryToHighlights(chatId: ID, storyId: number): Promise<void>

Add a single story to highlights. User-only.

answerCallbackQuery(id: string, params?: AnswerCallbackQueryParams): Promise<void>

Answer a callback query. Bot-only.

answerInlineQuery(
id: string,
results: InlineQueryResult[],
params?: AnswerInlineQueryParams,
): Promise<void>

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,
params?: BanChatMemberParams,
): Promise<void>

Ban a member from a chat.

blockUser(userId: ID): Promise<void>

Block a user. User-only.

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

createStory(
chatId: ID,
content: InputStoryContent,
params?: CreateStoryParams,
): Promise<Story>

Create a story. User-only.

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,
params?: DeleteMessageParams,
): Promise<void>

Delete a single message.

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

Delete multiple messages.

deleteStories(chatId: ID, storyIds: number[]): Promise<void>

Delete multiple stories. User-only.

deleteStory(chatId: ID, storyId: number): Promise<void>

Delete a single story. User-only.

Disable join requests in a chat. User-only.

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

Download a file.

editInlineMessageReplyMarkup(inlineMessageId: string, params?: EditMessageReplyMarkupParams)

Edit an inline message's reply markup.

editInlineMessageText(
inlineMessageId: string,
text: string,
params?: EditMessageParams,
): Promise<void>

Edit an inline message's text.

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

Edit a message's reply markup.

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

Edit a message's text.

enableJoinRequests(chatId: ID)

Enable join requests in a chat. User-only.

exportAuthString(): Promise<string>
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,
params?: ForwardMessagesParams,
): Promise<Message>

Forward a single message.

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

Forward multiple messages.

getChat(chatId: ID): Promise<Chat>

Get a chat.

getChatAdministrators(chatId: ID): Promise<ChatMember[]>

Get the administrators of 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.

getInactiveChats(): Promise<InactiveChat[]>

Get inactive chats. User-only.

getInputChannel(id: ID): Promise<types.InputChannel>
getInputPeer(id: ID): Promise<enums.InputPeer>
getInputUser(id: ID): Promise<types.InputUser>
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.

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>

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

getNetworkStatistics(): Promise<NetworkStatistics>

Get network statistics. This might not always be available.

getStories(chatId: ID, storyIds: number[]): Promise<Story[]>

Retrieve multiple stories. User-only.

getStory(chatId: ID, storyId: number): Promise<Story | null>

Retrieve a single story. User-only.

hideUsername(id: ID, username: string)

Hide a username from the current account, a bot account, a supergroup, or a channel's profile. User-only.

hideUsernames(id: ID): Promise<boolean>

Hide all usernames from the a supergroup or a channel's profile. User-only.

importAuthString(authString: string): Promise<void>
joinChat(chatId: ID): Promise<void>

Join a chat. User-only.

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

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

leaveChat(chatId: ID): Promise<void>

Leave a chat.

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

Pin a message in a chat.

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

Undo a reaction made to a message.

removeStoriesFromHighlights(chatId: ID, storyIds: number[]): Promise<void>

Remove multiple stories from highlights. User-only.

removeStoryFromHighlights(chatId: ID, storyId: number): Promise<void>

Remove a single story from highlights. User-only.

reorderUsernames(id: ID, order: string[]): Promise<boolean>

Reorder the usernames of the current account, a bot account, a supergroup, or a channel's profile. User-only.

searchMessages(
chatId: ID,
query: string,
params?: SearchMessagesParams,
): Promise<Message[]>

Search the messages of a chat.

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

Alias for invoke with its second parameter being true.

sendAnimation(
chatId: ID,
animation: FileSource,
params?: SendAnimationParams,
): 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; },
): Promise<void>

Send a chat action.

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

Send a contact.

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

Send a dice.

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

Send a document.

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

Send a location.

sendMessage(
chatId: ID,
text: string,
params?: SendMessageParams,
): 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,
params?: SendVideoNoteParams,
): 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.

setBoostsRequiredToCircumventRestrictions(chatId: ID, boosts: number): Promise<void>

Set the number of boosts required to circument a chat's default restrictions.

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

Set the rights of a chat member.

setChatPhoto(
chatId: number,
photo: FileSource,
params?: SetChatPhotoParams,
): 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.

setMyCommands(commands: BotCommand[], params?: SetMyCommandsParams): Promise<void>

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

setMyDescription(params?: { description?: string; languageCode?: string; }): Promise<void>

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

setMyName(params?: { name?: string; languageCode?: string; }): Promise<void>

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

setMyShortDescription(params?: { shortDescription?: string; languageCode?: string; }): Promise<void>

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

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

Change reactions made to a message.

showUsername(id: ID, username: string)

Show a username in the current account, a bot account, sa upergroup, or a channel's profile. User-only.

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

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

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

Unban a member from a chat.

unblockUser(userId: ID): Promise<void>

Unblock a user. User-only.

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): Promise<any>

Upload a file.

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