grammY is a powerful, user-friendly, and highly efficient framework designed for creating Telegram bots using TypeScript or JavaScript. As of version 1.42.0, it offers robust support for the latest Telegram Bot API features, frequently releasing updates to keep pace with Telegram's evolving platform (e.g., Bot API 9.6 in recent releases). It distinguishes itself with comprehensive documentation, seamless integration with web frameworks (like Express, Koa, Bun, Cloudflare Workers) and databases, and a thriving ecosystem of plugins. The library emphasizes scalability and performance, making it suitable for both novice bot developers and large-scale applications. It runs on Node.js (requiring ^12.20.0 || >=14.13.1) and Deno.
npm install grammyVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a grammY bot, registers handlers for text messages and the `/start` command, and starts it using long polling. It demonstrates basic message echoing and includes essential error handling for the bot token, ensuring the bot runs securely by advocating environment variables for sensitive data.
Always load your bot token from environment variables (`process.env.BOT_TOKEN`) or a secure configuration management system. Never commit tokens to version control.
Regularly update grammY to its latest version to ensure compatibility with the Telegram Bot API. Monitor the grammY release notes for any migration guides or breaking changes, especially when new Bot API versions are released.
Standardize on ES Modules (`import`/`export`) for new projects and consider migrating existing CommonJS projects. Ensure your `package.json` specifies `"type": "module"` for ESM, or use a TypeScript compiler that targets ESM.
Verify that your server's firewall allows traffic on the webhook port. Ensure the URL provided to Telegram via `bot.setWebhook()` is correct and resolves to your server. Use a service like `ngrok` for local development to test webhook functionality.
Ensure the `BOT_TOKEN` environment variable is set before running your bot, or pass a valid token string to the `Bot` constructor. Example: `process.env.BOT_TOKEN`.
Verify that `new Bot(BOT_TOKEN)` successfully created a bot instance and that `BOT_TOKEN` is a valid string. Check for typos or incorrect variable assignments.
Use a non-privileged port (e.g., 3000, 8080) for your webhook server if running as a non-root user. If you must use a privileged port, configure your system to allow the bot's process to bind to it, or use a reverse proxy (like Nginx) to forward requests.
Always use `await` for asynchronous operations (e.g., `ctx.reply()`, API calls) inside your middleware. Implement proper error handling using `try...catch` blocks or `bot.catch()` middleware to gracefully manage errors.
No dependency data recorded yet.