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

x/mtkruto/mod.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.6.3/mod.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, R = T["_"] extends keyof Api.Functions ? Api.ReturnType<T> extends never ? Api.ReturnType<Api.Functions[T["_"]]> : never : never>(function_: T): Promise<R>; <T extends Api.AnyObject>(function_: T, noWait: true): Promise<void>; <T extends Api.AnyObject, R = T["_"] extends keyof Api.Functions ? Api.ReturnType<T> extends never ? Api.ReturnType<Api.Functions[T["_"]]> : never : 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
managers: Record<string, any>
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,
params?: AddChatMemberParams,
): 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,
params?: AddReactionParams,
)

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.

answerCallbackQuery(id: string, params?: AnswerCallbackQueryParams)

Answer a callback query. Bot-only.

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

Answer an inline query. Bot-only.

answerPreCheckoutQuery(
preCheckoutQueryId: string,
ok: boolean,
params?: AnswerPreCheckoutQueryParams,
): 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,
params?: BanChatMemberParams,
)

Ban a member from a chat.

blockUser(userId: ID)

Block a user. User-only.

closeChat(chatId: ID): Promise<void>

Close a chat previously opened by openChat. 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.

createChannel(title: string, params?: CreateChannelParams): Promise<ChatPChannel>

Create a channel. User-only.

createGroup(title: string, params?: CreateGroupParams): Promise<ChatPGroup>

Create a group. User-only.

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

Create a story. User-only.

createSupergroup(title: string, params?: CreateSupergroupParams): Promise<ChatPSupergroup>

Create a supergroup. 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,
params?: DeleteMessageParams,
)

Delete a single message.

deleteMessages(
chatId: ID,
messageIds: number[],
params?: DeleteMessagesParams,
)

Delete multiple messages.

deleteScheduledMessage(chatId: ID, messageId: number)

Delete a scheduled message.

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

Delete multiple scheduled 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,
params?: DownloadLiveStreamChunkParams,
): AsyncGenerator<Uint8Array, void, unknown>

Download a live stream chunk. User-only.

editInlineMessageLiveLocation(
inlineMessageId: string,
latitude: number,
longitude: number,
params?: EditMessageLiveLocationParams,
)

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

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

Edit an inline message's media.

editInlineMessageReplyMarkup(inlineMessageId: string, params?: EditMessageReplyMarkupParams)

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

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

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

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

Edit a message's live location.

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

Edit a message's media.

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

getBusinessConnection(id: string): Promise<BusinessConnection>

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.

getChatMembers(chatId: ID, params?: GetChatMembersParams): Promise<ChatMember[]>

Get the members of a chat.

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.

getInactiveChats(): Promise<InactiveChat[]>

Get inactive chats. User-only.

getInputChannel(id: ID): Promise<Api.inputChannel | Api.inputChannelFromMessage>

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

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

getLiveStreamChannels(id: string): Promise<LiveStreamChannel[]>

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.

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.

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

openChat(chatId: ID): Promise<void>

Open a chat. User-only.

pinMessage(
chatId: ID,
messageId: number,
params?: PinMessageParams,
)

Pin a message in a chat.

readMessages(chatId: number, untilMessageId: number): Promise<void>

Mark messages as read. User-only.

reconnect(dc?: DC)
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.

scheduleVideoChat(
chatId: ID,
startAt: Date,
params?: ScheduleVideoChatParams,
): Promise<VideoChatScheduled>

Schedule a video chat. User-only.

searchMessages(
chatId: ID,
query: string,
params?: SearchMessagesParams,
): 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,
params?: SendAnimationParams,
): Promise<MessageAnimation>

Send an animation.

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

Send an audio file.

sendCallbackQuery(
chatId: ID,
messageId: number,
question: CallbackQueryQuestion,
): 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,
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.

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

Send an inline query. User-only.

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

Send an invoice. Bot-only.

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

Send a location.

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

Send a media group.

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.

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

Send a scheduled message before its schedule.

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

Send multiple scheduled messages before their schedule.

sendSticker(
chatId: ID,
sticker: FileSource,
params?: SendStickerParams,
): 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,
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[])

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

setBoostsRequiredToCircumventRestrictions(chatId: ID, boosts: number)

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

setChatMemberRights(
chatId: ID,
memberId: ID,
params?: SetChatMemberRightsParams,
)

Set the rights of a chat member.

setChatPhoto(
chatId: number,
photo: FileSource,
params?: SetChatPhotoParams,
)

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.

setMessageTtl(chatId: ID, messageTtl: number): Promise<void>

Set the time to live of the messages of a chat. User-only.

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

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.

setOnline(online: boolean): Promise<void>

Set the current account's online status. User-only.

setReactions(
chatId: number,
messageId: number,
reactions: Reaction[],
params?: SetReactionsParams,
)

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.

signIn(params?: SignInParams)

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.
start(params?: SignInParams)

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

startBot(botId: number, params?: StartBotParams): Promise<Message>

Start a bot. User-only.

startVideoChat(chatId: ID, params?: StartVideoChatParams): Promise<VideoChatActive>

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,
params?: UnpinMessageParams,
)

Unpin a pinned message.

unpinMessages(chatId: ID)

Unpin all pinned messages.