UNPKG

@gramio/keyboards

Version:

Framework-agnostic Telegram bot keyboard builder with many cool features!

865 lines (854 loc) 45.5 kB
import { TelegramKeyboardButton, TelegramKeyboardButtonRequestUsers, TelegramKeyboardButtonRequestChat, TelegramKeyboardButtonPollType, TelegramReplyKeyboardMarkup, TelegramInlineKeyboardButton, TelegramLoginUrl, TelegramSwitchInlineQueryChosenChat, TelegramCallbackGame, TelegramCopyTextButton, TelegramInlineKeyboardMarkup, TelegramWebAppInfo, TelegramReplyKeyboardRemove, TelegramForceReply, TelegramInputTextMessageContent, TelegramInputLocationMessageContent, TelegramInputVenueMessageContent, TelegramInputContactMessageContent, TelegramInputInvoiceMessageContent, TelegramInlineQueryResultCachedAudio, TelegramInlineQueryResultCachedDocument, TelegramInlineQueryResultCachedGif, TelegramInlineQueryResultCachedMpeg4Gif, TelegramInlineQueryResultCachedPhoto, TelegramInlineQueryResultCachedSticker, TelegramInlineQueryResultCachedVideo, TelegramInlineQueryResultCachedVoice, TelegramInputMessageContent, TelegramInlineQueryResultArticle, TelegramInlineQueryResultAudio, TelegramInlineQueryResultContact, TelegramInlineQueryResultGame, TelegramInlineQueryResultDocument, TelegramInlineQueryResultGif, TelegramInlineQueryResultLocation, TelegramInlineQueryResultMpeg4Gif, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultVenue, TelegramInlineQueryResultVideo, TelegramInlineQueryResultVoice } from '@gramio/types'; interface KeyboardFeatureFlags { enableSetterKeyboardHelpers: boolean; } declare const keyboardsFeatureFlagsMap: KeyboardFeatureFlags; type ButtonsIterator<T> = (options: { button: T; index: number; row: T[]; rowIndex: number; }) => boolean; type CreateButtonIterator<T> = (options: { index: number; rowIndex: number; }) => T; interface KeyboardHelperColumns { type: "columns"; columns: number; } interface KeyboardHelperWrap<T> { type: "wrap"; fn: ButtonsIterator<T>; } interface KeyboardHelperFilter<T> { type: "filter"; fn: ButtonsIterator<T>; } interface KeyboardHelperPattern { type: "pattern"; pattern: number[]; } type KeyboardHelpers<T> = KeyboardHelperColumns | KeyboardHelperWrap<T> | KeyboardHelperFilter<T> | KeyboardHelperPattern; declare function chunk<T>(array: T[][], size: number): T[][]; declare function customWrap<T>(array: T[][], fn: ButtonsIterator<T>): T[][]; declare function pattern<T>(array: T[][], pattern: number[]): T[][]; declare function filter<T>(array: T[][], fn: ButtonsIterator<T>): T[][]; /** Base-class for construct keyboard with useful helpers */ declare class BaseKeyboardConstructor<T> { protected rows: T[][]; protected currentRow: T[]; protected featureFlags: KeyboardFeatureFlags; constructor(featureFlags?: KeyboardFeatureFlags); private wrapOptions; private appliedHelper; private appliedFilter; protected get keyboard(): T[][]; /** * Adds a `line break`. Call this method to make sure that the next added buttons will be on a new row. * @example * ```ts * new InlineKeyboard() * .text("first row", "payload") * .row() * .text("second row", "payload"); * ``` */ row(): this; /** * Allows you to limit the number of columns in the keyboard. * @example * ```ts * new InlineKeyboard() * .columns(1) * .text("first row", "payload") * .text("second row", "payload"); * .text("third row", "payload"); * ``` */ columns(length?: number): this; /** * A custom handler that controls row wrapping. * @example * ```ts * new InlineKeyboard() * .wrap(({ button }) => button.callback_data === "2") * .text("first row", "1") * .text("first row", "1"); * .text("second row", "2"); * ``` */ wrap(fn?: ButtonsIterator<T>): this; /** * A handler that helps filter keyboard buttons * @example * ```ts * new InlineKeyboard() * .filter(({ button }) => button.callback_data !== "hidden") * .text("button", "pass") * .text("button", "hidden") * .text("button", "pass"); * ``` */ filter(fn?: ButtonsIterator<T>): this; /** * An array with the number of columns per row. Allows you to set a "template" * @example * ```ts * new InlineKeyboard() * .pattern([1, 3, 2]) * .text("1", "payload") * .text("2", "payload") * .text("2", "payload") * .text("2", "payload") * .text("3", "payload") * .text("3", "payload"); * ``` */ pattern(pattern?: number[]): this; /** * Allows you to add multiple buttons in raw format. * @example * ```ts * const labels = ["some", "buttons"]; * * new InlineKeyboard() * .add({ text: "raw button", callback_data: "payload" }) * .add(InlineKeyboard.text("raw button by InlineKeyboard.text", "payload")) * .add(...labels.map((x) => InlineKeyboard.text(x, `${x}payload`))); * ``` */ add(...buttons: T[]): this; /** * Allows you to dynamically substitute buttons depending on something * @example * ```ts * const labels = ["some", "buttons"]; * const isAdmin = true; * * new InlineKeyboard() * .addIf(1 === 2, { text: "raw button", callback_data: "payload" }) * .addIf( * isAdmin, * InlineKeyboard.text("raw button by InlineKeyboard.text", "payload") * ) * .addIf( * ({ index, rowIndex }) => rowIndex === index, * ...labels.map((x) => InlineKeyboard.text(x, `${x}payload`)) * ); * ``` */ addIf(condition: ((options: { rowIndex: number; index: number; }) => boolean) | boolean, ...buttons: T[]): this; /** * Allows you to create a button matrix. * @example * ```ts * import { randomInt } from "node:crypto"; * * const bomb = [randomInt(0, 9), randomInt(0, 9)] as const; * * new InlineKeyboard().matrix(10, 10, ({ rowIndex, index }) => * InlineKeyboard.text( * rowIndex === bomb[0] && index === bomb[1] ? "💣" : "ㅤ", * "payload" * ) *); * ``` */ matrix(rows: number, columns: number, fn: CreateButtonIterator<T>): this; resetHelpers(): this; } /** * **ReplyKeyboardMarkup** builder * * This object represents a [custom keyboard](https://core.telegram.org/bots/features#keyboards) with reply options (see [Introduction to bots](https://core.telegram.org/bots/features#keyboards) for details and examples). * * {@link https://core.telegram.org/bots/api/#replykeyboardmarkup | [Documentation]} */ declare class Keyboard extends BaseKeyboardConstructor<TelegramKeyboardButton> { options: { isOneTime: boolean; isPersistent: boolean; isResized: boolean; isSelective: boolean; placeholder: string | undefined; }; /** * Text of the button. It will be sent as a message when the button is pressed * @example * ```ts * new Keyboard().text("some button text"); * ``` */ text(text: string): this; /** * Text of the button. It will be sent as a message when the button is pressed */ static text(text: string): TelegramKeyboardButton; /** * If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users\_shared” service message. Available in private chats only. * @example * ```ts * new Keyboard().requestUsers("some button text", 228, { * user_is_premium: true, * }); * ``` */ requestUsers(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestUsers, "request_id">): this; /** * If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users\_shared” service message. Available in private chats only. */ static requestUsers(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestUsers, "request_id">): TelegramKeyboardButton; /** * If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat\_shared” service message. Available in private chats only. * @example * ```ts * new Keyboard().requestChat("gramio", 255, { * chat_is_forum: true, * }); * ``` */ requestChat(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestChat, "request_id" | "chat_is_channel"> & { chat_is_channel?: boolean; }): this; /** * If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat\_shared” service message. Available in private chats only. */ static requestChat(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestChat, "request_id" | "chat_is_channel"> & { chat_is_channel?: boolean; }): TelegramKeyboardButton; /** * If *True*, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only. * @example * ```ts * new Keyboard().requestContact("some button text"); * ``` */ requestContact(text: string): this; /** * If *True*, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only. */ static requestContact(text: string): TelegramKeyboardButton; /** * If *True*, the user's current location will be sent when the button is pressed. Available in private chats only. * @example * ```ts * new Keyboard().requestLocation("some button text"); * ``` */ requestLocation(text: string): this; /** * If *True*, the user's current location will be sent when the button is pressed. Available in private chats only. */ static requestLocation(text: string): TelegramKeyboardButton; /** * If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only. * * If *quiz* is passed, the user will be allowed to create only polls in the quiz mode. If *regular* is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type. * @example * ```ts * new Keyboard().requestPoll("some button text", "quiz"); * ``` */ requestPoll(text: string, type?: TelegramKeyboardButtonPollType["type"]): this; /** * If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only. * * If *quiz* is passed, the user will be allowed to create only polls in the quiz mode. If *regular* is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type. */ static requestPoll(text: string, type?: TelegramKeyboardButtonPollType["type"]): TelegramKeyboardButton; /** * If specified, the described [Web App](https://core.telegram.org/bots/webapps) will be launched when the button is pressed. The Web App will be able to send a “web\_app\_data” service message. Available in private chats only. * @example * ```ts * new Keyboard().webApp("some button text", "https://..."); * ``` */ webApp(text: string, url: string): this; /** * If specified, the described [Web App](https://core.telegram.org/bots/webapps) will be launched when the button is pressed. The Web App will be able to send a “web\_app\_data” service message. Available in private chats only. */ static webApp(text: string, url: string): TelegramKeyboardButton; /** * Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to *false*. * @example * ```ts * new Keyboard().text("some text").oneTime(); // to enable * new Keyboard().text("some text").oneTime(false); // to disable * ``` */ oneTime(isEnabled?: boolean): this; /** * Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to *false*, in which case the custom keyboard can be hidden and opened with a keyboard icon. * @example * ```ts * new Keyboard().text("some text").persistent(); // to enable * new Keyboard().text("some text").persistent(false); // to disable * ``` */ persistent(isEnabled?: boolean): this; /** * The placeholder to be shown in the input field when the keyboard is active; 1-64 characters * @example * ```ts * new Keyboard().text("some text").placeholder("some text"); // to enable * new Keyboard().text("some text").placeholder(); // to disable * ``` */ placeholder(value?: string): this; /** * !**Note** Keyboard is resized by default! For disable it you can use `.resized(false)` * * Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to *false*, in which case the custom keyboard is always of the same height as the app's standard keyboard. * @example * ```ts * new Keyboard().text("some text").resized(); // to enable * new Keyboard().text("some text").resized(false); // to disable * ``` */ resized(isEnabled?: boolean): this; /** * Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are \@mentioned in the *text* of the [Message](https://core.telegram.org/bots/api/#message) object; 2) if the bot's message is a reply to a message in the same chat and forum topic, sender of the original message. * * *Example:* A user requests to change the bot's language, bot replies to the request with a keyboard to select the new language. Other users in the group don't see the keyboard. * @example * ```ts * new Keyboard().text("some text").selective(); // to enable * new Keyboard().text("some text").selective(false); // to disable * ``` */ selective(isEnabled?: boolean): this; /** * Allows you to combine keyboards. Only keyboards are combined. You need to call the `.row()` method to line-break after combine. * * @example * ```ts * new Keyboard() * .combine(new Keyboard().text("first")) * .row() * .combine(new Keyboard().text("second").row().text("third")) * ``` */ combine(keyboard: TelegramKeyboardButton[][] | TelegramReplyKeyboardMarkup | { toJSON: () => TelegramReplyKeyboardMarkup; }): this; /** * Return {@link TelegramReplyKeyboardMarkup} as object */ build(): TelegramReplyKeyboardMarkup; /** * Serializing a class into an {@link TelegramReplyKeyboardMarkup} object (used by JSON.stringify) */ toJSON(): TelegramReplyKeyboardMarkup; } declare namespace InlineKeyboardButton { interface AbstractInlineKeyboardButton { text: string; } interface UrlButton extends AbstractInlineKeyboardButton { url: string; } interface CallbackButton extends AbstractInlineKeyboardButton { callback_data: string; } interface WebAppButton extends AbstractInlineKeyboardButton { web_app: TelegramWebAppInfo; } interface LoginButton extends AbstractInlineKeyboardButton { login_url: TelegramLoginUrl; } interface SwitchInlineButton extends AbstractInlineKeyboardButton { switch_inline_query: string; } interface SwitchInlineCurrentChatButton extends AbstractInlineKeyboardButton { switch_inline_query_current_chat: string; } interface SwitchInlineChosenChatButton extends AbstractInlineKeyboardButton { switch_inline_query_chosen_chat: TelegramSwitchInlineQueryChosenChat; } interface GameButton extends AbstractInlineKeyboardButton { callback_game: TelegramCallbackGame; } interface PayButton extends AbstractInlineKeyboardButton { pay: boolean; } interface CopyTextButtonButton extends AbstractInlineKeyboardButton { /** Description of the button that copies the specified text to the clipboard. */ copy_text: TelegramCopyTextButton; } } interface TelegramInlineKeyboardMarkupFix { inline_keyboard: (TelegramInlineKeyboardButton | InlineKeyboardButton.CallbackButton | InlineKeyboardButton.GameButton | InlineKeyboardButton.LoginButton | InlineKeyboardButton.PayButton | InlineKeyboardButton.SwitchInlineButton | InlineKeyboardButton.SwitchInlineCurrentChatButton | InlineKeyboardButton.SwitchInlineChosenChatButton | InlineKeyboardButton.CopyTextButtonButton | InlineKeyboardButton.UrlButton | InlineKeyboardButton.WebAppButton)[][]; } /** * **InlineKeyboardMarkup** builder * * This object represents an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards) that appears right next to the message it belongs to. * * {@link https://core.telegram.org/bots/api/#inlinekeyboardmarkup | [Documentation]} */ declare class InlineKeyboard extends BaseKeyboardConstructor<TelegramInlineKeyboardButton> { /** * Text button with data to be sent in a [callback query](https://core.telegram.org/bots/api/#callbackquery) to the bot when button is pressed, 1-64 bytes * @example * ```ts * new InlineKeyboard().text("some text", "payload"); * // or * new InlineKeyboard().text("some text", { * json: "payload", * }); // it uses JSON.stringify * ``` */ text(text: string, payload: string | Record<string, unknown>): this; /** * Text button with data to be sent in a [callback query](https://core.telegram.org/bots/api/#callbackquery) to the bot when button is pressed, 1-64 bytes */ static text(text: string, payload: string | Record<string, unknown>): TelegramInlineKeyboardButton; /** * HTTP or tg:// URL to be opened when the button is pressed. Links `tg://user?id=<user_id>` can be used to mention a user by their identifier without using a username, if this is allowed by their privacy settings. * @example * ```ts * new InlineKeyboard().url("GitHub", "https://github.com/gramiojs/gramio"); * ``` */ url(text: string, url: string): this; /** * HTTP or tg:// URL to be opened when the button is pressed. Links `tg://user?id=<user_id>` can be used to mention a user by their identifier without using a username, if this is allowed by their privacy settings. */ static url(text: string, url: string): TelegramInlineKeyboardButton; /** * Description of the [Web App](https://core.telegram.org/bots/webapps) that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method [answerWebAppQuery](https://core.telegram.org/bots/api/#answerwebappquery). Available only in private chats between a user and the bot. * @example * ```ts * new InlineKeyboard().webApp("some text", "https://..."); * ``` */ webApp(text: string, url: string): this; /** * Description of the [Web App](https://core.telegram.org/bots/webapps) that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method [answerWebAppQuery](https://core.telegram.org/bots/api/#answerwebappquery). Available only in private chats between a user and the bot. */ static webApp(text: string, url: string): TelegramInlineKeyboardButton; /** * An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the [Telegram Login Widget](https://core.telegram.org/widgets/login). * @example * ```ts * new InlineKeyboard().login("some text", "https://..."); * // or * new InlineKeyboard().login("some text", { * url: "https://...", * request_write_access: true, *}); * ``` */ login(text: string, url: string | TelegramLoginUrl): this; /** * An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the [Telegram Login Widget](https://core.telegram.org/widgets/login). */ static login(text: string, url: string | TelegramLoginUrl): TelegramInlineKeyboardButton; /** * Send a [Pay button](https://core.telegram.org/bots/api/#payments). * * **NOTE:** This type of button **must** always be the first button in the first row and can only be used in invoice messages. * @example * ```ts * new InlineKeyboard().pay("5 coins"); * ``` */ pay(text: string): this; /** * Send a [Pay button](https://core.telegram.org/bots/api/#payments). * * **NOTE:** This type of button **must** always be the first button in the first row and can only be used in invoice messages. */ static pay(text: string): TelegramInlineKeyboardButton; /** * Pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. * * By default empty, in which case just the bot's username will be inserted. * @example * ```ts * new InlineKeyboard().switchToChat("Select chat"); * // or * new InlineKeyboard().switchToChat("Select chat", "InlineQuery"); * ``` */ switchToChat(text: string, query?: string): this; /** * If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. * * By default empty, in which case just the bot's username will be inserted. */ static switchToChat(text: string, query?: string): TelegramInlineKeyboardButton; /** * Pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field * @example * ```ts * new InlineKeyboard().switchToChosenChat("Select chat"); * // or * new InlineKeyboard().switchToChosenChat("Select chat", "InlineQuery"); * // or * new InlineKeyboard().switchToChosenChat("Select chat", { * query: "InlineQuery", * allow_channel_chats: true, * allow_group_chats: true, * allow_bot_chats: true, * allow_user_chats: true, * }); * ``` */ switchToChosenChat(text: string, query?: string | TelegramSwitchInlineQueryChosenChat): this; /** * Pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field */ static switchToChosenChat(text: string, query?: string | TelegramSwitchInlineQueryChosenChat): TelegramInlineKeyboardButton; /** * Pressing the button will insert the bot's username and the specified inline query in the current chat's input field. May be empty, in which case only the bot's username will be inserted. * * This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options. * @example * ```ts * new InlineKeyboard().switchToChosenChat("Open Inline mod"); * // or * new InlineKeyboard().switchToChosenChat("Open Inline mod", "InlineQuery"); * ``` */ switchToCurrentChat(text: string, query?: string): this; /** * Pressing the button will insert the bot's username and the specified inline query in the current chat's input field. May be empty, in which case only the bot's username will be inserted. * * This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options. */ static switchToCurrentChat(text: string, query?: string): TelegramInlineKeyboardButton; /** * Description of the game that will be launched when the user presses the button. * * **NOTE:** This type of button **must** always be the first button in the first row. * @example * ```ts * new InlineKeyboard().game("text", ???); * ``` */ game(text: string, gameOptions?: TelegramCallbackGame): this; /** * Description of the game that will be launched when the user presses the button. * * **NOTE:** This type of button **must** always be the first button in the first row. */ static game(text: string, gameOptions?: TelegramCallbackGame): TelegramInlineKeyboardButton; copy(text: string, textToCopy: string | TelegramCopyTextButton): this; static copy(text: string, textToCopy: string | TelegramCopyTextButton): TelegramInlineKeyboardButton; /** * Allows you to combine keyboards. Only keyboards are combined. You need to call the `.row()` method to line-break after combine. * * @example * ```ts * new InlineKeyboard() * .combine(new InlineKeyboard().text("some", "payload")) * .row() * .combine( * new InlineKeyboard() * .text("test", "payload") * .row() * .text("second row???", "payload"), * ) * ``` */ combine(keyboard: TelegramInlineKeyboardButton[][] | TelegramInlineKeyboardMarkup | { toJSON: () => TelegramInlineKeyboardMarkup; }): this; /** * Return {@link TelegramInlineKeyboardMarkup} as JSON */ build(): TelegramInlineKeyboardMarkupFix; /** * Serializing a class into an {@link TelegramInlineKeyboardMarkupFix} object (used by JSON.stringify) */ toJSON(): TelegramInlineKeyboardMarkupFix; } /** * **ReplyKeyboardRemove** builder * * Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see [ReplyKeyboardMarkup](https://core.telegram.org/bots/api/#replykeyboardmarkup)). * * {@link https://core.telegram.org/bots/api/#replykeyboardremove | [Documentation]} */ declare class RemoveKeyboard { options: { isSelective: boolean; }; /** * Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are \@mentioned in the *text* of the [Message](https://core.telegram.org/bots/api/#message) object; 2) if the bot's message is a reply to a message in the same chat and forum topic, sender of the original message. * * *Example:* A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. * @example * ```ts * new RemoveKeyboard().selective(); // to enable * new RemoveKeyboard().selective(false); // to disable * ``` */ selective(isEnabled?: boolean): this; /** * Return {@link TelegramReplyKeyboardRemove} as object */ build(): TelegramReplyKeyboardRemove; /** * Serializing a class into an {@link TelegramReplyKeyboardRemove} object (used by JSON.stringify) */ toJSON(): TelegramReplyKeyboardRemove; } /** * **ForceReply** builder * * Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot's message and tapped 'Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice [privacy mode](https://core.telegram.org/bots/features#privacy-mode). * * {@link https://core.telegram.org/bots/api/#forcereply | [Documentation]} */ declare class ForceReplyKeyboard { options: { isSelective: boolean; placeholder: string | undefined; }; /** * Use this parameter if you want to force reply from specific users only. Targets: 1) users that are \@mentioned in the *text* of the [Message](https://core.telegram.org/bots/api/#message) object; 2) if the bot's message is a reply to a message in the same chat and forum topic, sender of the original message. * @example * ```ts * new ForceReplyKeyboard().selective(); // to enable * new ForceReplyKeyboard().selective(false); // to disable * ``` */ selective(isEnabled?: boolean): this; /** * The placeholder to be shown in the input field when the reply is active; 1-64 characters * @example * ```ts * new Keyboard().placeholder("some text"); // to enable * new Keyboard().placeholder(); // to disable * ``` */ placeholder(value?: string): this; /** * Return {@link TelegramForceReply} as JSON */ build(): TelegramForceReply; /** * Serializing a class into an {@link TelegramForceReply} object (used by JSON.stringify) */ toJSON(): TelegramForceReply; } /** * This object represents the content of a message to be sent as a result of an inline query. * * @example * ```typescript * bot.api.answerInlineQuery({ * inline_query_id: context.id, * results: [ * InlineQueryResult.article( * "id-1", * "some article", * InputMessageContent.text("my article"), * ), * ], * }); * ``` * * [Documentation](https://core.telegram.org/bots/api/#inputmessagecontent) */ declare class InputMessageContent { /** * Represents the [content](https://core.telegram.org/bots/api/#inputmessagecontent) of a text message to be sent as the result of an inline query. * * [Documentation](https://core.telegram.org/bots/api/#inputtextmessagecontent) */ static text(text: TelegramInputTextMessageContent["message_text"], options?: Omit<TelegramInputTextMessageContent, "message_text">): TelegramInputTextMessageContent; /** * Represents the [content](https://core.telegram.org/bots/api/#inputmessagecontent) of a location message to be sent as the result of an inline query. * * [Documentation](https://core.telegram.org/bots/api/#inputlocationmessagecontent) */ static location(latitude: number, longitude: number, options?: Omit<TelegramInputLocationMessageContent, "latitude" | "longitude">): TelegramInputLocationMessageContent; /** * Represents the [content](https://core.telegram.org/bots/api/#inputmessagecontent) of a venue message to be sent as the result of an inline query. * * [Documentation](https://core.telegram.org/bots/api/#inputvenuemessagecontent) */ static venue(options: TelegramInputVenueMessageContent): TelegramInputLocationMessageContent; /** * Represents the [content](https://core.telegram.org/bots/api/#inputmessagecontent) of a contact message to be sent as the result of an inline query. * * [Documentation](https://core.telegram.org/bots/api/#inputcontactmessagecontent) */ static contact(phoneNumber: string, firstName: string, options?: Omit<TelegramInputContactMessageContent, "phone_number" | "first_name">): TelegramInputContactMessageContent; /** * Represents the [content](https://core.telegram.org/bots/api/#inputmessagecontent) of an invoice message to be sent as the result of an inline query. * * [Documentation](https://core.telegram.org/bots/api/#inputinvoicemessagecontent) */ static invoice(options: TelegramInputInvoiceMessageContent): TelegramInputInvoiceMessageContent; } /** Cached result of InlineQuery builder. */ declare class InlineQueryResultCached { /** * Represents a link to an MP3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the audio. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcachedaudio) */ static audio(id: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedAudio, "type" | "audio_file_id" | "id">): TelegramInlineQueryResultCachedAudio; /** * Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the file. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcacheddocument) */ static document(id: string, title: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedDocument, "type" | "document_file_id" | "id" | "title">): TelegramInlineQueryResultCachedDocument; /** * Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with specified content instead of the animation. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcachedgif) */ static gif(id: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedGif, "type" | "gif_file_id" | "id">): TelegramInlineQueryResultCachedGif; /** * Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the animation. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcachedmpeg4gif) */ static mpeg4Gif(id: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedMpeg4Gif, "type" | "mpeg4_file_id" | "id">): TelegramInlineQueryResultCachedMpeg4Gif; /** * Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the photo. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcachedphoto) */ static photo(id: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedPhoto, "type" | "photo_file_id" | "id">): TelegramInlineQueryResultCachedPhoto; /** * Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the sticker. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcachedsticker) */ static sticker(id: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedSticker, "type" | "sticker_file_id" | "id">): TelegramInlineQueryResultCachedSticker; /** * Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the video. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcachedvideo) */ static video(id: string, title: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedVideo, "type" | "video_file_id" | "id" | "title">): TelegramInlineQueryResultCachedVideo; /** * Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the voice message. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcachedvoice) */ static voice(id: string, title: string, fileId: string, options?: Omit<TelegramInlineQueryResultCachedVoice, "type" | "voice_file_id" | "id" | "title">): TelegramInlineQueryResultCachedVoice; } /** * Result of InlineQuery builder. * * @example * ```ts * bot.api.answerInlineQuery({ * inline_query_id: context.id, * results: [ * InlineQueryResult.article( * "id-1", * "some article", * InputMessageContent.text("my article"), * ), * ], * }); * ``` * * [Documentation](https://core.telegram.org/bots/api#inlinequeryresult) */ declare class InlineQueryResult { /** Cached result of InlineQuery builder. */ static cached: typeof InlineQueryResultCached; /** * Represents a link to an article or web page. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultarticle) */ static article(id: string, title: string, inputMessageContent: TelegramInputMessageContent, options?: Omit<TelegramInlineQueryResultArticle, "type" | "title" | "id" | "input_message_content">): TelegramInlineQueryResultArticle; /** * Represents a link to an MP3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the audio. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultaudio) */ static audio(id: string, title: string, audioUrl: string, options?: Omit<TelegramInlineQueryResultAudio, "type" | "title" | "id" | "audio_url">): TelegramInlineQueryResultAudio; /** * Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the contact. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultcontact) */ static contact(id: string, phoneNumber: string, firstName: string, options?: Omit<TelegramInlineQueryResultContact, "type" | "phone_number" | "id" | "first_name">): TelegramInlineQueryResultContact; /** * Represents a [Game](https://core.telegram.org/bots/api/#games). * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultgame) */ static game(id: string, gameShortName: string, options?: Omit<TelegramInlineQueryResultGame, "type" | "game_short_name" | "id">): TelegramInlineQueryResultGame; /** * Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the file. Currently, only **.PDF** and **.ZIP** files can be sent using this method. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultdocument) */ static documentPdf(id: string, title: string, url: string, options?: Omit<TelegramInlineQueryResultDocument, "type" | "mime_type" | "id" | "title" | "document_url">): TelegramInlineQueryResultDocument; /** * Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the file. Currently, only **.PDF** and **.ZIP** files can be sent using this method. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultdocument) */ static documentZip(id: string, title: string, url: string, options?: Omit<TelegramInlineQueryResultDocument, "type" | "mime_type" | "id" | "title" | "document_url">): TelegramInlineQueryResultDocument; /** * Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the animation. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultgif) */ static gif(id: string, gifUrl: string, thumbnailUrl: string, options?: Omit<TelegramInlineQueryResultGif, "type" | "gif_url" | "id" | "thumbnail_url">): TelegramInlineQueryResultGif; /** * Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the location. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultlocation) */ static location(id: string, latitude: number, longitude: number, title: string, options?: Omit<TelegramInlineQueryResultLocation, "type" | "latitude" | "id" | "longitude" | "title">): TelegramInlineQueryResultLocation; /** * Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the animation. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultmpeg4gif) */ static mpeg4Gif(id: string, mpeg4Url: string, thumbnailUrl: string, options?: Omit<TelegramInlineQueryResultMpeg4Gif, "type" | "mpeg4_url" | "id" | "thumbnail_url">): TelegramInlineQueryResultMpeg4Gif; /** * Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the photo. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultphoto) */ static photo(id: string, photoUrl: string, thumbnailUrl: string, options?: Omit<TelegramInlineQueryResultPhoto, "type" | "photo_url" | "id" | "thumbnail_url">): TelegramInlineQueryResultPhoto; /** * Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the venue. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultvenue) */ static venue(id: string, options: Omit<TelegramInlineQueryResultVenue, "type" | "id">): TelegramInlineQueryResultVenue; /** * Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the video. * * If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you **must** replace its content using *input\_message\_content*. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultvideo) */ static videoHtml(id: string, title: string, videoUrl: string, thumbnailUrl: string, options?: Omit<TelegramInlineQueryResultVideo, "type" | "video_url" | "id" | "thumbnail_url" | "mime_type" | "title">): TelegramInlineQueryResultVideo; /** * Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the video. * * If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you **must** replace its content using *input\_message\_content*. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultvideo) */ static videoMp4(id: string, title: string, videoUrl: string, thumbnailUrl: string, options?: Omit<TelegramInlineQueryResultVideo, "type" | "video_url" | "id" | "thumbnail_url" | "mime_type" | "title">): TelegramInlineQueryResultVideo; /** * Represents a link to a voice recording in an .OGG container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use *input\_message\_content* to send a message with the specified content instead of the the voice message. * * [Documentation](https://core.telegram.org/bots/api/#inlinequeryresultvoice) */ static voice(id: string, title: string, url: string, options?: Omit<TelegramInlineQueryResultVoice, "type" | "voice_url" | "id" | "title">): TelegramInlineQueryResultVoice; } export { BaseKeyboardConstructor, type ButtonsIterator, type CreateButtonIterator, ForceReplyKeyboard, InlineKeyboard, InlineQueryResult, InputMessageContent, Keyboard, type KeyboardFeatureFlags, type KeyboardHelperColumns, type KeyboardHelperFilter, type KeyboardHelperPattern, type KeyboardHelperWrap, type KeyboardHelpers, RemoveKeyboard, chunk, customWrap, filter, keyboardsFeatureFlagsMap, pattern };