This package, `node-telegram-bot-api`, provides a comprehensive interface for interacting with the official Telegram Bot API in Node.js environments. It currently maintains version `0.67.0`, which includes robust support for Telegram Bot API up to v8.1, demonstrating an active release cadence closely aligned with new Telegram API features and ensuring compatibility. The library supports both long polling and webhook methods for receiving updates, offering flexibility for various deployment scenarios and scalability needs. Its primary differentiator is its direct and extensive mapping to the Telegram Bot API methods, providing a low-level yet convenient way to build Telegram bots. It offers robust event-driven handling for various message types and commands, along with utilities for sending messages, media, and managing chat interactions. It is a foundational choice for developers looking for a well-maintained, feature-rich, and community-supported Telegram bot development library in Node.js.
npm install node-telegram-bot-apiVerified import paths — ran on the pinned version, not inferred.
Initializes a Telegram bot with long polling for updates, then echoes any message sent to it and responds specifically to the `/echo` command, acknowledging all other messages.
Consult the official Telegram Bot API documentation and the `node-telegram-bot-api` changelog for migration guides. Update your bot's code to align with the latest API specifications.
Always use environment variables (e.g., `process.env.TELEGRAM_BOT_TOKEN`) to store and retrieve sensitive tokens. For development, you can use `.env` files with packages like `dotenv`.
Install the type definitions as a development dependency: `npm install --save-dev @types/node-telegram-bot-api`.
For production bots, consider using webhooks instead of polling. This involves setting up an HTTPS server to receive updates directly from Telegram, which is more resource-efficient and scalable. Refer to the library's documentation on webhook setup.
Verify your bot token with @BotFather on Telegram. Ensure there are no typos and that the token is active. If you recently regenerated it, update your application's configuration.
Add nullish coalescing or optional chaining (`msg?.chat?.id`) to safely access properties. Debug your `bot.on()` or `bot.onText()` handlers to ensure the incoming `msg` object matches the expected Telegram `Message` structure for that event.
Check your internet connection and network configuration. Ensure no firewalls are blocking outgoing connections to `api.telegram.org`. You can also try a simple `ping api.telegram.org` from your server. If the issue persists, Telegram's API might be temporarily unavailable.
No dependency data recorded yet.