Skip to main content
Module

x/mtkruto/mod.ts>Client

Cross-runtime JavaScript library for building Telegram clients
Go to Latest
class Client
extends Composer<C>
import { Client } from "https://deno.land/x/mtkruto@0.1.190/mod.ts";

An MTKruto client.

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

api: Api
readonly
appVersion: string
readonly
connected: boolean
readonly
deviceModel: string
readonly
disconnected: boolean
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,
)

Make a reaction to a message.

addStoriesToHighlights(chatId: ID, storyIds: number[])

Add multiple stories to highlights. User-only.

addStoryToHighlights(chatId: ID, storyId: number)

Add a single story to highlights. User-only.

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

Ban a member from a chat.

blockUser(userId: ID)

Block a user. User-only.

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,
): Promise<Story>

Create a story. User-only.

deleteChatMemberMessages(chatId: ID, memberId: ID)

Delete all messages sent by a specific member of a chat. User-only.

deleteChatPhoto(chatId: number)

Delete a chat's photo.

Delete a chat's sticker set.

deleteMessage(
chatId: ID,
messageId: number,
)

Delete a single message.

deleteMessages(
chatId: ID,
messageIds: number[],
)

Delete multiple messages.

deleteStories(chatId: ID, storyIds: number[])

Delete multiple stories. User-only.

deleteStory(chatId: ID, storyId: number)

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.

editInlineMessageLiveLocation(
inlineMessageId: string,
latitude: number,
longitude: number,
)

Edit an inline message's live location. Bot-only.

Edit an inline message's reply markup. Bot-only.

editInlineMessageText(
inlineMessageId: string,
text: string,
)

Edit an inline message's text. Bot-only.

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

Edit a message's live location.

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.

Enable join requests in a chat. User-only.

exportAuthString(): Promise<string>
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.

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

Get the administrators of a chat.

getChatMember(chatId: ID, userId: ID): Promise<ChatMember>

Get information on a user's chat membership.

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

Get chats from a chat list. User-only.

getCustomEmojiStickers(id: string | string[]): Promise<Sticker[]>

Get custom emoji documents for download.

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

Get chat history. User-only.

Get inactive chats. User-only.

getInputChannel(id: ID): Promise<types.InputChannel>

Get a channel or a supergroup's inputChannel. Useful when calling API functions directly.

getInputPeer(id: ID): Promise<enums.InputPeer>

Get a chat's inputPeer. Useful when calling API functions directly.

getInputUser(id: ID): Promise<types.InputUser>

Get a user's inputUser. Useful when calling API functions directly.

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>

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.

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)
joinChat(chatId: ID)

Join a chat. User-only.

kickChatMember(chatId: ID, memberId: ID)

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

leaveChat(chatId: ID)

Leave a chat.

pinMessage(
chatId: ID,
messageId: number,
)

Pin a message in a chat.

removeReaction(
chatId: number,
messageId: number,
reaction: Reaction,
)

Undo a reaction made to a message.

removeStoriesFromHighlights(chatId: ID, storyIds: number[])

Remove multiple stories from highlights. User-only.

removeStoryFromHighlights(chatId: ID, storyId: number)

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

Search the messages of a chat. User-only.

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

sendSticker(
chatId: ID,
sticker: FileSource,
): Promise<MessageSticker>

Send a sticker.

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[])

Set a chat's available reactions. User-only.

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

setChatMemberRights(
chatId: ID,
memberId: ID,
)

Set the rights of a chat member.

setChatPhoto(
chatId: number,
photo: FileSource,
)

Set a chat's photo.

setChatStickerSet(chatId: ID, setName: string)

Set a chat's sticker set.

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[],
)

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

stopPoll(
chatId: ID,
messageId: number,
params?: StopPollParams,
): Promise<Poll>

Stop a poll.

unbanChatMember(chatId: ID, memberId: ID)

Unban a member from a chat.

unblockUser(userId: ID)

Unblock a user. User-only.

unpinMessage(chatId: ID, messageId: number)

Unpin a pinned message.

unpinMessages(chatId: ID)

Unpin all pinned messages.

upload(contents: Uint8Array, params?: UploadParams): Promise<any>

Upload a file.