### Install the library Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/README.md Use npm to install the package in your project. ```bash npm install typescript-telegram-bot-api ``` -------------------------------- ### Install Proxy Agents Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Install necessary packages to support HTTP/HTTPS or SOCKS proxies. ```bash npm install https-proxy-agent socks-proxy-agent ``` -------------------------------- ### CallbackQuery Usage Example Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/types.md Demonstrates handling a callback query event and responding to it. ```typescript bot.on('callback_query', async (query) => { if (query.data === 'btn1') { await bot.answerCallbackQuery({ callback_query_id: query.id, text: 'Button 1 clicked!' }); } }); ``` -------------------------------- ### Define .env file Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Example configuration file for storing sensitive bot credentials and environment settings. ```text BOT_TOKEN=123456:ABCdefGHIjklmNOPqrsTUVwxyz-1234567 NODE_ENV=development PROXY_URL=http://proxy.example.com:8080 ``` -------------------------------- ### startPolling Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Starts the long polling process for receiving updates. ```APIDOC ## startPolling ### Description Starts long polling. ### Method async startPolling(): Promise ``` -------------------------------- ### Initialize and start a long-polling bot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/overview.md Instantiate the TelegramBot class and start polling for updates. Ensure the bot token is valid before starting. ```typescript const bot = new TelegramBot({ botToken: 'TOKEN' }); bot.on('message', (msg) => { /* handle */ }); await bot.startPolling(); ``` -------------------------------- ### Send photo with FileOptions Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/utility-classes-and-patterns.md Examples demonstrating how to send files using buffers, streams, or browser File objects. ```typescript import { readFile } from 'fs/promises'; import { FileOptions } from 'typescript-telegram-bot-api'; const photoBuffer = await readFile('photo.jpg'); await bot.sendPhoto({ chat_id: 123, photo: new FileOptions(photoBuffer, { filename: 'my_photo.jpg', contentType: 'image/jpeg' }) }); ``` ```typescript const photoBuffer = await readFile('photo.jpg'); await bot.sendPhoto({ chat_id: 123, photo: new FileOptions(photoBuffer, 'my_photo.jpg') }); ``` ```typescript import { createReadStream } from 'fs'; import { FileOptions } from 'typescript-telegram-bot-api'; const stream = createReadStream('video.mp4'); await bot.sendVideo({ chat_id: 123, video: new FileOptions(stream, { filename: 'my_video.mp4', contentType: 'video/mp4' }) }); ``` ```typescript const input = document.getElementById('file-input') as HTMLInputElement; const file = input.files?.[0]; if (file) { await bot.sendPhoto({ chat_id: 123, photo: new FileOptions(file, { filename: file.name, contentType: file.type }) }); } ``` -------------------------------- ### sendMessage Usage Example Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Demonstrates sending a formatted text message with an inline keyboard. ```typescript const msg = await bot.sendMessage({ chat_id: 123456, text: '*Bold* _italic_', parse_mode: 'Markdown', reply_markup: { inline_keyboard: [[ { text: 'Click me', callback_data: 'clicked' } ]] } }); ``` -------------------------------- ### Get File Information Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves file metadata and provides the path for download URL construction. ```typescript async getFile(options: { file_id: string; }): Promise ``` ```typescript const url = `https://api.telegram.org/file/bot${botToken}/${file.file_path}`; ``` -------------------------------- ### Get Webhook Info Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves the current status and configuration of the webhook. ```typescript async getWebhookInfo(): Promise ``` -------------------------------- ### Get User Profile Audios Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves a list of profile audios for a specific user. ```typescript async getUserProfileAudios(options: { user_id: number; offset?: number; limit?: number; }): Promise ``` -------------------------------- ### Identify File I/O Errors Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/errors.md Examples of common file system error messages encountered during file operations. ```typescript // Error: ENOENT: no such file or directory // Error: EACCES: permission denied ``` -------------------------------- ### Configure Auto-Retry Strategies Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/errors.md Examples of configuring the TelegramBot constructor for different retry behaviors, including disabling retries or setting specific delay limits. ```typescript const bot = new TelegramBot({ botToken: 'TOKEN', autoRetry: false }); // Always throws on rate limit try { await bot.sendMessage({ chat_id: 123, text: 'hello' }); } catch (error) { // Handle manually } ``` ```typescript const bot = new TelegramBot({ botToken: 'TOKEN', autoRetry: true, autoRetryLimit: 5 // Only retry if retry_after <= 5 seconds }); ``` ```typescript const bot = new TelegramBot({ botToken: 'TOKEN', autoRetry: true, autoRetryLimit: 300 // Retry any delay up to 5 minutes }); ``` -------------------------------- ### Get User Profile Photos Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves a list of profile photos for a specific user. ```typescript async getUserProfilePhotos(options: { user_id: number; offset?: number; limit?: number; }): Promise ``` -------------------------------- ### Implement Polling via TelegramBot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/utility-classes-and-patterns.md Standard usage pattern for starting, listening to events, and stopping the polling loop. ```typescript const bot = new TelegramBot({ botToken: 'TOKEN' }); // Start polling (uses Polling internally) await bot.startPolling(); // Listen for events bot.on('message', (msg) => console.log('Message:', msg.text)); // Stop polling await bot.stopPolling(); ``` -------------------------------- ### Get chat information Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Use this method to retrieve full information about a chat. ```typescript const chat = await bot.getChat({ chat_id: 123 }); console.log('Chat title:', chat.title); console.log('Members:', chat.members_count); ``` -------------------------------- ### Identify Proxy Errors Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/errors.md Examples of common proxy-related error messages indicating authentication or connection failures. ```typescript // Error: 407 Proxy Authentication Required // Error: connect ECONNREFUSED (proxy not running) ``` -------------------------------- ### Environment Variables for Testing Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/tests/README.md Create a .env file in the root directory and populate it with these variables for testing purposes. ```bash TEST_TELEGRAM_TOKEN=your_bot_token TEST_USER_ID=your_user_id TEST_GROUP_ID=your_group_id TEST_GROUP_MEMBER_ID=your_group_member_id TEST_CHANNEL_ID=your_channel_id ``` -------------------------------- ### Get Updates Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Fetches incoming updates using long polling. ```typescript async getUpdates(options?: { offset?: number; limit?: number; timeout?: number; allowed_updates?: UpdateType[]; }, abortController?: AbortController): Promise ``` -------------------------------- ### Initialize Minimal Development Bot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Uses default settings for quick local testing. ```typescript const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN! }); ``` -------------------------------- ### Initialize and use the Telegram bot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/README.md Import the TelegramBot class, initialize it with a token, and set up event listeners for incoming messages. ```typescript import { TelegramBot } from 'typescript-telegram-bot-api'; const bot = new TelegramBot({ botToken: 'YOUR_BOT_TOKEN' }); bot.startPolling(); bot.on('message', (message) => { console.log('Received message:', message.text); }); bot.on('message:sticker', (message) => { console.log('Received sticker:', message.sticker.emoji); }); bot.getMe() .then(console.log) .catch(console.error); ``` -------------------------------- ### Initialize Standard Production Bot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Balanced configuration for typical bot use cases. ```typescript const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN!, autoRetry: true, autoRetryLimit: 30, pollingTimeout: 50, allowedUpdates: ['message', 'callback_query'] }); ``` -------------------------------- ### Start Long Polling Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Initiates the long polling process to receive updates from Telegram. ```typescript async startPolling(): Promise ``` -------------------------------- ### new TelegramBot(options) Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Initializes a new TelegramBot instance with the provided configuration options. ```APIDOC ## new TelegramBot(options) ### Description Initializes the Telegram bot client. The `options` object defines the connection parameters, retry logic, and polling behavior. ### Parameters - **botToken** (string) - Required - Bot API token from @BotFather. - **testEnvironment** (boolean) - Optional - Use Telegram test servers (default: false). - **baseURL** (string) - Optional - Custom API endpoint URL (default: https://api.telegram.org). - **autoRetry** (boolean) - Optional - Automatically retry requests on 429 errors (default: true). - **autoRetryLimit** (number) - Optional - Max retry_after seconds to allow for auto-retry (default: 0). - **allowedUpdates** (UpdateType[]) - Optional - Filter update types for polling (default: []). - **pollingTimeout** (number) - Optional - Long-polling timeout in seconds (default: 50). - **agent** (object) - Optional - Node.js HTTP/HTTPS agent for proxies. ### Usage Example ```typescript const bot = new TelegramBot({ botToken: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", pollingTimeout: 60 }); ``` ``` -------------------------------- ### Running Tests and Linting Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/tests/README.md Execute these npm commands to run tests, linting, and format checks. ```bash npm test ``` ```bash npm run lint ``` ```bash npm run format:check ``` -------------------------------- ### Initialize bot with environment variables Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Use dotenv to load environment variables for secure token management. ```typescript import 'dotenv/config'; const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN || process.env.TELEGRAM_BOT_TOKEN, testEnvironment: process.env.NODE_ENV === 'test' }); ``` -------------------------------- ### Initialize TelegramBot Client Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/overview.md Configure the main bot instance with authentication, polling settings, and optional proxy support. ```typescript const bot = new TelegramBot({ botToken: 'YOUR_TOKEN', autoRetry: true, // Auto-retry on rate limit pollingTimeout: 50, // Long-polling timeout allowedUpdates: [...], // Filter update types baseURL: 'https://api.telegram.org', agent: proxyAgent // Optional proxy support }); ``` -------------------------------- ### Identify Network Errors Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/errors.md Examples of common network-related error messages encountered when the API is unreachable. ```typescript // Network connection failed // Error: connect ECONNREFUSED // Error: getaddrinfo ENOTFOUND api.telegram.org ``` -------------------------------- ### Access bot configuration properties Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Demonstrates that constructor options are accessible as readable and writable properties on the bot instance. ```typescript const bot = new TelegramBot({ botToken: 'TOKEN', pollingTimeout: 30 }); // All are readable (and writable) console.log(bot.botToken); // 'TOKEN' console.log(bot.testEnvironment); // false console.log(bot.baseURL); // 'https://api.telegram.org' console.log(bot.autoRetry); // true console.log(bot.autoRetryLimit); // 0 console.log(bot.allowedUpdates); // [] console.log(bot.pollingTimeout); // 30 console.log(bot.agent); // undefined ``` -------------------------------- ### TelegramBot Constructor Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/overview.md The main entry point for the library is the TelegramBot class, which requires a bot token and accepts various configuration options for environment and behavior customization. ```APIDOC ## TelegramBot Constructor ### Description Initializes the main API client for interacting with the Telegram Bot API. ### Constructor Options - **botToken** (string) - Required - Bot token obtained from @BotFather. - **testEnvironment** (boolean) - Optional - Whether to use the test API server. - **baseURL** (string) - Optional - Custom API URL. - **autoRetry** (boolean) - Optional - Enable auto-retry on rate limits (default: true). - **autoRetryLimit** (number) - Optional - Retry threshold for retry_after values (default: 0). - **allowedUpdates** (UpdateType[]) - Optional - Filter specific update types. - **pollingTimeout** (number) - Optional - Long-polling timeout in seconds (default: 50). - **agent** (object) - Optional - HTTP/HTTPS agent for proxy support. ``` -------------------------------- ### Define and use FileOptions Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/types.md Wraps a file with metadata for sending. Use when custom filenames or content types are required. ```typescript class FileOptions { constructor( public file: ReadStream | Buffer | File, public options?: FormData.AppendOptions | string ); } ``` ```typescript const buffer = await readFile('photo.jpg'); await bot.sendPhoto({ chat_id: 123, photo: new FileOptions(buffer, { filename: 'custom_name.jpg', contentType: 'image/jpeg' }) }); ``` -------------------------------- ### Initialize Bot with Proxy Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Routes traffic through a corporate proxy or VPN using HttpsProxyAgent. ```typescript import { HttpsProxyAgent } from 'https-proxy-agent'; const agent = new HttpsProxyAgent(process.env.PROXY_URL!); const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN!, agent: agent, autoRetry: true }); ``` -------------------------------- ### setMyShortDescription Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sets the bot's short description. ```APIDOC ## setMyShortDescription ### Description Sets the bot's short description. ### Signature `async setMyShortDescription(options?: { short_description?: string; language_code?: string; }): Promise` ``` -------------------------------- ### Initialize TelegramBot instance Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Basic instantiation of the TelegramBot class using an options object. ```typescript const bot = new TelegramBot(options); ``` -------------------------------- ### getMyShortDescription Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves the bot's short description. ```APIDOC ## getMyShortDescription ### Description Retrieves the bot's short description. ### Signature `async getMyShortDescription(options?: { language_code?: string; }): Promise` ``` -------------------------------- ### Run Tests Locally and via Docker Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/README.md Execute the test suite using npm or build and run the project within a Docker container. ```bash npm test ``` ```bash docker build -t typescript-bot-api . docker run --rm --env-file .env typescript-bot-api run test ``` -------------------------------- ### on() Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Registers an event listener for incoming updates. ```APIDOC ## on() ### Description Listen for updates. Supports any UpdateType (message, callback_query, etc.) and Message sub-types (message:photo, message:audio, etc.). ### Signature `on(event: EventType, listener: (...args) => void): this` ### Example ```typescript bot.on('message', (msg: Message) => { console.log('Message:', msg.text); }); ``` ``` -------------------------------- ### Initialize Testing/Debug Bot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Configures a safe environment with quick response times for testing. ```typescript const bot = new TelegramBot({ botToken: process.env.TEST_BOT_TOKEN!, testEnvironment: true, pollingTimeout: 5, allowedUpdates: ['message', 'callback_query'] }); ``` -------------------------------- ### getMe Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves information about the bot. ```APIDOC ## getMe ### Description Get bot info. ### Method async getMe(): Promise ``` -------------------------------- ### Send photos using various input types Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/README.md Demonstrates sending photos using file IDs, URLs, streams, buffers, the FileOptions wrapper, and browser file inputs. ```typescript import { TelegramBot, FileOptions } from 'typescript-telegram-bot-api'; import { createReadStream } from 'fs'; import { readFile } from 'fs/promises'; await bot.sendPhoto({ chat_id: chat_id, photo: 'AgACAgIAAxkDAAIF62Zq43...AgADcwADNQQ', caption: 'file_id', }); // or await bot.sendPhoto({ chat_id: chat_id, photo: 'https://unsplash.it/640/480', caption: 'url', }); // or await bot.sendPhoto({ chat_id: chat_id, photo: createReadStream('photo.jpg'), caption: 'stream', }); // or await bot.sendPhoto({ chat_id: chat_id, photo: await readFile('photo.jpg'), caption: 'buffer', }); // or await bot.sendPhoto({ chat_id: chat_id, photo: new FileOptions( await readFile('photo.jpg'), { filename: 'custom_file_name.jpg', contentType: 'image/jpeg', } ), caption: 'FileOptions', }); // or in browser await bot.sendPhoto({ chat_id: chat_id, photo: input.files[0], // or new File(…) caption: 'file', }); ``` -------------------------------- ### setMyDescription Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sets the bot's description. ```APIDOC ## setMyDescription ### Description Sets the bot's description. ### Signature `async setMyDescription(options?: { description?: string; language_code?: string; }): Promise` ``` -------------------------------- ### setMyCommands Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sets the list of commands for the bot. ```APIDOC ## setMyCommands ### Description Sets the list of commands for the bot. ### Signature `async setMyCommands(options: { commands: BotCommand[]; scope?: BotCommandScope; language_code?: string; }): Promise` ``` -------------------------------- ### FileOptions Constructor Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/utility-classes-and-patterns.md The FileOptions class is used to wrap file data for transmission. It accepts the file content and optional metadata. ```APIDOC ## constructor(file: ReadStream | Buffer | File, options?: FormData.AppendOptions | string) ### Description Creates a new instance of FileOptions to be used in bot methods that require file uploads. ### Parameters - **file** (ReadStream | Buffer | File) - Required - The file content to be sent. - **options** (FormData.AppendOptions | string) - Optional - Metadata for the file, either as a string (filename) or an object containing filename and contentType. ### Usage Example ```typescript import { FileOptions } from 'typescript-telegram-bot-api'; const photo = new FileOptions(buffer, { filename: 'image.jpg', contentType: 'image/jpeg' }); ``` ``` -------------------------------- ### getMyDescription Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves the bot's description. ```APIDOC ## getMyDescription ### Description Retrieves the bot's description. ### Signature `async getMyDescription(options?: { language_code?: string; }): Promise` ``` -------------------------------- ### Import Telegram API Types Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/types.md Demonstrates importing core Telegram API types directly from the main package index. ```typescript import { Message, User, Chat, Update, InlineQuery, CallbackQuery, Poll, Invoice, /* ... 300+ types */ } from 'typescript-telegram-bot-api'; ``` -------------------------------- ### Configure botToken Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Set the bot API token directly or via environment variables for security. ```typescript const bot = new TelegramBot({ botToken: '123456789:ABCdefGHIjklmNOPqrsTUVwxyz-1234567' }); ``` ```typescript const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN! }); ``` -------------------------------- ### Create Forum Topic Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Creates a new forum topic in a supergroup chat. ```typescript async createForumTopic(options: { chat_id: number | string; name: string; icon_color?: number; icon_custom_emoji_id?: string; }): Promise ``` -------------------------------- ### Initialize High-Traffic Bot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Optimized to minimize requests and bandwidth consumption. ```typescript const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN!, autoRetry: true, autoRetryLimit: 300, pollingTimeout: 60, allowedUpdates: ['message'] // Only messages }); ``` -------------------------------- ### getFile Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves file information and the download URL. ```APIDOC ## getFile ### Description Get file info and download URL. ### Method async getFile(options: { file_id: string; }): Promise ``` -------------------------------- ### Initialize TelegramBot Constructor Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Defines the structure and parameters for the TelegramBot class constructor. ```typescript constructor(options: { botToken: string; testEnvironment?: boolean; baseURL?: string; autoRetry?: boolean; autoRetryLimit?: number; allowedUpdates?: UpdateType[]; pollingTimeout?: number; agent?: { destroy(): void }; }) ``` -------------------------------- ### getMyCommands Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves the current list of bot commands. ```APIDOC ## getMyCommands ### Description Retrieves the current list of bot commands. ### Signature `async getMyCommands(options?: { scope?: BotCommandScope; language_code?: string; }): Promise` ``` -------------------------------- ### Create a new sticker set Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Creates a new sticker set for a user. Requires user ID, set name, title, and an array of stickers. ```typescript async createNewStickerSet(options: { user_id: number; name: string; title: string; sticker_type?: 'regular' | 'mask' | 'custom_emoji'; needs_repainting?: boolean; stickers: InputSticker[]; }): Promise ``` -------------------------------- ### Define FileOptions class Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/utility-classes-and-patterns.md Constructor for wrapping file data with optional FormData metadata. ```typescript export class FileOptions { constructor( public file: ReadStream | Buffer | File, public options?: FormData.AppendOptions | string ); } ``` -------------------------------- ### Set Bot Commands Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Configures the list of commands available for the bot. ```typescript await bot.setMyCommands({ commands: [ { command: 'start', description: 'Start the bot' }, { command: 'help', description: 'Get help' } ] }); ``` -------------------------------- ### answerCallbackQuery Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Responds to a button click callback query. ```APIDOC ## answerCallbackQuery ### Description Respond to button click. ### Method async answerCallbackQuery(options: { callback_query_id: string; text?: string; show_alert?: boolean; url?: string; cache_time?: number; }): Promise ``` -------------------------------- ### sendAudio Method Definition Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Defines the signature for sending audio files up to 50MB. ```typescript async sendAudio(options: { chat_id: number | string; audio: InputFile | string; caption?: string; parse_mode?: ParseMode; duration?: number; performer?: string; title?: string; thumbnail?: InputFile | string; disable_notification?: boolean; protect_content?: boolean; reply_parameters?: ReplyParameters; reply_markup?: keyboard; }): Promise ``` -------------------------------- ### Configure Proxy Agent Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Use an HTTP/HTTPS or SOCKS agent for proxy support in Node.js environments. ```typescript import { HttpsProxyAgent } from 'https-proxy-agent'; const agent = new HttpsProxyAgent('http://user:password@proxy.example.com:8080'); const bot = new TelegramBot({ botToken: 'TOKEN', agent: agent }); ``` ```typescript import { SocksProxyAgent } from 'socks-proxy-agent'; const agent = new SocksProxyAgent('socks5://user:password@proxy.example.com:1080'); const bot = new TelegramBot({ botToken: 'TOKEN', agent: agent }); ``` ```typescript import { HttpsProxyAgent } from 'https-proxy-agent'; const agent = new HttpsProxyAgent('http://proxy.example.com:8080'); const bot = new TelegramBot({ botToken: 'TOKEN', agent: agent }); ``` -------------------------------- ### Define ReplyKeyboardMarkup Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/types.md Defines a custom keyboard layout for user interaction. ```typescript type ReplyKeyboardMarkup = { keyboard: KeyboardButton[][]; // 2D array of buttons is_persistent?: boolean; // Show when minimized resize_keyboard?: boolean; // Resize to fit one_time_keyboard?: boolean; // Hide after use input_field_placeholder?: string; // Placeholder text selective?: boolean; // Show to specific users }; ``` -------------------------------- ### Handle 404 Not Found Error Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/errors.md Demonstrates catching a 404 error when attempting to interact with a non-existent resource. ```typescript try { await bot.deleteMessage({ chat_id: 123, message_id: 999 // Does not exist }); } catch (error) { if (TelegramBot.isTelegramError(error)) { // error_code: 404 // description: 'Not Found: message to delete not found' } } ``` -------------------------------- ### createNewStickerSet Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Creates a new sticker set. ```APIDOC ## createNewStickerSet ### Description Creates a new sticker set for a user. ### Method async createNewStickerSet(options: { user_id: number; name: string; title: string; sticker_type?: 'regular' | 'mask' | 'custom_emoji'; needs_repainting?: boolean; stickers: InputSticker[]; }): Promise ``` -------------------------------- ### createForumTopic Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Creates a new forum topic in a specified chat. ```APIDOC ## createForumTopic ### Description Creates a new forum topic. ### Method async createForumTopic(options: { chat_id: number | string; name: string; icon_color?: number; icon_custom_emoji_id?: string; }): Promise ``` -------------------------------- ### getFile() Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Retrieves file information for downloading. ```APIDOC ## getFile() ### Description Get file info and prepare for download. ### Signature `getFile(options: { file_id: string }): Promise` ### Parameters - **options** (object) - Required - Object containing the file_id. ### Example ```typescript const file = await bot.getFile({ file_id: 'AgADBAAD...' }); ``` ``` -------------------------------- ### setWebhook Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Registers a webhook for receiving updates. ```APIDOC ## setWebhook ### Description Register webhook for updates. ### Method async setWebhook(options: { url: string; certificate?: InputFile; ip_address?: string; max_connections?: number; allowed_updates?: UpdateType[]; drop_pending_updates?: boolean; secret_token?: string; }): Promise ``` -------------------------------- ### Define TelegramBot configuration options Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/overview.md Use this interface to configure the TelegramBot instance, including authentication, polling behavior, and proxy settings. ```typescript interface TelegramBotOptions { botToken: string; // Required: Bot token from @BotFather testEnvironment?: boolean; // Optional: Use test API server baseURL?: string; // Optional: Custom API URL autoRetry?: boolean; // Optional: Auto-retry on rate limit (default: true) autoRetryLimit?: number; // Optional: Retry if retry_after < limit (default: 0) allowedUpdates?: UpdateType[]; // Optional: Filter update types pollingTimeout?: number; // Optional: Long-polling timeout in seconds (default: 50) agent?: { destroy(): void }; // Optional: HTTP/HTTPS agent for proxies } ``` -------------------------------- ### Enable auto-retry Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Configure auto-retry settings for production environments to improve reliability. ```typescript const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN!, autoRetry: true, autoRetryLimit: 30 }); ``` -------------------------------- ### Common Parameters Reference Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/INDEX.md Defines standard parameters used across multiple API methods. ```text chat_id: number | string - Required for most methods user_id: number - User identifier message_id: number - Message identifier reply_markup: keyboard types - Optional button layout ``` -------------------------------- ### Implement Telegram Bot Webhook with Express Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/README.md Uses Express to handle incoming POST requests and ngrok to expose the local server to Telegram. Requires a valid Telegram bot token in the environment variables. ```typescript import 'dotenv/config'; import * as ngrok from 'ngrok'; import express from "express"; import {TelegramBot} from "./src"; import {Update} from "./src/types"; const port = 3001; const bot = new TelegramBot({ botToken: process.env.TEST_TELEGRAM_TOKEN as string, }); bot.on('message', async (message) => { await bot.setMessageReaction({ chat_id: message.chat.id, message_id: message.message_id, reaction: [{ type: 'emoji', emoji: '👍' }] }); }); const app = express(); app.use(express.json()); app.post('/', async (req, res) => { try { await bot.processUpdate(req.body as Update); res.sendStatus(200); } catch (e) { res.sendStatus(500); } }); (async () => { app.listen(port, async () => { const url = await ngrok.connect({ proto: 'http', addr: port, }); await bot.setWebhook({url}); console.log('Set Webhook to', url); }) })(); process.on('SIGINT', async () => { await bot.deleteWebhook(); await ngrok.disconnect(); console.log('Webhook deleted'); }); ``` -------------------------------- ### sendVideo Method Definition Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Defines the signature for sending video files up to 50MB. ```typescript async sendVideo(options: { chat_id: number | string; video: InputFile | string; duration?: number; width?: number; height?: number; thumbnail?: InputFile | string; caption?: string; parse_mode?: ParseMode; supports_streaming?: boolean; has_spoiler?: boolean; disable_notification?: boolean; protect_content?: boolean; reply_parameters?: ReplyParameters; reply_markup?: keyboard; }): Promise ``` -------------------------------- ### Create a Custom Request Queue Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/utility-classes-and-patterns.md Manage API rate limits by wrapping bot methods in a queue that processes tasks sequentially with a delay. ```typescript import { TelegramBot } from 'typescript-telegram-bot-api'; import { EventEmitter } from 'events'; class QueuedTelegramBot extends EventEmitter { private queue: Array<() => Promise> = []; private processing = false; constructor(private bot: TelegramBot) { super(); } private async processQueue() { if (this.processing || this.queue.length === 0) return; this.processing = true; while (this.queue.length > 0) { const task = this.queue.shift(); if (task) { try { await task(); } catch (error) { this.emit('error', error); } await new Promise(r => setTimeout(r, 100)); // Rate limit } } this.processing = false; } async sendMessage(options: any) { return new Promise((resolve, reject) => { this.queue.push(async () => { try { const result = await this.bot.sendMessage(options); resolve(result); } catch (error) { reject(error); } }); this.processQueue(); }); } } // Usage const queuedBot = new QueuedTelegramBot(bot); await queuedBot.sendMessage({ chat_id: 123, text: 'Message 1' }); await queuedBot.sendMessage({ chat_id: 123, text: 'Message 2' }); // Messages sent with 100ms rate limiting ``` -------------------------------- ### promoteChatMember Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Promotes a member to administrator status. ```APIDOC ## promoteChatMember ### Description Promote to admin. ### Method async promoteChatMember(options: { chat_id: number | string; user_id: number; can_change_info?: boolean; can_post_messages?: boolean; can_edit_messages?: boolean; can_delete_messages?: boolean; can_manage_video_chats?: boolean; can_restrict_members?: boolean; can_promote_members?: boolean; can_manage_chat?: boolean; can_invite_users?: boolean; is_member?: boolean; }): Promise ``` -------------------------------- ### getStarTransactions(options?) Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Retrieves the transaction history for Telegram Stars. ```APIDOC ## getStarTransactions(options?) ### Description Get star transaction history. ### Parameters - **options** (object) - Optional - Configuration object containing offset and limit. ### Example ```typescript const transactions = await bot.getStarTransactions({ offset: 0, limit: 10 }); ``` ``` -------------------------------- ### Respond to callback query Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Use this method to send a response to a callback query triggered by a button click. ```typescript await bot.answerCallbackQuery({ callback_query_id: 'query_id', text: 'Button clicked!', show_alert: false }); ``` -------------------------------- ### Define InlineKeyboardMarkup Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/types.md Represents an inline keyboard layout using a 2D array of buttons. ```typescript type InlineKeyboardMarkup = { inline_keyboard: InlineKeyboardButton[][]; // 2D array of buttons }; ``` -------------------------------- ### sendVideo Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends a video file to a specified chat. ```APIDOC ## sendVideo ### Description Sends a video file (MPEG4, up to 50MB). ### Parameters - **chat_id** (number | string) - Required - Target chat ID - **video** (InputFile | string) - Required - The video to send ``` -------------------------------- ### close Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Closes the current bot instance. ```APIDOC ## close ### Description Close bot instance. ### Method async close(): Promise ``` -------------------------------- ### answerInlineQuery(options) Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Responds to an inline query with a list of results. ```APIDOC ## answerInlineQuery(options) ### Description Respond to inline query with results. ### Parameters - **options** (object) - Required - The inline query options including inline_query_id and results. ### Returns - **Promise** - Returns true upon success. ``` -------------------------------- ### Handle Proxy Errors Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/errors.md Configure the bot with an HttpsProxyAgent and catch potential connection errors during initialization or requests. ```typescript import { HttpsProxyAgent } from 'https-proxy-agent'; try { const agent = new HttpsProxyAgent('http://user:pass@proxy:8080'); const bot = new TelegramBot({ botToken: 'TOKEN', agent }); await bot.getMe(); } catch (error) { console.error('Proxy connection failed:', error.message); } ``` -------------------------------- ### getUserProfileAudios Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves a user's profile audios. ```APIDOC ## getUserProfileAudios ### Description Get user's profile audios. ### Method async getUserProfileAudios(options: { user_id: number; offset?: number; limit?: number; }): Promise ``` -------------------------------- ### Define InputMedia types Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/types.md Base types for media objects used in albums. ```typescript type InputMedia = InputMediaPhoto | InputMediaVideo | InputMediaAudio | InputMediaDocument | InputMediaAnimation; type InputMediaPhoto = { type: 'photo'; media: string | InputFile; caption?: string; parse_mode?: ParseMode; caption_entities?: MessageEntity[]; show_caption_above_media?: boolean; has_spoiler?: boolean; }; type InputMediaVideo = { type: 'video'; media: string | InputFile; thumbnail?: string | InputFile; caption?: string; parse_mode?: ParseMode; caption_entities?: MessageEntity[]; width?: number; height?: number; duration?: number; supports_streaming?: boolean; has_spoiler?: boolean; }; ``` -------------------------------- ### Configure testEnvironment Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Enable the test API server for development and testing purposes to avoid affecting production users. ```typescript const bot = new TelegramBot({ botToken: 'TEST_BOT_TOKEN', testEnvironment: true }); ``` -------------------------------- ### getMyDefaultAdministratorRights Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Retrieves the default administrator rights for the bot. ```APIDOC ## getMyDefaultAdministratorRights ### Description Retrieves the default administrator rights for the bot. ### Signature `async getMyDefaultAdministratorRights(options?: { for_channels?: boolean; }): Promise` ``` -------------------------------- ### getChat(options) Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Retrieves full information about a specific chat. ```APIDOC ## getChat(options) ### Description Get chat information. ### Parameters - **options** (object) - Required - Contains chat_id (number | string). ### Returns - **Promise** - Returns the full chat information object. ``` -------------------------------- ### sendAudio Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends an audio file to a specified chat. ```APIDOC ## sendAudio ### Description Sends an audio file (MP3/M4A, up to 50MB). ### Parameters - **chat_id** (number | string) - Required - Target chat ID - **audio** (InputFile | string) - Required - The audio file to send ``` -------------------------------- ### sendDocument Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends a general file to a specified chat. ```APIDOC ## sendDocument ### Description Sends a general file. ### Parameters - **chat_id** (number | string) - Required - Target chat ID - **document** (InputFile | string) - Required - The document to send ``` -------------------------------- ### Implement Type-Safe Command Routing Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/utility-classes-and-patterns.md Organize bot commands by mapping specific command strings to handler functions. Automatically strips bot usernames from command strings. ```typescript type CommandHandler = (msg: Message) => Promise; class CommandRouter { private commands: Map = new Map(); register(command: string, handler: CommandHandler) { this.commands.set(command, handler); } async route(msg: Message) { if (!msg.text || !msg.text.startsWith('/')) return; const parts = msg.text.split(' '); const command = parts[0].slice(1).split('@')[0]; // Remove @botname const handler = this.commands.get(command); if (handler) { await handler(msg); } } } // Usage const router = new CommandRouter(); router.register('start', async (msg) => { await bot.sendMessage({ chat_id: msg.chat.id, text: 'Start command' }); }); router.register('help', async (msg) => { await bot.sendMessage({ chat_id: msg.chat.id, text: 'Available commands: /start, /help' }); }); bot.on('message', (msg) => { router.route(msg); }); ``` -------------------------------- ### Configure Proxy Support for TelegramBot Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/README.md Use an http.Agent-compatible instance to route requests through HTTP or SOCKS5 proxies. This option is specific to Node.js environments. ```typescript import { TelegramBot } from 'typescript-telegram-bot-api'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; // HTTP/HTTPS proxy new TelegramBot({ botToken: 'TOKEN', agent: new HttpsProxyAgent('http://user:pass@host:8080') }); // SOCKS5 proxy new TelegramBot({ botToken: 'TOKEN', agent: new SocksProxyAgent('socks5://user:pass@host:1080') }); ``` -------------------------------- ### setMyDefaultAdministratorRights Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sets the default administrator rights for the bot. ```APIDOC ## setMyDefaultAdministratorRights ### Description Sets the default administrator rights for the bot. ### Signature `async setMyDefaultAdministratorRights(options?: { rights?: ChatAdministratorRights; for_channels?: boolean; }): Promise` ``` -------------------------------- ### setMyName Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sets the bot's name. ```APIDOC ## setMyName ### Description Sets the bot's name. ### Signature `async setMyName(options?: { name?: string; language_code?: string; }): Promise` ``` -------------------------------- ### Retrieve Bot Information Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Fetches basic bot details such as username and ID. ```typescript const bot = await bot.getMe(); console.log('Bot username:', bot.username); console.log('Bot ID:', bot.id); ``` -------------------------------- ### Configure test environment Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Use the testEnvironment flag to distinguish between production and test runs. ```typescript const bot = new TelegramBot({ botToken: process.env.BOT_TOKEN!, testEnvironment: process.env.NODE_ENV === 'test' }); ``` -------------------------------- ### sendDocument Method Definition Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Defines the signature for sending general files. ```typescript async sendDocument(options: { chat_id: number | string; document: InputFile | string; thumbnail?: InputFile | string; caption?: string; parse_mode?: ParseMode; disable_content_type_detection?: boolean; disable_notification?: boolean; protect_content?: boolean; reply_parameters?: ReplyParameters; reply_markup?: keyboard; }): Promise ``` -------------------------------- ### Reopen Forum Topic Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Reopens a previously closed forum topic. ```typescript async reopenForumTopic(options: { chat_id: number | string; message_thread_id: number; }): Promise ``` -------------------------------- ### sendVideoNote Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends a video message (rounded square MPEG4, up to 1 minute). ```APIDOC ## sendVideoNote ### Description Sends a video message (rounded square MPEG4, up to 1 minute). ### Parameters - **chat_id** (number | string) - Required - **video_note** (InputFile | string) - Required - **duration** (number) - Optional - **length** (number) - Optional - **thumbnail** (InputFile | string) - Optional - **disable_notification** (boolean) - Optional - **protect_content** (boolean) - Optional - **reply_parameters** (ReplyParameters) - Optional - **reply_markup** (keyboard) - Optional ``` -------------------------------- ### Register webhook with setWebhook Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Configure the bot to receive updates via a specific HTTPS URL. Optional parameters include secret tokens and connection limits. ```typescript await bot.setWebhook({ url: 'https://example.com/webhook', secret_token: 'my-secret-token-123' }); ``` -------------------------------- ### sendVideoNote Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends a rounded square MPEG4 video message, limited to 1 minute duration. ```typescript async sendVideoNote(options: { chat_id: number | string; video_note: InputFile | string; duration?: number; length?: number; thumbnail?: InputFile | string; disable_notification?: boolean; protect_content?: boolean; reply_parameters?: ReplyParameters; reply_markup?: keyboard; }): Promise ``` -------------------------------- ### sendMediaGroup Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends an album of media. ```APIDOC ## sendMediaGroup ### Description Sends an album of media. ### Parameters - **chat_id** (number | string) - Required - **media** (InputMediaPhoto | InputMediaVideo | InputMediaAudio | InputMediaDocument)[] - Required - **disable_notification** (boolean) - Optional - **protect_content** (boolean) - Optional - **message_effect_id** (string) - Optional - **reply_parameters** (ReplyParameters) - Optional ``` -------------------------------- ### sendMediaGroup Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends an album containing multiple media items. ```typescript async sendMediaGroup(options: { chat_id: number | string; media: (InputMediaPhoto | InputMediaVideo | InputMediaAudio | InputMediaDocument)[]; disable_notification?: boolean; protect_content?: boolean; message_effect_id?: string; reply_parameters?: ReplyParameters; }): Promise ``` -------------------------------- ### setChatTitle Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sets the title of a chat. ```APIDOC ## setChatTitle ### Description Set chat title. ### Method async setChatTitle(options: { chat_id: number | string; title: string; }): Promise ``` -------------------------------- ### addStickerToSet Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Adds a sticker to an existing set. ```APIDOC ## addStickerToSet ### Description Adds a new sticker to an existing sticker set. ### Method async addStickerToSet(options: { user_id: number; name: string; sticker: InputSticker; }): Promise ``` -------------------------------- ### Define Audio type Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/types.md Represents an audio file object. ```typescript type Audio = { file_id: string; file_unique_id: string; duration: number; performer?: string; title?: string; mime_type?: string; file_size?: number; thumbnail?: PhotoSize; }; ``` -------------------------------- ### sendVenue Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends a venue location with title and address details. ```typescript async sendVenue(options: { chat_id: number | string; latitude: number; longitude: number; title: string; address: string; foursquare_id?: string; foursquare_type?: string; google_place_id?: string; google_place_type?: string; disable_notification?: boolean; protect_content?: boolean; reply_parameters?: ReplyParameters; reply_markup?: keyboard; }): Promise ``` -------------------------------- ### sendVenue Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends a venue. ```APIDOC ## sendVenue ### Description Sends a venue. ### Parameters - **chat_id** (number | string) - Required - **latitude** (number) - Required - **longitude** (number) - Required - **title** (string) - Required - **address** (string) - Required - **foursquare_id** (string) - Optional - **foursquare_type** (string) - Optional - **google_place_id** (string) - Optional - **google_place_type** (string) - Optional - **disable_notification** (boolean) - Optional - **protect_content** (boolean) - Optional - **reply_parameters** (ReplyParameters) - Optional - **reply_markup** (keyboard) - Optional ``` -------------------------------- ### HTTP Methods by Category Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/INDEX.md Lists the HTTP methods used for various Telegram API operations. ```text Message Sending: POST (content via multipart/form-data for files) Chat Management: POST Sticker Operations: POST File Operations: GET (file downloads), POST (uploads) ``` -------------------------------- ### Send a sticker Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Sends a sticker to a specified chat. Requires chat_id and the sticker file or file ID. ```typescript async sendSticker(options: { chat_id: number | string; sticker: InputFile | string; emoji?: string; disable_notification?: boolean; protect_content?: boolean; reply_parameters?: ReplyParameters; reply_markup?: keyboard; }): Promise ``` -------------------------------- ### Configure allowedUpdates Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/configuration.md Filter incoming updates to reduce bandwidth and processing load. ```typescript const bot = new TelegramBot({ botToken: 'TOKEN', allowedUpdates: ['message'] }); ``` ```typescript const bot = new TelegramBot({ botToken: 'TOKEN', allowedUpdates: ['message', 'callback_query'] }); ``` ```typescript const bot = new TelegramBot({ botToken: 'TOKEN', allowedUpdates: ['inline_query', 'chosen_inline_result'] }); ``` -------------------------------- ### Send a contact Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/telegram-bot-class.md Sends a phone contact to the chat. ```typescript await bot.sendContact({ chat_id: 123, phone_number: '+1234567890', first_name: 'John' }); ``` -------------------------------- ### Set Webhook Source: https://github.com/borodin/typescript-telegram-bot-api/blob/main/_autodocs/api-methods.md Registers a URL to receive incoming updates via webhook. ```typescript async setWebhook(options: { url: string; certificate?: InputFile; ip_address?: string; max_connections?: number; allowed_updates?: UpdateType[]; drop_pending_updates?: boolean; secret_token?: string; }): Promise ```