UNPKG

grammy

Version:

The Telegram Bot Framework.

783 lines β€’ 126 kB
import { type Api, type Other as OtherApi } from "./core/api.js"; import { type Methods, type RawApi } from "./core/client.js"; import { type Filter, type FilterCore, type FilterQuery } from "./filter.js"; import { type AcceptedGiftTypes, type Chat, type ChatPermissions, type InlineQueryResult, type InputChecklist, type InputFile, type InputMedia, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputPaidMedia, type InputPollOption, type InputProfilePhoto, type InputStoryContent, type LabeledPrice, type Message, type MessageEntity, type PassportElementError, type ReactionType, type ReactionTypeEmoji, type Update, type User, type UserFromGetMe } from "./types.js"; export type MaybeArray<T> = T | T[]; /** permits `string` but gives hints */ export type StringWithCommandSuggestions = (string & Record<never, never>) | "start" | "help" | "settings" | "privacy" | "developer_info"; type Other<M extends Methods<RawApi>, X extends string = never> = OtherApi<RawApi, M, X>; type SnakeToCamelCase<S extends string> = S extends `${infer L}_${infer R}` ? `${L}${Capitalize<SnakeToCamelCase<R>>}` : S; type AliasProps<U> = { [K in string & keyof U as SnakeToCamelCase<K>]: U[K]; }; type RenamedUpdate = AliasProps<Omit<Update, "update_id">>; interface StaticHas { /** * Generates a predicate function that can test context objects for matching * the given filter query. This uses the same logic as `bot.on`. * * @param filter The filter query to check */ filterQuery<Q extends FilterQuery>(filter: Q | Q[]): <C extends Context>(ctx: C) => ctx is Filter<C, Q>; /** * Generates a predicate function that can test context objects for * containing the given text, or for the text to match the given regular * expression. This uses the same logic as `bot.hears`. * * @param trigger The string or regex to match */ text(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is HearsContext<C>; /** * Generates a predicate function that can test context objects for * containing a command. This uses the same logic as `bot.command`. * * @param command The command to match */ command(command: MaybeArray<StringWithCommandSuggestions>): <C extends Context>(ctx: C) => ctx is CommandContext<C>; /** * Generates a predicate function that can test context objects for * containing a message reaction update. This uses the same logic as * `bot.reaction`. * * @param reaction The reaction to test against */ reaction(reaction: MaybeArray<ReactionTypeEmoji["emoji"] | ReactionType>): <C extends Context>(ctx: C) => ctx is ReactionContext<C>; /** * Generates a predicate function that can test context objects for * belonging to a chat with the given chat type. This uses the same logic as * `bot.chatType`. * * @param chatType The chat type to match */ chatType<T extends Chat["type"]>(chatType: MaybeArray<T>): <C extends Context>(ctx: C) => ctx is ChatTypeContext<C, T>; /** * Generates a predicate function that can test context objects for * containing the given callback query, or for the callback query data to * match the given regular expression. This uses the same logic as * `bot.callbackQuery`. * * @param trigger The string or regex to match */ callbackQuery(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is CallbackQueryContext<C>; /** * Generates a predicate function that can test context objects for * containing the given game query, or for the game name to match the given * regular expression. This uses the same logic as `bot.gameQuery`. * * @param trigger The string or regex to match */ gameQuery(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is GameQueryContext<C>; /** * Generates a predicate function that can test context objects for * containing the given inline query, or for the inline query to match the * given regular expression. This uses the same logic as `bot.inlineQuery`. * * @param trigger The string or regex to match */ inlineQuery(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is InlineQueryContext<C>; /** * Generates a predicate function that can test context objects for * containing the chosen inline result, or for the chosen inline result to * match the given regular expression. * * @param trigger The string or regex to match */ chosenInlineResult(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is ChosenInlineResultContext<C>; /** * Generates a predicate function that can test context objects for * containing the given pre-checkout query, or for the pre-checkout query * payload to match the given regular expression. This uses the same logic * as `bot.preCheckoutQuery`. * * @param trigger The string or regex to match */ preCheckoutQuery(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is PreCheckoutQueryContext<C>; /** * Generates a predicate function that can test context objects for * containing the given shipping query, or for the shipping query to match * the given regular expression. This uses the same logic as * `bot.shippingQuery`. * * @param trigger The string or regex to match */ shippingQuery(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is ShippingQueryContext<C>; } /** * When your bot receives a message, Telegram sends an update object to your * bot. The update contains information about the chat, the user, and of course * the message itself. There are numerous other updates, too: * https://core.telegram.org/bots/api#update * * When grammY receives an update, it wraps this update into a context object * for you. Context objects are commonly named `ctx`. A context object does two * things: * 1. **`ctx.update`** holds the update object that you can use to process the * message. This includes providing useful shortcuts for the update, for * instance, `ctx.msg` is a shortcut that gives you the message object from * the updateβ€”no matter whether it is contained in `ctx.update.message`, or * `ctx.update.edited_message`, or `ctx.update.channel_post`, or * `ctx.update.edited_channel_post`. * 2. **`ctx.api`** gives you access to the full Telegram Bot API so that you * can directly call any method, such as responding via * `ctx.api.sendMessage`. Also here, the context objects has some useful * shortcuts for you. For instance, if you want to send a message to the same * chat that a message comes from (i.e. just respond to a user) you can call * `ctx.reply`. This is nothing but a wrapper for `ctx.api.sendMessage` with * the right `chat_id` pre-filled for you. Almost all methods of the Telegram * Bot API have their own shortcut directly on the context object, so you * probably never really have to use `ctx.api` at all. * * This context object is then passed to all of the listeners (called * middleware) that you register on your bot. Because this is so useful, the * context object is often used to hold more information. One example are * sessions (a chat-specific data storage that is stored in a database), and * another example is `ctx.match` that is used by `bot.command` and other * methods to keep information about how a regular expression was matched. * * Read up about middleware on the * [website](https://grammy.dev/guide/context) if you want to know more * about the powerful opportunities that lie in context objects, and about how * grammY implements them. */ export declare class Context implements RenamedUpdate { /** * The update object that is contained in the context. */ readonly update: Update; /** * An API instance that allows you to call any method of the Telegram * Bot API. */ readonly api: Api; /** * Information about the bot itself. */ readonly me: UserFromGetMe; /** * Used by some middleware to store information about how a certain string * or regular expression was matched. */ match: string | RegExpMatchArray | undefined; constructor( /** * The update object that is contained in the context. */ update: Update, /** * An API instance that allows you to call any method of the Telegram * Bot API. */ api: Api, /** * Information about the bot itself. */ me: UserFromGetMe); /** Alias for `ctx.update.message` */ get message(): (Message & Update.NonChannel) | undefined; /** Alias for `ctx.update.edited_message` */ get editedMessage(): (Message & Update.Edited & Update.NonChannel) | undefined; /** Alias for `ctx.update.channel_post` */ get channelPost(): (Message & Update.Channel) | undefined; /** Alias for `ctx.update.edited_channel_post` */ get editedChannelPost(): (Message & Update.Edited & Update.Channel) | undefined; /** Alias for `ctx.update.business_connection` */ get businessConnection(): import("@grammyjs/types/manage.js").BusinessConnection | undefined; /** Alias for `ctx.update.business_message` */ get businessMessage(): (Message & Update.Private) | undefined; /** Alias for `ctx.update.edited_business_message` */ get editedBusinessMessage(): (Message & Update.Edited & Update.Private) | undefined; /** Alias for `ctx.update.deleted_business_messages` */ get deletedBusinessMessages(): import("@grammyjs/types/manage.js").BusinessMessagesDeleted | undefined; /** Alias for `ctx.update.message_reaction` */ get messageReaction(): import("@grammyjs/types/message.js").MessageReactionUpdated | undefined; /** Alias for `ctx.update.message_reaction_count` */ get messageReactionCount(): import("@grammyjs/types/message.js").MessageReactionCountUpdated | undefined; /** Alias for `ctx.update.inline_query` */ get inlineQuery(): import("@grammyjs/types/inline.js").InlineQuery | undefined; /** Alias for `ctx.update.chosen_inline_result` */ get chosenInlineResult(): import("@grammyjs/types/inline.js").ChosenInlineResult | undefined; /** Alias for `ctx.update.callback_query` */ get callbackQuery(): import("@grammyjs/types/markup.js").CallbackQuery | undefined; /** Alias for `ctx.update.shipping_query` */ get shippingQuery(): import("@grammyjs/types/payment.js").ShippingQuery | undefined; /** Alias for `ctx.update.pre_checkout_query` */ get preCheckoutQuery(): import("@grammyjs/types/payment.js").PreCheckoutQuery | undefined; /** Alias for `ctx.update.poll` */ get poll(): import("@grammyjs/types/message.js").Poll | undefined; /** Alias for `ctx.update.poll_answer` */ get pollAnswer(): import("@grammyjs/types/message.js").PollAnswer | undefined; /** Alias for `ctx.update.my_chat_member` */ get myChatMember(): import("@grammyjs/types/manage.js").ChatMemberUpdated | undefined; /** Alias for `ctx.update.chat_member` */ get chatMember(): import("@grammyjs/types/manage.js").ChatMemberUpdated | undefined; /** Alias for `ctx.update.chat_join_request` */ get chatJoinRequest(): import("@grammyjs/types/manage.js").ChatJoinRequest | undefined; /** Alias for `ctx.update.chat_boost` */ get chatBoost(): import("@grammyjs/types/manage.js").ChatBoostUpdated | undefined; /** Alias for `ctx.update.removed_chat_boost` */ get removedChatBoost(): import("@grammyjs/types/manage.js").ChatBoostRemoved | undefined; /** Alias for `ctx.update.purchased_paid_media` */ get purchasedPaidMedia(): import("@grammyjs/types/payment.js").PaidMediaPurchased | undefined; /** * Get the message object from wherever possible. Alias for `this.message ?? * this.editedMessage ?? this.channelPost ?? this.editedChannelPost ?? * this.businessMessage ?? this.editedBusinessMessage ?? * this.callbackQuery?.message`. */ get msg(): Message | undefined; /** * Get the chat object from wherever possible. Alias for `(this.msg ?? * this.deletedBusinessMessages ?? this.messageReaction ?? * this.messageReactionCount ?? this.myChatMember ?? this.chatMember ?? * this.chatJoinRequest ?? this.chatBoost ?? this.removedChatBoost)?.chat`. */ get chat(): Chat | undefined; /** * Get the sender chat object from wherever possible. Alias for * `ctx.msg?.sender_chat`. */ get senderChat(): Chat | undefined; /** * Get the user object from wherever possible. Alias for * `(this.businessConnection ?? this.messageReaction ?? * (this.chatBoost?.boost ?? this.removedChatBoost)?.source)?.user ?? * (this.callbackQuery ?? this.msg ?? this.inlineQuery ?? * this.chosenInlineResult ?? this.shippingQuery ?? this.preCheckoutQuery ?? * this.myChatMember ?? this.chatMember ?? this.chatJoinRequest ?? * this.purchasedPaidMedia)?.from`. */ get from(): User | undefined; /** * Get the message identifier from wherever possible. Alias for * `this.msg?.message_id ?? this.messageReaction?.message_id ?? * this.messageReactionCount?.message_id`. */ get msgId(): number | undefined; /** * Gets the chat identifier from wherever possible. Alias for `this.chat?.id * ?? this.businessConnection?.user_chat_id`. */ get chatId(): number | undefined; /** * Get the inline message identifier from wherever possible. Alias for * `(ctx.callbackQuery ?? ctx.chosenInlineResult)?.inline_message_id`. */ get inlineMessageId(): string | undefined; /** * Get the business connection identifier from wherever possible. Alias for * `this.msg?.business_connection_id ?? this.businessConnection?.id ?? * this.deletedBusinessMessages?.business_connection_id`. */ get businessConnectionId(): string | undefined; /** * Get entities and their text. Extracts the text from `ctx.msg.text` or * `ctx.msg.caption`. Returns an empty array if one of `ctx.msg`, * `ctx.msg.text` or `ctx.msg.entities` is undefined. * * You can filter specific entity types by passing the `types` parameter. * Example: * * ```ts * ctx.entities() // Returns all entity types * ctx.entities('url') // Returns only url entities * ctx.entities(['url', 'email']) // Returns url and email entities * ``` * * @param types Types of entities to return. Omit to get all entities. * @returns Array of entities and their texts, or empty array when there's no text */ entities(): Array<MessageEntity & { /** Slice of the message text that contains this entity */ text: string; }>; entities<T extends MessageEntity["type"]>(types: MaybeArray<T>): Array<MessageEntity & { type: T; /** Slice of the message text that contains this entity */ text: string; }>; /** * Find out which reactions were added and removed in a `message_reaction` * update. This method looks at `ctx.messageReaction` and computes the * difference between the old reaction and the new reaction. It also groups * the reactions by emoji reactions and custom emoji reactions. For example, * the resulting object could look like this: * ```ts * { * emoji: ['πŸ‘', 'πŸŽ‰'] * emojiAdded: ['πŸŽ‰'], * emojiKept: ['πŸ‘'], * emojiRemoved: [], * customEmoji: [], * customEmojiAdded: [], * customEmojiKept: [], * customEmojiRemoved: ['id0123'], * paid: true, * paidAdded: false, * paidRemoved: false, * } * ``` * In the above example, a tada reaction was added by the user, and a custom * emoji reaction with the custom emoji 'id0123' was removed in the same * update. The user had already reacted with a thumbs up reaction and a paid * star reaction, which they left both unchanged. As a result, the current * reaction by the user is thumbs up, tada, and a paid reaction. Note that * the current reaction (all emoji reactions regardless of type in one list) * can also be obtained from `ctx.messageReaction.new_reaction`. * * Remember that reaction updates only include information about the * reaction of a specific user. The respective message may have many more * reactions by other people which will not be included in this update. * * @returns An object containing information about the reaction update */ reactions(): { /** Emoji currently present in this user's reaction */ emoji: ReactionTypeEmoji["emoji"][]; /** Emoji newly added to this user's reaction */ emojiAdded: ReactionTypeEmoji["emoji"][]; /** Emoji not changed by the update to this user's reaction */ emojiKept: ReactionTypeEmoji["emoji"][]; /** Emoji removed from this user's reaction */ emojiRemoved: ReactionTypeEmoji["emoji"][]; /** Custom emoji currently present in this user's reaction */ customEmoji: string[]; /** Custom emoji newly added to this user's reaction */ customEmojiAdded: string[]; /** Custom emoji not changed by the update to this user's reaction */ customEmojiKept: string[]; /** Custom emoji removed from this user's reaction */ customEmojiRemoved: string[]; /** * `true` if a paid reaction is currently present in this user's * reaction, and `false` otherwise */ paid: boolean; /** * `true` if a paid reaction was newly added to this user's reaction, * and `false` otherwise */ paidAdded: boolean; }; /** * `Context.has` is an object that contains a number of useful functions for * probing context objects. Each of these functions can generate a predicate * function, to which you can pass context objects in order to check if a * condition holds for the respective context object. * * For example, you can call `Context.has.filterQuery(":text")` to generate * a predicate function that tests context objects for containing text: * ```ts * const hasText = Context.has.filterQuery(":text"); * * if (hasText(ctx0)) {} // `ctx0` matches the filter query `:text` * if (hasText(ctx1)) {} // `ctx1` matches the filter query `:text` * if (hasText(ctx2)) {} // `ctx2` matches the filter query `:text` * ``` * These predicate functions are used internally by the has-methods that are * installed on every context object. This means that calling * `ctx.has(":text")` is equivalent to * `Context.has.filterQuery(":text")(ctx)`. */ static has: StaticHas; /** * Returns `true` if this context object matches the given filter query, and * `false` otherwise. This uses the same logic as `bot.on`. * * @param filter The filter query to check */ has<Q extends FilterQuery>(filter: Q | Q[]): this is FilterCore<Q>; /** * Returns `true` if this context object contains the given text, or if it * contains text that matches the given regular expression. It returns * `false` otherwise. This uses the same logic as `bot.hears`. * * @param trigger The string or regex to match */ hasText(trigger: MaybeArray<string | RegExp>): this is HearsContextCore; /** * Returns `true` if this context object contains the given command, and * `false` otherwise. This uses the same logic as `bot.command`. * * @param command The command to match */ hasCommand(command: MaybeArray<StringWithCommandSuggestions>): this is CommandContextCore; hasReaction(reaction: MaybeArray<ReactionTypeEmoji["emoji"] | ReactionType>): this is ReactionContextCore; /** * Returns `true` if this context object belongs to a chat with the given * chat type, and `false` otherwise. This uses the same logic as * `bot.chatType`. * * @param chatType The chat type to match */ hasChatType<T extends Chat["type"]>(chatType: MaybeArray<T>): this is ChatTypeContextCore<T>; /** * Returns `true` if this context object contains the given callback query, * or if the contained callback query data matches the given regular * expression. It returns `false` otherwise. This uses the same logic as * `bot.callbackQuery`. * * @param trigger The string or regex to match */ hasCallbackQuery(trigger: MaybeArray<string | RegExp>): this is CallbackQueryContextCore; /** * Returns `true` if this context object contains the given game query, or * if the contained game query matches the given regular expression. It * returns `false` otherwise. This uses the same logic as `bot.gameQuery`. * * @param trigger The string or regex to match */ hasGameQuery(trigger: MaybeArray<string | RegExp>): this is GameQueryContextCore; /** * Returns `true` if this context object contains the given inline query, or * if the contained inline query matches the given regular expression. It * returns `false` otherwise. This uses the same logic as `bot.inlineQuery`. * * @param trigger The string or regex to match */ hasInlineQuery(trigger: MaybeArray<string | RegExp>): this is InlineQueryContextCore; /** * Returns `true` if this context object contains the chosen inline result, * or if the contained chosen inline result matches the given regular * expression. It returns `false` otherwise. This uses the same logic as * `bot.chosenInlineResult`. * * @param trigger The string or regex to match */ hasChosenInlineResult(trigger: MaybeArray<string | RegExp>): this is ChosenInlineResultContextCore; /** * Returns `true` if this context object contains the given pre-checkout * query, or if the contained pre-checkout query matches the given regular * expression. It returns `false` otherwise. This uses the same logic as * `bot.preCheckoutQuery`. * * @param trigger The string or regex to match */ hasPreCheckoutQuery(trigger: MaybeArray<string | RegExp>): this is PreCheckoutQueryContextCore; /** * Returns `true` if this context object contains the given shipping query, * or if the contained shipping query matches the given regular expression. * It returns `false` otherwise. This uses the same logic as * `bot.shippingQuery`. * * @param trigger The string or regex to match */ hasShippingQuery(trigger: MaybeArray<string | RegExp>): this is ShippingQueryContextCore; /** * Context-aware alias for `api.sendMessage`. Use this method to send text messages. On success, the sent Message is returned. * * @param text Text of the message to be sent, 1-4096 characters after entities parsing * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendmessage */ reply(text: string, other?: Other<"sendMessage", "chat_id" | "text">, signal?: AbortSignal): Promise<Message.TextMessage>; /** * Context-aware alias for `api.forwardMessage`. Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent Message is returned. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#forwardmessage */ forwardMessage(chat_id: number | string, other?: Other<"forwardMessage", "chat_id" | "from_chat_id" | "message_id">, signal?: AbortSignal): Promise<Message>; /** * Context-aware alias for `api.forwardMessages`. Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param message_ids A list of 1-100 identifiers of messages in the current chat to forward. The identifiers must be specified in a strictly increasing order. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#forwardmessages */ forwardMessages(chat_id: number | string, message_ids: number[], other?: Other<"forwardMessages", "chat_id" | "from_chat_id" | "message_ids">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").MessageId[]>; /** * Context-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#copymessage */ copyMessage(chat_id: number | string, other?: Other<"copyMessage", "chat_id" | "from_chat_id" | "message_id">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").MessageId>; /** * Context-aware alias for `api.copyMessages`. Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param message_ids A list of 1-100 identifiers of messages in the current chat to copy. The identifiers must be specified in a strictly increasing order. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#copymessages */ copyMessages(chat_id: number | string, message_ids: number[], other?: Other<"copyMessages", "chat_id" | "from_chat_id" | "message_ids">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").MessageId[]>; /** * Context-aware alias for `api.sendPhoto`. Use this method to send photos. On success, the sent Message is returned. * * @param photo Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendphoto */ replyWithPhoto(photo: InputFile | string, other?: Other<"sendPhoto", "chat_id" | "photo">, signal?: AbortSignal): Promise<Message.PhotoMessage>; /** * Context-aware alias for `api.sendAudio`. Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. * * For sending voice messages, use the sendVoice method instead. * * @param audio Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendaudio */ replyWithAudio(audio: InputFile | string, other?: Other<"sendAudio", "chat_id" | "audio">, signal?: AbortSignal): Promise<Message.AudioMessage>; /** * Context-aware alias for `api.sendDocument`. Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. * * @param document File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#senddocument */ replyWithDocument(document: InputFile | string, other?: Other<"sendDocument", "chat_id" | "document">, signal?: AbortSignal): Promise<Message.DocumentMessage>; /** * Context-aware alias for `api.sendVideo`. Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. * * @param video Video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendvideo */ replyWithVideo(video: InputFile | string, other?: Other<"sendVideo", "chat_id" | "video">, signal?: AbortSignal): Promise<Message.VideoMessage>; /** * Context-aware alias for `api.sendAnimation`. Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. * * @param animation Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendanimation */ replyWithAnimation(animation: InputFile | string, other?: Other<"sendAnimation", "chat_id" | "animation">, signal?: AbortSignal): Promise<Message.AnimationMessage>; /** * Context-aware alias for `api.sendVoice`. Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. * * @param voice Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendvoice */ replyWithVoice(voice: InputFile | string, other?: Other<"sendVoice", "chat_id" | "voice">, signal?: AbortSignal): Promise<Message.VoiceMessage>; /** * Context-aware alias for `api.sendVideoNote`. Use this method to send video messages. On success, the sent Message is returned. * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. * * @param video_note Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data.. Sending video notes by a URL is currently unsupported * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendvideonote */ replyWithVideoNote(video_note: InputFile | string, other?: Other<"sendVideoNote", "chat_id" | "video_note">, signal?: AbortSignal): Promise<Message.VideoNoteMessage>; /** * Context-aware alias for `api.sendMediaGroup`. Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Messages that were sent is returned. * * @param media An array describing messages to be sent, must include 2-10 items * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendmediagroup */ replyWithMediaGroup(media: ReadonlyArray<InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo>, other?: Other<"sendMediaGroup", "chat_id" | "media">, signal?: AbortSignal): Promise<(Message.PhotoMessage | Message.AudioMessage | Message.DocumentMessage | Message.VideoMessage)[]>; /** * Context-aware alias for `api.sendLocation`. Use this method to send point on the map. On success, the sent Message is returned. * * @param latitude Latitude of the location * @param longitude Longitude of the location * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendlocation */ replyWithLocation(latitude: number, longitude: number, other?: Other<"sendLocation", "chat_id" | "latitude" | "longitude">, signal?: AbortSignal): Promise<Message.LocationMessage>; /** * Context-aware alias for `api.editMessageLiveLocation`. Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param latitude Latitude of new location * @param longitude Longitude of new location * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#editmessagelivelocation */ editMessageLiveLocation(latitude: number, longitude: number, other?: Other<"editMessageLiveLocation", "chat_id" | "message_id" | "inline_message_id" | "latitude" | "longitude">, signal?: AbortSignal): Promise<true | (Update.Edited & Message.CommonMessage & { location: import("@grammyjs/types/message.js").Location; })>; /** * Context-aware alias for `api.stopMessageLiveLocation`. Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#stopmessagelivelocation */ stopMessageLiveLocation(other?: Other<"stopMessageLiveLocation", "chat_id" | "message_id" | "inline_message_id">, signal?: AbortSignal): Promise<true | (Update.Edited & Message.CommonMessage & { location: import("@grammyjs/types/message.js").Location; })>; /** * Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media. On success, the sent Message is returned. * * @param star_count The number of Telegram Stars that must be paid to buy access to the media * @param media An array describing the media to be sent; up to 10 items * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendpaidmedia */ sendPaidMedia(star_count: number, media: InputPaidMedia[], other?: Other<"sendPaidMedia", "chat_id" | "star_count" | "media">, signal?: AbortSignal): Promise<Message.PaidMediaMessage>; /** * Context-aware alias for `api.sendVenue`. Use this method to send information about a venue. On success, the sent Message is returned. * * @param latitude Latitude of the venue * @param longitude Longitude of the venue * @param title Name of the venue * @param address Address of the venue * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendvenue */ replyWithVenue(latitude: number, longitude: number, title: string, address: string, other?: Other<"sendVenue", "chat_id" | "latitude" | "longitude" | "title" | "address">, signal?: AbortSignal): Promise<Message.VenueMessage>; /** * Context-aware alias for `api.sendContact`. Use this method to send phone contacts. On success, the sent Message is returned. * * @param phone_number Contact's phone number * @param first_name Contact's first name * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendcontact */ replyWithContact(phone_number: string, first_name: string, other?: Other<"sendContact", "chat_id" | "phone_number" | "first_name">, signal?: AbortSignal): Promise<Message.ContactMessage>; /** * Context-aware alias for `api.sendPoll`. Use this method to send a native poll. On success, the sent Message is returned. * * @param question Poll question, 1-300 characters * @param options A list of answer options, 2-12 strings 1-100 characters each * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendpoll */ replyWithPoll(question: string, options: (string | InputPollOption)[], other?: Other<"sendPoll", "chat_id" | "question" | "options">, signal?: AbortSignal): Promise<Message.PollMessage>; /** * Context-aware alias for `api.sendChecklist`. Use this method to send a checklist on behalf of a connected business account. On success, the sent Message is returned. * * @param checklist An object for the checklist to send * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendchecklist */ replyWithChecklist(checklist: InputChecklist, other?: Other<"sendChecklist", "business_connection_id" | "chat_id" | "checklist">, signal?: AbortSignal): Promise<Message.ChecklistMessage>; /** * Context-aware alias for `api.editMessageChecklist`. Use this method to edit a checklist on behalf of a connected business account. On success, the edited Message is returned. * * @param checklist An object for the new checklist * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#editmessagechecklist */ editMessageChecklist(checklist: InputChecklist, other?: Other<"editMessageChecklist", "business_connection_id" | "chat_id" | "messaage_id" | "checklist">, signal?: AbortSignal): Promise<Message.ChecklistMessage>; /** * Context-aware alias for `api.sendDice`. Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned. * * @param emoji Emoji on which the dice throw animation is based. Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, β€œπŸ€β€, β€œβš½β€, β€œπŸŽ³β€, or β€œπŸŽ°β€. Dice can have values 1-6 for β€œπŸŽ²β€, β€œπŸŽ―β€ and β€œπŸŽ³β€, values 1-5 for β€œπŸ€β€ and β€œβš½β€, and values 1-64 for β€œπŸŽ°β€. Defaults to β€œπŸŽ²β€ * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#senddice */ replyWithDice(emoji: (string & Record<never, never>) | "🎲" | "🎯" | "πŸ€" | "⚽" | "🎳" | "🎰", other?: Other<"sendDice", "chat_id" | "emoji">, signal?: AbortSignal): Promise<Message.DiceMessage>; /** * Context-aware alias for `api.sendChatAction`. Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success. * * Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of β€œRetrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a β€œsending photo” status for the bot. * * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. * * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, choose_sticker for stickers, find_location for location data, record_video_note or upload_video_note for video notes. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#sendchataction */ replyWithChatAction(action: "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_voice" | "upload_document" | "choose_sticker" | "find_location" | "record_video_note" | "upload_video_note", other?: Other<"sendChatAction", "chat_id" | "action">, signal?: AbortSignal): Promise<true>; /** * Context-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages of some types can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success. * * @param reaction A list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots. * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#setmessagereaction */ react(reaction: MaybeArray<ReactionTypeEmoji["emoji"] | ReactionType>, other?: Other<"setMessageReaction", "chat_id" | "message_id" | "reaction">, signal?: AbortSignal): Promise<true>; /** * Context-aware alias for `api.getUserProfilePhotos`. Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. * * @param user_id Unique identifier of the target user * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#getuserprofilephotos */ getUserProfilePhotos(other?: Other<"getUserProfilePhotos", "user_id">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").UserProfilePhotos>; /** * Context-aware alias for `api.serUserEmojiStatus`. Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess. Returns True on success. * * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#setuseremojistatus */ setUserEmojiStatus(other?: Other<"setUserEmojiStatus", "user_id">, signal?: AbortSignal): Promise<true>; /** * Context-aware alias for `api.getUserChatBoosts`. Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object. * * @param chat_id Unique identifier for the chat or username of the channel (in the format @channelusername) * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#getuserchatboosts */ getUserChatBoosts(chat_id: number | string, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").UserChatBoosts>; /** * Context-aware alias for `api.getBusinessConnection`. Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success. * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#getbusinessconnection */ getBusinessConnection(signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").BusinessConnection>; /** * Context-aware alias for `api.getFile`. Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again. * * Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received. * * @param signal Optional `AbortSignal` to cancel the request * * **Official reference:** https://core.telegram.org/bots/api#getfile */ getFile(signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").File>; /** @deprecated Use `banAuthor` instead. */ kickAuthor(...args: Parameters<Context["banAuthor"]>): Promise<true>; /** * Context-aware alias f