Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

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

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

An MTKruto client.

Constructors

new
Client(params?: ClientParams)

Constructs the client.

Type Parameters

optional
C extends Context = Context

Properties

readonly
appVersion: string
readonly
connected: boolean
readonly
deviceModel: string
readonly
disconnected: boolean
invoke: { <T extends Api.AnyObject<P>, P extends Api.Function, R extends unknown = T["_"] extends keyof Api.Functions ? Api.ReturnType<Api.Functions[T["_"]]> : never>(function_: T): Promise<R>; <T extends Api.AnyObject<P>, P extends Api.Function>(function_: T, noWait: true): Promise<void>; <T extends Api.AnyObject<P>, P extends Api.Function, R extends unknown = T["_"] extends keyof Api.Functions ? Api.ReturnType<Api.Functions[T["_"]]> : never>(function_: T, noWait?: boolean): Promise<R | 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: StorageOperations
readonly
storage: StorageOperations
readonly
systemLangCode: string
readonly
systemVersion: string

Methods

private
[getEntity](peer: Api.peerUser): Promise<Api.user | null>
private
[getEntity](peer: Api.peerChat): Promise<Api.chat | Api.chatForbidden | null>
private
[getEntity](peer: Api.peerChannel): Promise<Api.channel | Api.channelForbidden | null>
private
[getEntity](peer: Api.peerUser | Api.peerChat | Api.peerChannel): Promise<
| Api.user
| Api.chat
| Api.chatForbidden
| Api.channel
| Api.channelForbidden
| null
>
addChatMember(
chatId: ID,
userId: ID,
): Promise<FailedInvitation[]>

Add a single user to a chat.

addChatMembers(chatId: ID, userIds: ID[]): Promise<FailedInvitation[]>

Add multiple users at once to a channel or a supergroup.

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.

answerPreCheckoutQuery(
preCheckoutQueryId: string,
ok: boolean,
): Promise<void>

Answer a pre-checkout query. Bot-only.

approveJoinRequest(chatId: ID, userId: ID): Promise<void>

Approve a join request.

approveJoinRequests(chatId: ID, params?: ApproveJoinRequestsParams): Promise<void>

Approve all join requests. User-only.

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.

declineJoinRequest(chatId: ID, userId: ID): Promise<void>

Decline a join request.

declineJoinRequests(chatId: ID, params?: DeclineJoinRequestsParams): Promise<void>

Decline all join requests. 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.

downloadLiveStreamChunk(
id: string,
channelId: number,
scale: number,
timestamp: number,
): AsyncGenerator<Uint8Array, void, unknown>

Download a live stream chunk. User-only.

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

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

editInlineMessageMedia(
inlineMessageId: string,
media: InputMedia,
): Promise<void>

Edit an inline message's media.

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

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

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.

editMessageMedia(
chatId: ID,
messageId: number,
media: InputMedia,
): Promise<Message>

Edit a message's media.

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.

Get a business connection. Bot-only.

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

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<Api.inputChannel>

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

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

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

getInputUser(id: ID): Promise<Api.inputUser>

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

Get live stream channels. 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>

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.

getVideoChat(id: string): Promise<VideoChat>

Get a video chat. 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.

joinLiveStream(id: string): Promise<void>

Join a live stream. User-only.

joinVideoChat(
id: string,
params_: string,
): Promise<string>

Join a video 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.

leaveVideoChat(id: string): Promise<void>

Leave a video chat. User-only.

pinMessage(
chatId: ID,
messageId: number,
)

Pin a message in a chat.

refundStarPayment(userId: ID, telegramPaymentChargeId: string): Promise<void>

Refund a star payment. Bot-only.

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.

Schedule a video chat. User-only.

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

Search the messages of a chat. User-only.

send<T extends Api.AnyObject<P>, P extends Api.Function>(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.

sendCallbackQuery(
chatId: ID,
messageId: number,
): Promise<CallbackQueryAnswer>

Send a callback query. User-only.

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.

sendInlineQuery(
userId: ID,
chatId: ID,
): Promise<InlineQueryAnswer>

Send an inline query. User-only.

sendInvoice(
chatId: ID,
title: string,
description: string,
payload: string,
currency: string,
prices: PriceTag[],
): Promise<MessageInvoice>

Send an invoice.

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

Send a location.

sendMediaGroup(
chatId: ID,
media: InputMedia[],
): Promise<Message[]>

Send a media group.

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, a supergroup, or a channel's profile. User-only.

Signs in using the provided parameters if not already signed in. If no parameters are provided, the credentials will be prompted in runtime.

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.

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

Start a video chat. User-only.

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.