### Basic Telegraf Bot Example Source: https://telegraf.js.org/index.html A fundamental example demonstrating how to create a Telegraf bot, handle basic commands like start and help, and respond to messages and stickers. It includes setup for graceful shutdown. ```javascript const { Telegraf } = require('telegraf') const { message } = require('telegraf/filters') const bot = new Telegraf(process.env.BOT_TOKEN) bot.start((ctx) => ctx.reply('Welcome')) bot.help((ctx) => ctx.reply('Send me a sticker')) bot.on(message('sticker'), (ctx) => ctx.reply('👍')) bot.hears('hi', (ctx) => ctx.reply('Hey there')) bot.launch() // Enable graceful stop process.once('SIGINT', () => bot.stop('SIGINT')) process.once('SIGTERM', () => bot.stop('SIGTERM')) ``` -------------------------------- ### Install Telegraf using npm Source: https://telegraf.js.org/index.html Command to install the Telegraf library using npm. ```bash $ npm install telegraf ``` -------------------------------- ### Start Webhook via launch Method Source: https://telegraf.js.org/index.html Launches the Telegraf bot using the launch method with webhook configuration. This is the preferred method for starting a webhook server. Ensure you provide the webhook domain, port, and optionally a path and secret token for security. ```javascript import { Telegraf } from "telegraf"; import { message } from 'telegraf/filters'; const bot = new Telegraf(token); bot.on(message("text"), ctx => ctx.reply("Hello")); // Start webhook via launch method (preferred) bot.launch({ webhook: { // Public domain for webhook; e.g.: example.com domain: webhookDomain, // Port to listen on; e.g.: 8080 port: port, // Optional path to listen for. // `bot.secretPathComponent()` will be used by default path: webhookPath, // Optional secret to be sent back in a header for security. // e.g.: `crypto.randomBytes(64).toString("hex")` secretToken: randomAlphaNumericString, }, }); ``` -------------------------------- ### Install Telegraf using yarn Source: https://telegraf.js.org/index.html Command to install the Telegraf library using yarn. ```bash $ yarn add telegraf ``` -------------------------------- ### Install Telegraf using pnpm Source: https://telegraf.js.org/index.html Command to install the Telegraf library using pnpm. ```bash $ pnpm add telegraf ``` -------------------------------- ### getFile Source: https://telegraf.js.org/classes/Telegram.html Get basic info about a file and prepare it for downloading. ```APIDOC ## getFile ### Description Get basic info about a file and prepare it for downloading. ### Method GET ### Endpoint /getFile ### Parameters #### Path Parameters None #### Query Parameters * **fileId** (string) - Required - Id of file to get link to ### Request Example ```json { "fileId": "AgADBAADGyc4MRy1m_p_x3_x_x" } ``` ### Response #### Success Response (200) * **File** - Basic information about the file. ``` -------------------------------- ### start Source: https://telegraf.js.org/classes/Telegraf-1.html Registers a middleware for handling the /start command. This method allows you to define custom logic that should be executed when a user initiates a chat with the bot using the /start command. ```APIDOC ## start ### Description Registers a middleware for handling /start. ### Method start ### Parameters * `...fns` (NonemptyReadonlyArray>>) - The middleware functions to register for handling the /start command. ### Returns Telegraf ``` -------------------------------- ### Telegraf Bot with Command Handlers Source: https://telegraf.js.org/index.html An example showcasing how to define specific command handlers for a Telegraf bot, including a simple reply and a lambda-based reply. It also includes setup for graceful shutdown. ```javascript const { Telegraf } = require('telegraf') const bot = new Telegraf(process.env.BOT_TOKEN) bot.command('oldschool', (ctx) => ctx.reply('Hello')) bot.command('hipster', Telegraf.reply('λ')) bot.launch() // Enable graceful stop process.once('SIGINT', () => bot.stop('SIGINT')) process.once('SIGTERM', () => bot.stop('SIGTERM')) ``` -------------------------------- ### getMe Source: https://telegraf.js.org/classes/Telegram.html Get basic information about the bot. ```APIDOC ## getMe ### Description Get basic information about the bot. ### Method GET ### Endpoint /getMe ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) * **UserFromGetMe** - Basic information about the bot. ``` -------------------------------- ### Telegraf Middleware Example with Timing Source: https://telegraf.js.org/index.html An example of a Telegraf middleware that measures the processing time for each incoming update. It uses `console.time` and `console.timeEnd` to log the duration. This middleware must call `await next()` to pass control to the next middleware in the chain. ```javascript import { Telegraf } from 'telegraf'; import { message } from 'telegraf/filters'; const bot = new Telegraf(process.env.BOT_TOKEN); bot.use(async (ctx, next) => { console.time(`Processing update ${ctx.update.update_id}`); await next() // runs next middleware // runs after next middleware finishes console.timeEnd(`Processing update ${ctx.update.update_id}`); }) bot.on(message('text'), (ctx) => ctx.reply('Hello World')); bot.launch(); // Enable graceful stop process.once('SIGINT', () => bot.stop('SIGINT')); process.once('SIGTERM', () => bot.stop('SIGTERM')); ``` -------------------------------- ### getWebhookInfo Source: https://telegraf.js.org/classes/Telegram.html Retrieves information about the bot's webhook setup. ```APIDOC ## getWebhookInfo ### Description Retrieves information about the bot's webhook setup. ### Method GET (assumed, based on typical API patterns for retrieval) ### Endpoint /getWebhookInfo ### Returns Promise ``` -------------------------------- ### Composer.start Source: https://telegraf.js.org/classes/Composer.html Registers middleware for handling the /start command. ```APIDOC ## Composer.start ### Description Registers a middleware for handling the /start command. ### Method `start(...fns)` ### Parameters * **...fns** (NonemptyReadonlyArray & Omit> & StartContextExtn>>) - The middleware functions to apply. ### Returns Composer ``` -------------------------------- ### launch (with config) Source: https://telegraf.js.org/classes/Telegraf-1.html Launches the bot with configuration options. Optionally accepts a callback function to be executed once the bot has launched. ```APIDOC ## launch ### Description Launches the bot with configuration options. Optionally accepts a callback function to be executed once the bot has launched. ### Method `launch(config, onLaunch?)` ### Parameters * `config`: `LaunchOptions` * `onLaunch` (Optional): `()` => `void` ### Returns `Promise` ### See https://github.com/telegraf/telegraf/discussions/1344#discussioncomment-335700 ``` -------------------------------- ### launch (no config) Source: https://telegraf.js.org/classes/Telegraf-1.html Launches the bot. Optionally accepts a callback function to be executed once the bot has launched. ```APIDOC ## launch ### Description Launches the bot. Optionally accepts a callback function to be executed once the bot has launched. ### Method `launch(onLaunch?)` ### Parameters * `onLaunch` (Optional): `()` => `void` ### Returns `Promise` ### See https://github.com/telegraf/telegraf/discussions/1344#discussioncomment-335700 ``` -------------------------------- ### help Source: https://telegraf.js.org/classes/Scenes.Stage.html Registers a middleware specifically for handling the /help command. ```APIDOC ## help ### Description Registers a middleware for handling /help. ### Parameters * **`Rest` ...fns**: NonemptyReadonlyArray & Omit> & CommandContextExtn>> ### Returns Stage ``` -------------------------------- ### help Source: https://telegraf.js.org/classes/Scenes.WizardScene.html Registers a middleware for handling the /help command. This method provides a convenient way to offer help information to users within the wizard flow. ```APIDOC ## help ### Description Registers a middleware for handling /help command. ### Method `help(...fns)` ### Parameters #### Path Parameters * **`Rest` ...fns** (NonemptyReadonlyArray & Omit> & CommandContextExtn>>) - Middleware functions to execute for the /help command. ### Returns WizardScene ``` -------------------------------- ### getFileLink Source: https://telegraf.js.org/classes/Telegram.html Get download link to a file. ```APIDOC ## getFileLink ### Description Get download link to a file. ### Method GET ### Endpoint /getFileLink ### Parameters #### Path Parameters None #### Query Parameters * **fileId** (string | File) - Required - The file ID or File object. ### Request Example ```json { "fileId": "AgADBAADGyc4MRy1m_p_x3_x_x" } ``` ### Response #### Success Response (200) * **URL** - The download URL for the file. ``` -------------------------------- ### help Source: https://telegraf.js.org/classes/Telegraf-1.html Registers a middleware for handling the /help command. ```APIDOC ## help ### Description Registers a middleware for handling the /help command. ### Method POST ### Endpoint /help ### Parameters #### Request Body - **...fns** (Middleware) - Required - The middleware functions to handle the /help command. ### Returns Telegraf ``` -------------------------------- ### help Source: https://telegraf.js.org/classes/Scenes.BaseScene.html Registers a middleware for handling the /help command. It accepts a list of middleware functions. ```APIDOC ## help ### Description Registers a middleware for handling the /help command. It accepts a list of middleware functions. ### Method `help(...fns)` ### Parameters * **`Rest` ...fns**: NonemptyReadonlyArray> & CommandContextExtn>> ### Returns BaseScene ``` -------------------------------- ### WizardScene Constructor Source: https://telegraf.js.org/classes/Scenes.WizardScene.html Instantiates a new WizardScene. It can be created with either just an ID and steps, or with an ID, options, and steps. ```APIDOC ## new WizardScene(id, ...steps) ### Description Creates a new WizardScene instance with the given ID and a sequence of middleware steps. ### Parameters * **id** (string) - The unique identifier for this scene. * **`Rest` ...steps** (Middleware[]) - A variable number of middleware functions that define the steps of the wizard. ### Returns WizardScene ``` ```APIDOC ## new WizardScene(id, options, ...steps) ### Description Creates a new WizardScene instance with the given ID, scene options, and a sequence of middleware steps. ### Parameters * **id** (string) - The unique identifier for this scene. * **options** (SceneOptions) - Options for configuring the scene. * **`Rest` ...steps** (Middleware[]) - A variable number of middleware functions that define the steps of the wizard. ### Returns WizardScene ``` -------------------------------- ### getMyDescription Source: https://telegraf.js.org/classes/Telegram.html Use this method to get the current bot description for the given user language. ```APIDOC ## getMyDescription ### Description Use this method to get the current bot description for the given user language. ### Method GET ### Endpoint /getMyDescription ### Parameters #### Path Parameters None #### Query Parameters * **language_code** (string) - Optional - A two-letter ISO 639-1 language code. ### Request Example ```json { "language_code": "en" } ``` ### Response #### Success Response (200) * **BotDescription** - The current bot description. ``` -------------------------------- ### getStickerSet Source: https://telegraf.js.org/interfaces/Scenes.SceneContext.html Use this method to get a sticker set. Deprecated, use Telegram.getStickerSet instead. ```APIDOC ## getStickerSet ### Description Retrieves a sticker set by its name. ### Method `getStickerSet(setName: string)` ### Parameters #### Path Parameters - **setName** (string) - Required - The name of the sticker set. ### Returns `Promise` ### Deprecated Use `Telegram.getStickerSet` instead. ### See https://core.telegram.org/bots/api#getstickerset ``` -------------------------------- ### Composer.use Source: https://telegraf.js.org/classes/Composer.html Registers a general middleware. ```APIDOC ## Composer.use ### Description Registers a middleware. ### Method `use(...fns)` ### Parameters * **...fns** (readonly Middleware[]) - The middleware functions to apply. ### Returns Composer ``` -------------------------------- ### help Source: https://telegraf.js.org/classes/Composer.html Registers middleware for handling the /help command. It accepts a list of middleware functions to process help requests. ```APIDOC ## help ### Description Registers a middleware for handling /help. It accepts a list of middleware functions to process help requests. ### Method Not applicable (SDK method) ### Signature `help(...fns): Composer` ### Parameters * **`Rest` ...fns**: NonemptyReadonlyArray> & CommandContextExtn>> ### Returns Composer ``` -------------------------------- ### getChatMembersCount Source: https://telegraf.js.org/interfaces/Scenes.SceneContext.html Use this method to get the number of members in a chat. Returns an integer on success. ```APIDOC ## getChatMembersCount ### Description Retrieves the total number of members in the chat. ### Method `getChatMembersCount(...args)` ### Returns `Promise` ### See https://core.telegram.org/bots/api#getchatmembercount ``` -------------------------------- ### token Accessor Source: https://telegraf.js.org/classes/Telegraf-1.html Gets the bot's token. This is a private accessor and should not be used directly. ```APIDOC ## get token ### Description Gets the bot's token. ### Returns string ``` -------------------------------- ### WizardContextWizard.back Source: https://telegraf.js.org/classes/Scenes.WizardContextWizard.html Navigates the wizard to the previous step. ```APIDOC ## back() ### Description Navigates the wizard to the previous step. ### Returns WizardContextWizard ``` -------------------------------- ### getChatMember Source: https://telegraf.js.org/interfaces/Scenes.SceneContext.html Use this method to get information about a member of a chat. Returns a ChatMember object on success. ```APIDOC ## getChatMember ### Description Retrieves information about a specific chat member. ### Method `getChatMember(...args: [userId: number])` ### Parameters #### Path Parameters - **userId** (number) - Required - The ID of the user to retrieve information for. ### Returns `Promise` ### See https://core.telegram.org/bots/api#getchatmember ``` -------------------------------- ### WizardContextWizard.next Source: https://telegraf.js.org/classes/Scenes.WizardContextWizard.html Navigates the wizard to the next step. ```APIDOC ## next() ### Description Navigates the wizard to the next step. ### Returns WizardContextWizard ``` -------------------------------- ### getChatAdministrators Source: https://telegraf.js.org/interfaces/Scenes.SceneContext.html Use this method to get a list of administrators in a chat. Returns an array of ChatMember objects. ```APIDOC ## getChatAdministrators ### Description Retrieves a list of administrators for the current chat. ### Method `getChatAdministrators(...args)` ### Returns `Promise<(ChatMemberOwner | ChatMemberAdministrator)[]>` ### See https://core.telegram.org/bots/api#getchatadministrators ``` -------------------------------- ### WizardContextWizard.cursor Source: https://telegraf.js.org/classes/Scenes.WizardContextWizard.html Manages the current step index of the wizard. It can be used to get or set the current cursor. ```APIDOC ## cursor ### Description Gets or sets the current step index of the wizard. ### Accessors * **get cursor(): number** - Returns the current step index. * **set cursor(cursor: number): void** - Sets the current step index. ``` -------------------------------- ### getMyDefaultAdministratorRights Source: https://telegraf.js.org/classes/Telegram.html Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success. ```APIDOC ## getMyDefaultAdministratorRights ### Description Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success. ### Method GET ### Endpoint /getMyDefaultAdministratorRights ### Parameters #### Path Parameters None #### Query Parameters * **forChannels** (boolean) - Optional - Pass true to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned. ### Request Example ```json { "forChannels": true } ``` ### Response #### Success Response (200) * **ChatAdministratorRights** - The default administrator rights of the bot. ``` -------------------------------- ### BaseScene Methods Source: https://telegraf.js.org/classes/Scenes.BaseScene.html Lists the methods available on BaseScene instances for handling various user inputs and managing scene transitions. ```APIDOC ## Methods ### action * **Signature**: `action(triggers, ...fns): BaseScene` * **Description**: Registers middleware for handling callback queries that match the provided triggers. * **Parameters**: * **triggers**: Triggers>> - The callback query triggers to match. * **...fns**: MatchedMiddleware - Middleware functions to execute. * **Returns**: `BaseScene` ### cashtag * **Signature**: `cashtag(cashtag, ...fns): BaseScene` * **Description**: Registers middleware for handling messages containing cashtags. * **Parameters**: * **cashtag**: MaybeArray - The cashtag(s) to match. * **...fns**: MatchedMiddleware - Middleware functions to execute. * **Returns**: `BaseScene` ### command * **Signature**: `command(command, ...fns): BaseScene` * **Description**: Registers middleware for handling specified commands. * **Parameters**: * **command**: Triggers> - The command(s) to match. * **...fns**: NonemptyReadonlyArray> & Omit> & CommandContextExtn>> - Middleware functions to execute. * **Returns**: `BaseScene` ### drop * **Signature**: `drop(predicate): BaseScene` * **Description**: Registers middleware for dropping updates that satisfy the given predicate. * **Parameters**: * **predicate**: Function - A function that returns true if the update should be dropped. * **Returns**: `BaseScene` ``` -------------------------------- ### getChat Source: https://telegraf.js.org/interfaces/Scenes.SceneContext.html Gets information about a chat. This method is a wrapper around the Telegram Bot API's getChat method. ```APIDOC ## getChat ### Description Gets information about a chat. This method returns basic information about the chat (chat type, title, all members count, etc.). ### Method Not specified (likely a method call on a SceneContext object). ### Parameters #### Path Parameters None. #### Query Parameters None. #### Request Body None. ### Request Example ```json getChat() ``` ### Response #### Success Response (200) - **result** (ChatFromGetChat) - An object containing information about the chat. #### Response Example ```json { "id": 123456789, "type": "private", "first_name": "John", "username": "john_doe" } ``` ``` -------------------------------- ### inlineKeyboard(buttons, options) Source: https://telegraf.js.org/functions/Markup.inlineKeyboard.html Creates an inline keyboard with the specified buttons and optional building options. ```APIDOC ## inlineKeyboard(buttons, options) ### Description Creates an inline keyboard with the specified buttons and optional building options. ### Parameters #### buttons - **buttons** (HideableIKBtn[]) - Required - An array of HideableIKBtn objects representing the buttons for the keyboard. #### options - **options** (Partial>) - Optional - Configuration options for building the keyboard, such as text wrapping or column count. ``` -------------------------------- ### setPassportDataErrors Source: https://telegraf.js.org/classes/Telegram.html Informs the user that there are errors in the provided Telegram Passport data. This is used to guide the user in correcting their information. ```APIDOC ## setPassportDataErrors ### Description Informs the user of errors in their Telegram Passport data. ### Method POST ### Endpoint /setPassportDataErrors ### Parameters #### Request Body - **userId** (number) - Required - The ID of the user whose data has errors. - **errors** (readonly PassportElementError[]) - Required - An array of errors found in the Passport data. ### Request Example ```json { "userId": 123456789, "errors": [ { "source": "passport", "type": "invalid_element_error", "element_hash": "some_hash", "message": "The document is blurry." } ] } ``` ### Response #### Success Response (200) - **ok** (boolean) - True if the operation was successful. #### Response Example ```json { "ok": true } ``` ``` -------------------------------- ### getMyDefaultAdministratorRights Source: https://telegraf.js.org/interfaces/Scenes.SceneContext.html Use this method to get the default administrator rights of the bot in the specified chat type. Returns ChatAdministratorRights on success. ```APIDOC ## getMyDefaultAdministratorRights ### Description Retrieves the default administrator rights for the bot. ### Method `getMyDefaultAdministratorRights(extra?: { forChannels?: boolean })` ### Parameters #### Query Parameters - **extra** (object) - Optional - Additional parameters. - **forChannels** (boolean) - Optional - Whether to get rights for channels. ### Returns `Promise` ### See https://core.telegram.org/bots/api#getmydefaultadministratorrights ``` -------------------------------- ### WizardContextWizard Constructor Source: https://telegraf.js.org/classes/Scenes.WizardContextWizard.html Initializes a new instance of the WizardContextWizard. It takes the context object and an array of middleware steps as arguments. ```APIDOC ## new WizardContextWizard(ctx, steps) ### Description Initializes a new instance of the WizardContextWizard. ### Parameters * **ctx** (C) - The context object. * **steps** (readonly Middleware[]) - An array of middleware functions representing the wizard steps. ### Returns WizardContextWizard ``` -------------------------------- ### BaseScene Constructor Source: https://telegraf.js.org/classes/Scenes.BaseScene.html Initializes a new BaseScene instance. It requires a unique ID and optionally accepts scene options. ```APIDOC ## new BaseScene(id, options?) ### Description Initializes a new BaseScene instance. ### Parameters * **id**: string - The unique identifier for the scene. * **options**: SceneOptions (Optional) - Configuration options for the scene. ``` -------------------------------- ### getStickerSet Source: https://telegraf.js.org/interfaces/Scenes.WizardContext.html Retrieves information about a sticker set. This method is used to get details about a collection of stickers, including their associated emojis and files. ```APIDOC ## getStickerSet ### Description Retrieves information about a sticker set. This method is used to get details about a collection of stickers, including their associated emojis and files. ### Method getStickerSet ### Parameters #### Path Parameters - **setName** (string) - Required - The name of the sticker set. ### Returns Promise ### Deprecated use Telegram.getStickerSet ### See https://core.telegram.org/bots/api#getstickerset ``` -------------------------------- ### enter Source: https://telegraf.js.org/classes/Scenes.WizardScene.html Registers middleware to be executed when entering the scene. This is typically used for initialization or setting up the scene's initial state. ```APIDOC ## enter ### Description Registers middleware to be executed when entering the scene. ### Method `enter(...fns)` ### Parameters #### Path Parameters * **`Rest` ...fns** (Middleware[]) - Middleware functions to execute upon entering the scene. ### Returns WizardScene ``` -------------------------------- ### getChat Source: https://telegraf.js.org/classes/Telegram.html Get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). ```APIDOC ## getChat ### Description Get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). ### Method GET ### Endpoint /getChat ### Parameters #### Path Parameters None #### Query Parameters * **chatId** (string | number) - Required - Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) ### Request Example ```json { "chatId": "@channelusername" } ``` ### Response #### Success Response (200) * **ChatFromGetChat** - Information about the chat. ``` -------------------------------- ### getChatMenuButton Source: https://telegraf.js.org/classes/Context.html Use this method to get the current value of the bot's menu button in the current private chat. Returns MenuButton on success. ```APIDOC ## getChatMenuButton ### Description Use this method to get the current value of the bot's menu button in the current private chat. Returns MenuButton on success. ### Method GET ### Endpoint /getChatMenuButton ### Parameters ### Request Example ```json { "example": "" } ``` ### Response #### Success Response (200) - **menuButton** (MenuButton) - Description of the menu button #### Response Example ```json { "example": "{...}" } ``` ``` -------------------------------- ### enter Source: https://telegraf.js.org/classes/Scenes.Stage.html Handles entering a specific scene, optionally setting an initial state and silent mode. ```APIDOC ## `Static` enter * enter(...args): ((ctx) => Promise) * #### Type Parameters * #### C extends Context & { scene: SceneContextScene; } #### Parameters * ##### `Rest` ...args: [sceneId: string, initialState: object, silent: boolean] `Rest` #### Returns ((ctx) => Promise) * * (ctx): Promise * #### Parameters * ##### ctx: C #### Returns Promise ``` -------------------------------- ### enterMiddleware Source: https://telegraf.js.org/classes/Scenes.BaseScene.html Returns a middleware function that handles entering the scene. ```APIDOC ## enterMiddleware ### Description Returns a middleware function that handles entering the scene. ### Method `enterMiddleware()` ### Returns MiddlewareFn ``` -------------------------------- ### getCustomEmojiStickers Source: https://telegraf.js.org/classes/Telegram.html Use this method to get a list of custom emoji stickers, which can be used as a forum topic icon by any user. Returns an Array of Sticker objects. ```APIDOC ## getCustomEmojiStickers ### Description Use this method to get a list of custom emoji stickers, which can be used as a forum topic icon by any user. Returns an Array of Sticker objects. ### Method GET ### Endpoint /getCustomEmojiStickers ### Parameters #### Path Parameters None #### Query Parameters * **custom_emoji_ids** (string[]) - Required - A list of custom emoji IDs. ### Request Example ```json { "custom_emoji_ids": ["5368497234567890000"] } ``` ### Response #### Success Response (200) * **Sticker[]** - An array of Sticker objects. ``` -------------------------------- ### getForumTopicIconStickers Source: https://telegraf.js.org/classes/Telegram.html Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects. ```APIDOC ## getForumTopicIconStickers ### Description Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects. ### Method GET ### Endpoint /getForumTopicIconStickers ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) * **Sticker[]** - An array of Sticker objects. ``` -------------------------------- ### keyboard(buttons, options) Source: https://telegraf.js.org/functions/Markup.keyboard.html Creates a reply keyboard markup with the specified buttons and optional configuration. This version expects a 1D array of buttons and allows for custom options. ```APIDOC ## keyboard(buttons, options) ### Description Creates a reply keyboard markup with the specified buttons and optional configuration. This version expects a 1D array of buttons and allows for custom options. ### Parameters #### Path Parameters * **buttons** (HideableKBtn[]) - Required - An array representing the keyboard buttons. * **options** (Partial>) - Optional - Configuration options for building the keyboard. ### Returns Markup ``` -------------------------------- ### removeKeyboard Source: https://telegraf.js.org/functions/Markup.removeKeyboard.html Removes the custom reply keyboard that was previously sent to the chat. Use this to send a message without a reply keyboard. For example, when you want to hide the keyboard for a certain reason. ```APIDOC ## removeKeyboard ### Description Removes the custom reply keyboard that was previously sent to the chat. Use this to send a message without a reply keyboard. For example, when you want to hide the keyboard for a certain reason. ### Method N/A (SDK function) ### Endpoint N/A (SDK function) ### Returns Markup ``` -------------------------------- ### pay(text, hide?) Source: https://telegraf.js.org/functions/Markup.button.pay.html Creates an inline keyboard button that initiates a payment flow. The button displays the provided text and can optionally be hidden. ```APIDOC ## pay(text, hide?) ### Description Creates an inline keyboard button that initiates a payment flow. The button displays the provided text and can optionally be hidden. ### Method N/A (SDK function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response Returns an `InlineKeyboardButton.PayButton` object. #### Response Example N/A ### Parameters * **text** (string) - The text to display on the button. * **hide** (boolean) - Optional. If true, the button will be hidden. Defaults to false. ``` -------------------------------- ### Static Methods Source: https://telegraf.js.org/classes/Scenes.WizardScene.html This section details the static methods available on the WizardScene class, which are utility functions for creating specific middleware. ```APIDOC ## `Static` acl * acl(userId, ...fns): MiddlewareFn * Generates middleware responding only to specified users. #### Type Parameters * #### C extends Context #### Parameters * ##### userId: MaybeArray * ##### `Rest` ...fns: NonemptyReadonlyArray> `Rest` #### Returns MiddlewareFn ## `Static` action * action(triggers, ...fns): MiddlewareFn * Generates middleware for handling matching callback queries. #### Type Parameters * #### C extends Context #### Parameters * ##### triggers: Triggers>> * ##### `Rest` ...fns: MatchedMiddleware `Rest` #### Returns MiddlewareFn ## `Static` admin * admin(...fns): MiddlewareFn * Generates middleware responding only to chat admins and chat creator. #### Type Parameters * #### C extends Context ``` -------------------------------- ### Create Webhook with Existing HTTP Server Source: https://telegraf.js.org/index.html Attaches Telegraf to an existing Node.js HTTP server using `createWebhook`. This is useful when you need more control over the server setup or are integrating with an existing application. It supports both HTTP and HTTPS servers. ```javascript import { createServer } from "http"; createServer(await bot.createWebhook({ domain: "example.com" })).listen(3000); ``` ```javascript import { createServer } from "https"; createServer(tlsOptions, await bot.createWebhook({ domain: "example.com" })).listen(8443); ``` -------------------------------- ### enter Source: https://telegraf.js.org/classes/Scenes.BaseScene.html Registers middleware to be executed when entering the scene. It accepts a list of middleware functions. ```APIDOC ## enter ### Description Registers middleware to be executed when entering the scene. It accepts a list of middleware functions. ### Method `enter(...fns)` ### Parameters * **`Rest` ...fns**: Middleware[] ### Returns BaseScene ``` -------------------------------- ### Stage Constructor Source: https://telegraf.js.org/classes/Scenes.Stage.html Initializes a new Stage instance. It can optionally take an array of scenes and configuration options. ```APIDOC ## constructor * `new Stage(scenes?, options?): Stage` * #### Type Parameters * #### C extends SessionContext> & { scene: SceneContextScene; } * #### D extends SceneSessionData = SceneSessionData #### Parameters * ##### scenes: readonly BaseScene[] = [] * ##### `Optional` options: Partial> `Optional` #### Returns Stage ``` -------------------------------- ### LaunchOptions Interface Source: https://telegraf.js.org/interfaces/Telegraf.LaunchOptions.html Defines the configuration options for launching a Telegraf bot, including settings for update types, pending updates, and webhook behavior. ```APIDOC ## Interface LaunchOptions ### Properties * **allowedUpdates?** (UpdateType[]) - Optional - List the types of updates you want your bot to receive. * **dropPendingUpdates?** (boolean) - Optional - If true, pending updates will be dropped. * **webhook?** (object) - Optional - Configuration options for when the bot is run via webhooks. * **cb?** (RequestListener) - Optional - Callback for handling incoming requests. * **certificate?** (InputFile) - Optional - Public key certificate for webhook verification. See self-signed guide for details. * **domain** (string) - Required - Public domain for the webhook. * **hookPath?** (string) - Optional - Webhook URL path. Will be automatically generated if not specified. Deprecated: Pass `path` instead. * **host?** (string) - Optional - Host for webhook requests. * **ipAddress?** (string) - Optional - The fixed IP address to use for sending webhook requests instead of the IP address resolved through DNS. * **maxConnections?** (number) - Optional - Maximum allowed simultaneous HTTPS connections to the webhook for update delivery (1-100). Defaults to 40. * **path?** (string) - Optional - Webhook URL path. Will be automatically generated if not specified. * **port?** (number) - Optional - Port for webhook requests. * **secretToken?** (string) - Optional - A secret token to be sent in the `X-Telegram-Bot-Api-Secret-Token` header for webhook requests. 1-256 characters. Only `A-Z`, `a-z`, `0-9`, `_`, and `-` are allowed. * **tlsOptions?** (TlsOptions) - Optional - TLS server options. Omit to use http. ``` -------------------------------- ### action Source: https://telegraf.js.org/classes/Telegraf-1.html Registers middleware for handling matching callback queries. ```APIDOC ## action ### Description Registers middleware for handling matching callback queries. ### Method POST ### Endpoint /action ### Parameters #### Request Body - **triggers** (Triggers) - Required - The triggers for the callback query. - **...fns** (MatcheMiddleware) - Required - The middleware functions to handle the callback query. ### Returns Telegraf ``` -------------------------------- ### Composer.action Source: https://telegraf.js.org/classes/Composer.html Generates middleware for handling matching callback queries. ```APIDOC ## Composer.action ### Description Generates middleware for handling matching callback queries. ### Method `action(triggers, ...fns)` ### Type Parameters * **C** extends Context ### Parameters * **triggers** (Triggers>>) - The callback query data to match. * **...fns** (MatchedMiddleware) - The middleware functions to apply. ### Returns MiddlewareFn ``` -------------------------------- ### Markup.resize Source: https://telegraf.js.org/classes/Types.Markup.html Configures the keyboard to resize dynamically based on the content. This method is applicable to ReplyKeyboardMarkup. ```APIDOC ## resize(value?: boolean): Markup ### Description Sets the resize keyboard option for the reply markup. ### Parameters * **value**: boolean = true - If true, the keyboard will resize. ### Returns Makes Markup ``` -------------------------------- ### WizardContextWizard.step Source: https://telegraf.js.org/classes/Scenes.WizardContextWizard.html Retrieves the middleware function for the current step. ```APIDOC ## step ### Description Gets the middleware function for the current step. ### Accessors * **get step(): undefined | Middleware** - Returns the middleware function for the current step, or undefined if no step is set. ``` -------------------------------- ### WizardScene Methods Source: https://telegraf.js.org/classes/Scenes.WizardScene.html This section details the various methods available on the WizardScene class for filtering and handling different types of updates and commands. ```APIDOC ## phone * phone(number, ...fns): WizardScene * #### Parameters * ##### number: Triggers * ##### `Rest` ...fns: MatchedMiddleware `Rest` #### Returns WizardScene ## reaction * reaction(reaction, ...fns): WizardScene * #### Parameters * ##### reaction: MaybeArray * ##### `Rest` ...fns: NonemptyReadonlyArray & Omit> & { match: ReactionAddedOrRemoved; }, MessageReactionUpdate>> `Rest` #### Returns WizardScene ## settings * settings(...fns): WizardScene * Registers a middleware for handling /settings #### Parameters * ##### `Rest` ...fns: NonemptyReadonlyArray & Omit> & CommandContextExtn>> `Rest` #### Returns WizardScene ## spoiler * spoiler(text, ...fns): WizardScene * #### Parameters * ##### text: Triggers * ##### `Rest` ...fns: MatchedMiddleware `Rest` #### Returns WizardScene ## start * start(...fns): WizardScene * Registers a middleware for handling /start #### Parameters * ##### `Rest` ...fns: NonemptyReadonlyArray & Omit> & StartContextExtn>> `Rest` #### Returns WizardScene ## textLink * textLink(link, ...fns): WizardScene * #### Parameters * ##### link: Triggers * ##### `Rest` ...fns: MatchedMiddleware `Rest` #### Returns WizardScene ## textMention * textMention(mention, ...fns): WizardScene * #### Parameters * ##### mention: Triggers * ##### `Rest` ...fns: MatchedMiddleware `Rest` #### Returns WizardScene ## url * url(url, ...fns): WizardScene * #### Parameters * ##### url: Triggers * ##### `Rest` ...fns: MatchedMiddleware `Rest` #### Returns WizardScene ## use * use(...fns): WizardScene * Registers a middleware. #### Parameters * ##### `Rest` ...fns: readonly Middleware[] `Rest` #### Returns WizardScene ``` -------------------------------- ### Static Methods Source: https://telegraf.js.org/classes/Scenes.BaseScene.html This section details static methods available on the BaseScene class, which are utility functions for creating specific types of middleware. ```APIDOC ## `Static` acl ### Description Generates middleware responding only to specified users. ### Type Parameters * **C extends Context ### Parameters * **userId**: MaybeArray * **`Rest` ...fns**: NonemptyReadonlyArray> ### Returns MiddlewareFn ``` ```APIDOC ## `Static` action ### Description Generates middleware for handling matching callback queries. ### Type Parameters * **C extends Context ### Parameters * **triggers**: Triggers>> * **`Rest` ...fns**: MatchedMiddleware ### Returns MiddlewareFn ``` ```APIDOC ## `Static` admin ### Description Generates middleware responding only to chat admins and chat creator. ### Type Parameters * **C extends Context ### Parameters * **`Rest` ...fns**: NonemptyReadonlyArray> ``` -------------------------------- ### FmtString Constructor Source: https://telegraf.js.org/classes/Format.FmtString.html Initializes a new instance of the FmtString class. ```APIDOC ## new FmtString(text, entities?) ### Description Initializes a new instance of the FmtString class. ### Parameters #### Parameters - **text**: string - The text content. - **entities**: MessageEntity[] - Optional. An array of message entities. #### Returns FmtString - The new FmtString instance. ``` -------------------------------- ### Composer.settings Source: https://telegraf.js.org/classes/Composer.html Registers middleware for handling the /settings command. ```APIDOC ## Composer.settings ### Description Registers a middleware for handling the /settings command. ### Method `settings(...fns)` ### Parameters * **...fns** (NonemptyReadonlyArray & Omit> & CommandContextExtn>>) - The middleware functions to apply. ### Returns Composer ``` -------------------------------- ### getMyShortDescription Source: https://telegraf.js.org/classes/Telegram.html Retrieves the current bot short description for a specified user language. ```APIDOC ## getMyShortDescription ### Description Use this method to get the current bot short description for the given user language. ### Method GET (assumed, based on typical API patterns for retrieval) ### Endpoint /getMyShortDescription ### Parameters #### Query Parameters - **language_code** (string) - Optional - A two-letter ISO 639-1 language code or an empty string. ### Returns Promise ``` -------------------------------- ### WizardContextWizard.selectStep Source: https://telegraf.js.org/classes/Scenes.WizardContextWizard.html Navigates the wizard to a specific step by its index. ```APIDOC ## selectStep(index) ### Description Navigates the wizard to a specific step by its index. ### Parameters * **index** (number) - The index of the step to select. ### Returns WizardContextWizard ``` -------------------------------- ### Command Arguments Parsing Source: https://telegraf.js.org/interfaces/Types.CommandContextExtn.html Demonstrates how the 'args' property parses command-line arguments, handling quoted strings correctly. ```plaintext /command token1 token2 -> [ "token1", "token2" ] /command "token1 token2" -> [ "token1 token2" ] /command token1 "token2 token3" -> [ "token1" "token2 token3" ] ``` -------------------------------- ### settings Source: https://telegraf.js.org/classes/Telegraf-1.html Registers a middleware for handling the /settings command. It accepts a rest parameter for middleware functions. ```APIDOC ## settings ### Description Registers a middleware for handling the /settings command. ### Method `settings(...fns)` ### Parameters * `...fns`: `NonemptyReadonlyArray & Omit> & CommandContextExtn>>` ### Returns Telegraf ``` -------------------------------- ### action Source: https://telegraf.js.org/classes/Telegraf-1.html Generates middleware for handling matching callback queries. This method is specifically designed to process button presses within inline keyboards. ```APIDOC ## action ### Description Generates middleware for handling matching callback queries. ### Type Parameters * `C` extends `Context` ### Method action ### Parameters * `triggers` (Triggers>>) - The callback query data to match. * `...fns` (MatchedMiddleware) - The middleware functions to execute when a matching callback query is received. ### Returns MiddlewareFn ``` -------------------------------- ### Markup Class Constructor Source: https://telegraf.js.org/classes/Types.Markup.html Initializes a new instance of the Markup class. It accepts a reply markup object which can be of type InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, or ForceReply. ```APIDOC ## new Markup(reply_markup: T) ### Description Initializes a new instance of the Markup class. ### Parameters * **reply_markup**: T - The reply markup object to be used. ### Returns Makes Markup ```