import * as tg from './core/types/typegram'; import * as tt from './telegram-types'; import { Deunionize, PropOr, UnionKeys } from './deunionize'; import ApiClient from './core/network/client'; import { Guard, Guarded, MaybeArray } from './core/helpers/util'; import Telegram from './telegram'; import { FmtString } from './format'; type Tail = T extends [unknown, ...infer U] ? U : never; type Shorthand> = Tail>; /** * Narrows down `C['update']` (and derived getters) * to specific update type `U`. * * Used by [[`Composer`]], * possibly useful for splitting a bot into multiple files. */ export type NarrowedContext = Context & Omit; export type FilteredContext> = Filter extends tt.UpdateType ? NarrowedContext>> : NarrowedContext>; export declare class Context = tg.Update> { readonly update: U; readonly telegram: Telegram; readonly botInfo: tg.UserFromGetMe; readonly state: Record; constructor(update: U, telegram: Telegram, botInfo: tg.UserFromGetMe); get updateType(): Extract, tt.UpdateType>; get me(): string; /** * @deprecated Use ctx.telegram instead */ get tg(): Telegram; get message(): PropOr; get editedMessage(): PropOr; get inlineQuery(): PropOr; get shippingQuery(): PropOr; get preCheckoutQuery(): PropOr; get chosenInlineResult(): PropOr; get channelPost(): PropOr; get editedChannelPost(): PropOr; get callbackQuery(): PropOr; get poll(): PropOr; get pollAnswer(): PropOr; get myChatMember(): PropOr; get chatMember(): PropOr; get chatJoinRequest(): PropOr; get chat(): Getter; get senderChat(): PropOr, "sender_chat", undefined>; get from(): PropOr, "from", undefined>; get inlineMessageId(): string | undefined; get passportData(): tg.PassportData | undefined; get webAppData(): { data: { json(): T; text(): string; }; button_text: string; } | undefined; /** * @deprecated use {@link Telegram.webhookReply} */ get webhookReply(): boolean; set webhookReply(enable: boolean); has>(filters: MaybeArray): this is FilteredContext; /** * @see https://core.telegram.org/bots/api#answerinlinequery */ answerInlineQuery(...args: Shorthand<'answerInlineQuery'>): Promise; /** * @see https://core.telegram.org/bots/api#answercallbackquery */ answerCbQuery(...args: Shorthand<'answerCbQuery'>): Promise; /** * @see https://core.telegram.org/bots/api#answercallbackquery */ answerGameQuery(...args: Shorthand<'answerGameQuery'>): Promise; /** * @see https://core.telegram.org/bots/api#answershippingquery */ answerShippingQuery(...args: Shorthand<'answerShippingQuery'>): Promise; /** * @see https://core.telegram.org/bots/api#answerprecheckoutquery */ answerPreCheckoutQuery(...args: Shorthand<'answerPreCheckoutQuery'>): Promise; /** * @see https://core.telegram.org/bots/api#editmessagetext */ editMessageText(text: string | FmtString, extra?: tt.ExtraEditMessageText): Promise; /** * @see https://core.telegram.org/bots/api#editmessagecaption */ editMessageCaption(caption: string | FmtString | undefined, extra?: tt.ExtraEditMessageCaption): Promise; /** * @see https://core.telegram.org/bots/api#editmessagemedia */ editMessageMedia(media: tt.WrapCaption, extra?: tt.ExtraEditMessageMedia): Promise; /** * @see https://core.telegram.org/bots/api#editmessagereplymarkup */ editMessageReplyMarkup(markup: tg.InlineKeyboardMarkup | undefined): Promise; /** * @see https://core.telegram.org/bots/api#editmessagelivelocation */ editMessageLiveLocation(latitude: number, longitude: number, extra?: tt.ExtraEditMessageLiveLocation): Promise; /** * @see https://core.telegram.org/bots/api#stopmessagelivelocation */ stopMessageLiveLocation(markup?: tg.InlineKeyboardMarkup): Promise; /** * @see https://core.telegram.org/bots/api#sendmessage */ sendMessage(text: string | FmtString, extra?: tt.ExtraReplyMessage): Promise; /** * @see https://core.telegram.org/bots/api#sendmessage */ reply(...args: Shorthand<'sendMessage'>): Promise; /** * @see https://core.telegram.org/bots/api#getchat */ getChat(...args: Shorthand<'getChat'>): Promise; /** * @see https://core.telegram.org/bots/api#exportchatinvitelink */ exportChatInviteLink(...args: Shorthand<'exportChatInviteLink'>): Promise; /** * @see https://core.telegram.org/bots/api#createchatinvitelink */ createChatInviteLink(...args: Shorthand<'createChatInviteLink'>): Promise; /** * @see https://core.telegram.org/bots/api#editchatinvitelink */ editChatInviteLink(...args: Shorthand<'editChatInviteLink'>): Promise; /** * @see https://core.telegram.org/bots/api#revokechatinvitelink */ revokeChatInviteLink(...args: Shorthand<'revokeChatInviteLink'>): Promise; /** * @see https://core.telegram.org/bots/api#banchatmember */ banChatMember(...args: Shorthand<'banChatMember'>): Promise; /** * @see https://core.telegram.org/bots/api#banchatmember * @deprecated since API 5.3. Use {@link Context.banChatMember} */ get kickChatMember(): (userId: number, untilDate?: number | undefined, extra?: Omit<{ chat_id: string | number; user_id: number; until_date?: number | undefined; revoke_messages?: boolean | undefined; }, "chat_id" | "user_id" | "until_date"> | undefined) => Promise; /** * @see https://core.telegram.org/bots/api#unbanchatmember */ unbanChatMember(...args: Shorthand<'unbanChatMember'>): Promise; /** * @see https://core.telegram.org/bots/api#restrictchatmember */ restrictChatMember(...args: Shorthand<'restrictChatMember'>): Promise; /** * @see https://core.telegram.org/bots/api#promotechatmember */ promoteChatMember(...args: Shorthand<'promoteChatMember'>): Promise; /** * @see https://core.telegram.org/bots/api#setchatadministratorcustomtitle */ setChatAdministratorCustomTitle(...args: Shorthand<'setChatAdministratorCustomTitle'>): Promise; /** * @see https://core.telegram.org/bots/api#setchatphoto */ setChatPhoto(...args: Shorthand<'setChatPhoto'>): Promise; /** * @see https://core.telegram.org/bots/api#deletechatphoto */ deleteChatPhoto(...args: Shorthand<'deleteChatPhoto'>): Promise; /** * @see https://core.telegram.org/bots/api#setchattitle */ setChatTitle(...args: Shorthand<'setChatTitle'>): Promise; /** * @see https://core.telegram.org/bots/api#setchatdescription */ setChatDescription(...args: Shorthand<'setChatDescription'>): Promise; /** * @see https://core.telegram.org/bots/api#pinchatmessage */ pinChatMessage(...args: Shorthand<'pinChatMessage'>): Promise; /** * @see https://core.telegram.org/bots/api#unpinchatmessage */ unpinChatMessage(...args: Shorthand<'unpinChatMessage'>): Promise; /** * @see https://core.telegram.org/bots/api#unpinallchatmessages */ unpinAllChatMessages(...args: Shorthand<'unpinAllChatMessages'>): Promise; /** * @see https://core.telegram.org/bots/api#leavechat */ leaveChat(...args: Shorthand<'leaveChat'>): Promise; /** * @see https://core.telegram.org/bots/api#setchatpermissions */ setChatPermissions(...args: Shorthand<'setChatPermissions'>): Promise; /** * @see https://core.telegram.org/bots/api#getchatadministrators */ getChatAdministrators(...args: Shorthand<'getChatAdministrators'>): Promise<(tg.ChatMemberOwner | tg.ChatMemberAdministrator)[]>; /** * @see https://core.telegram.org/bots/api#getchatmember */ getChatMember(...args: Shorthand<'getChatMember'>): Promise; /** * @see https://core.telegram.org/bots/api#getchatmembercount */ getChatMembersCount(...args: Shorthand<'getChatMembersCount'>): Promise; /** * @see https://core.telegram.org/bots/api#setpassportdataerrors */ setPassportDataErrors(errors: readonly tg.PassportElementError[]): Promise; /** * @see https://core.telegram.org/bots/api#sendphoto */ sendPhoto(photo: string | tg.InputFile, extra?: tt.ExtraPhoto): Promise; /** * @see https://core.telegram.org/bots/api#sendphoto */ replyWithPhoto(...args: Shorthand<'sendPhoto'>): Promise; /** * @see https://core.telegram.org/bots/api#sendmediagroup */ sendMediaGroup(media: tt.MediaGroup, extra?: tt.ExtraMediaGroup): Promise<(tg.Message.DocumentMessage | tg.Message.AudioMessage | tg.Message.PhotoMessage | tg.Message.VideoMessage)[]>; /** * @see https://core.telegram.org/bots/api#sendmediagroup */ replyWithMediaGroup(...args: Shorthand<'sendMediaGroup'>): Promise<(tg.Message.DocumentMessage | tg.Message.AudioMessage | tg.Message.PhotoMessage | tg.Message.VideoMessage)[]>; /** * @see https://core.telegram.org/bots/api#sendaudio */ sendAudio(audio: string | tg.InputFile, extra?: tt.ExtraAudio): Promise; /** * @see https://core.telegram.org/bots/api#sendaudio */ replyWithAudio(...args: Shorthand<'sendAudio'>): Promise; /** * @see https://core.telegram.org/bots/api#senddice */ sendDice(extra?: tt.ExtraDice): Promise; /** * @see https://core.telegram.org/bots/api#senddice */ replyWithDice(...args: Shorthand<'sendDice'>): Promise; /** * @see https://core.telegram.org/bots/api#senddocument */ sendDocument(document: string | tg.InputFile, extra?: tt.ExtraDocument): Promise; /** * @see https://core.telegram.org/bots/api#senddocument */ replyWithDocument(...args: Shorthand<'sendDocument'>): Promise; /** * @see https://core.telegram.org/bots/api#sendsticker */ sendSticker(sticker: string | tg.InputFile, extra?: tt.ExtraSticker): Promise; /** * @see https://core.telegram.org/bots/api#sendsticker */ replyWithSticker(...args: Shorthand<'sendSticker'>): Promise; /** * @see https://core.telegram.org/bots/api#sendvideo */ sendVideo(video: string | tg.InputFile, extra?: tt.ExtraVideo): Promise; /** * @see https://core.telegram.org/bots/api#sendvideo */ replyWithVideo(...args: Shorthand<'sendVideo'>): Promise; /** * @see https://core.telegram.org/bots/api#sendanimation */ sendAnimation(animation: string | tg.InputFile, extra?: tt.ExtraAnimation): Promise; /** * @see https://core.telegram.org/bots/api#sendanimation */ replyWithAnimation(...args: Shorthand<'sendAnimation'>): Promise; /** * @see https://core.telegram.org/bots/api#sendvideonote */ sendVideoNote(videoNote: string | tg.InputFileVideoNote, extra?: tt.ExtraVideoNote): Promise; /** * @see https://core.telegram.org/bots/api#sendvideonote */ replyWithVideoNote(...args: Shorthand<'sendVideoNote'>): Promise; /** * @see https://core.telegram.org/bots/api#sendinvoice */ sendInvoice(invoice: tt.NewInvoiceParameters, extra?: tt.ExtraInvoice): Promise; /** * @see https://core.telegram.org/bots/api#sendinvoice */ replyWithInvoice(...args: Shorthand<'sendInvoice'>): Promise; /** * @see https://core.telegram.org/bots/api#sendgame */ sendGame(game: string, extra?: tt.ExtraGame): Promise; /** * @see https://core.telegram.org/bots/api#sendgame */ replyWithGame(...args: Shorthand<'sendGame'>): Promise; /** * @see https://core.telegram.org/bots/api#sendvoice */ sendVoice(voice: string | tg.InputFile, extra?: tt.ExtraVoice): Promise; /** * @see https://core.telegram.org/bots/api#sendvoice */ replyWithVoice(...args: Shorthand<'sendVoice'>): Promise; /** * @see https://core.telegram.org/bots/api#sendpoll */ sendPoll(poll: string, options: readonly string[], extra?: tt.ExtraPoll): Promise; /** * @see https://core.telegram.org/bots/api#sendpoll */ replyWithPoll(...args: Shorthand<'sendPoll'>): Promise; /** * @see https://core.telegram.org/bots/api#sendpoll */ sendQuiz(quiz: string, options: readonly string[], extra?: tt.ExtraPoll): Promise; /** * @see https://core.telegram.org/bots/api#sendpoll */ replyWithQuiz(...args: Shorthand<'sendQuiz'>): Promise; /** * @see https://core.telegram.org/bots/api#stoppoll */ stopPoll(...args: Shorthand<'stopPoll'>): Promise; /** * @see https://core.telegram.org/bots/api#sendchataction */ sendChatAction(action: Shorthand<'sendChatAction'>[0], extra?: tt.ExtraSendChatAction): Promise; /** * @see https://core.telegram.org/bots/api#sendchataction * * Sends the sendChatAction request repeatedly, with a delay between requests, * as long as the provided callback function is being processed. * * The sendChatAction errors should be ignored, because the goal is the actual long process completing and performing an action. * * @param action - chat action type. * @param callback - a function to run along with the chat action. * @param extra - extra parameters for sendChatAction. * @param {number} [extra.intervalDuration=8000] - The duration (in milliseconds) between subsequent sendChatAction requests. */ persistentChatAction(action: Shorthand<'sendChatAction'>[0], callback: () => Promise, { intervalDuration, ...extra }?: tt.ExtraSendChatAction & { intervalDuration?: number; }): Promise; /** * @deprecated use {@link Context.sendChatAction} instead * @see https://core.telegram.org/bots/api#sendchataction */ replyWithChatAction(...args: Shorthand<'sendChatAction'>): Promise; /** * @see https://core.telegram.org/bots/api#sendlocation */ sendLocation(latitude: number, longitude: number, extra?: tt.ExtraLocation): Promise; /** * @see https://core.telegram.org/bots/api#sendlocation */ replyWithLocation(...args: Shorthand<'sendLocation'>): Promise; /** * @see https://core.telegram.org/bots/api#sendvenue */ sendVenue(latitude: number, longitude: number, title: string, address: string, extra?: tt.ExtraVenue): Promise; /** * @see https://core.telegram.org/bots/api#sendvenue */ replyWithVenue(...args: Shorthand<'sendVenue'>): Promise; /** * @see https://core.telegram.org/bots/api#sendcontact */ sendContact(phoneNumber: string, firstName: string, extra?: tt.ExtraContact): Promise; /** * @see https://core.telegram.org/bots/api#sendcontact */ replyWithContact(...args: Shorthand<'sendContact'>): Promise; /** * @deprecated use {@link Telegram.getStickerSet} * @see https://core.telegram.org/bots/api#getstickerset */ getStickerSet(setName: string): Promise; /** * @see https://core.telegram.org/bots/api#setchatstickerset */ setChatStickerSet(setName: string): Promise; /** * @see https://core.telegram.org/bots/api#deletechatstickerset */ deleteChatStickerSet(): Promise; /** * Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this * to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a * ForumTopic object. * * @see https://core.telegram.org/bots/api#createforumtopic */ createForumTopic(...args: Shorthand<'createForumTopic'>): Promise; /** * Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in * the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the * topic. Returns True on success. * * @see https://core.telegram.org/bots/api#editforumtopic */ editForumTopic(extra: tt.ExtraEditForumTopic): Promise; /** * Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. * Returns True on success. * * @see https://core.telegram.org/bots/api#closeforumtopic */ closeForumTopic(): Promise; /** * Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. * Returns True on success. * * @see https://core.telegram.org/bots/api#reopenforumtopic */ reopenForumTopic(): Promise; /** * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an * administrator in the chat for this to work and must have the can_delete_messages administrator rights. * Returns True on success. * * @see https://core.telegram.org/bots/api#deleteforumtopic */ deleteForumTopic(): Promise; /** * Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat * for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success. * * @see https://core.telegram.org/bots/api#unpinallforumtopicmessages */ unpinAllForumTopicMessages(): Promise; /** * Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator * in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success. * * @see https://core.telegram.org/bots/api#editgeneralforumtopic */ editGeneralForumTopic(name: string): Promise; /** * Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success. * * @see https://core.telegram.org/bots/api#closegeneralforumtopic */ closeGeneralForumTopic(): Promise; /** * Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in * the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically * unhidden if it was hidden. Returns True on success. * * @see https://core.telegram.org/bots/api#reopengeneralforumtopic */ reopenGeneralForumTopic(): Promise; /** * Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat * for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed * if it was open. Returns True on success. * * @see https://core.telegram.org/bots/api#hidegeneralforumtopic */ hideGeneralForumTopic(): Promise; /** * Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success. * * @see https://core.telegram.org/bots/api#unhidegeneralforumtopic */ unhideGeneralForumTopic(): Promise; /** * Use this method to clear the list of pinned messages in a General forum topic. * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator * right in the supergroup. * * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) * * @see https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages */ unpinAllGeneralForumTopicMessages(): Promise; /** * @deprecated use {@link Telegram.setStickerPositionInSet} * @see https://core.telegram.org/bots/api#setstickerpositioninset */ setStickerPositionInSet(sticker: string, position: number): Promise; /** * @deprecated use {@link Telegram.setStickerSetThumbnail} * @see https://core.telegram.org/bots/api#setstickersetthumbnail */ setStickerSetThumb(...args: Parameters): Promise; setStickerSetThumbnail(...args: Parameters): Promise; setStickerMaskPosition(...args: Parameters): Promise; setStickerKeywords(...args: Parameters): Promise; setStickerEmojiList(...args: Parameters): Promise; deleteStickerSet(...args: Parameters): Promise; setStickerSetTitle(...args: Parameters): Promise; setCustomEmojiStickerSetThumbnail(...args: Parameters): Promise; /** * @deprecated use {@link Telegram.deleteStickerFromSet} * @see https://core.telegram.org/bots/api#deletestickerfromset */ deleteStickerFromSet(sticker: string): Promise; /** * @see https://core.telegram.org/bots/api#uploadstickerfile */ uploadStickerFile(...args: Shorthand<'uploadStickerFile'>): Promise; /** * @see https://core.telegram.org/bots/api#createnewstickerset */ createNewStickerSet(...args: Shorthand<'createNewStickerSet'>): Promise; /** * @see https://core.telegram.org/bots/api#addstickertoset */ addStickerToSet(...args: Shorthand<'addStickerToSet'>): Promise; /** * @deprecated use {@link Telegram.getMyCommands} * @see https://core.telegram.org/bots/api#getmycommands */ getMyCommands(): Promise; /** * @deprecated use {@link Telegram.setMyCommands} * @see https://core.telegram.org/bots/api#setmycommands */ setMyCommands(commands: readonly tg.BotCommand[]): Promise; /** * @deprecated use {@link Context.replyWithMarkdownV2} * @see https://core.telegram.org/bots/api#sendmessage */ replyWithMarkdown(markdown: string, extra?: tt.ExtraReplyMessage): Promise; /** * @see https://core.telegram.org/bots/api#sendmessage */ replyWithMarkdownV2(markdown: string, extra?: tt.ExtraReplyMessage): Promise; /** * @see https://core.telegram.org/bots/api#sendmessage */ replyWithHTML(html: string, extra?: tt.ExtraReplyMessage): Promise; /** * @see https://core.telegram.org/bots/api#deletemessage */ deleteMessage(messageId?: number): Promise; /** * @see https://core.telegram.org/bots/api#forwardmessage */ forwardMessage(chatId: string | number, extra?: Shorthand<'forwardMessage'>[2]): Promise; /** * @see https://core.telegram.org/bots/api#copymessage */ copyMessage(chatId: string | number, extra?: tt.ExtraCopyMessage): Promise; /** * @see https://core.telegram.org/bots/api#approvechatjoinrequest */ approveChatJoinRequest(userId: number): Promise; /** * @see https://core.telegram.org/bots/api#declinechatjoinrequest */ declineChatJoinRequest(userId: number): Promise; /** * @see https://core.telegram.org/bots/api#banchatsenderchat */ banChatSenderChat(senderChatId: number): Promise; /** * @see https://core.telegram.org/bots/api#unbanchatsenderchat */ unbanChatSenderChat(senderChatId: number): Promise; /** * Use this method to change the bot's menu button in the current private chat. Returns true on success. * @see https://core.telegram.org/bots/api#setchatmenubutton */ setChatMenuButton(menuButton?: tg.MenuButton): Promise; /** * Use this method to get the current value of the bot's menu button in the current private chat. Returns MenuButton on success. * @see https://core.telegram.org/bots/api#getchatmenubutton */ getChatMenuButton(): Promise; /** * @see https://core.telegram.org/bots/api#setmydefaultadministratorrights */ setMyDefaultAdministratorRights(extra?: Parameters[0]): Promise; /** * @see https://core.telegram.org/bots/api#getmydefaultadministratorrights */ getMyDefaultAdministratorRights(extra?: Parameters[0]): Promise; } export default Context; type UpdateTypes> = Extract, tt.UpdateType>; export type GetUpdateContent = U extends tg.Update.CallbackQueryUpdate ? U['callback_query']['message'] : U[UpdateTypes]; type Getter, P extends string> = PropOr, P>; //# sourceMappingURL=context.d.ts.map