Rate-limiting middleware for the Telegraf Telegram bot framework (v2.0.0). Simple in-memory rate limiter with configurable time window, request limit, custom key generation, and exceeded-limit callback. Lightweight, no external dependencies, designed for ease of integration with Telegraf. Suitable for basic bot rate limiting but not distributed or persistent (in-memory only). Actively maintained as part of the Telegraf ecosystem.
npm install telegraf-ratelimitVerified import paths — ran on the pinned version, not inferred.
Create a Telegram bot with Telegraf and apply rate limiting: 1 message per 3 seconds per user.
Use an external store (e.g., Redis) with a custom keyGenerator and external state.
Provide a custom keyGenerator that handles missing ctx.from.
Use a keyGenerator that includes chat ID, e.g., (ctx) => `${ctx.from.id}:${ctx.chat.id}`.Ensure Node.js >=12 (recommended) as older versions are out of support.
Use `const rateLimit = require('telegraf-ratelimit')` (CommonJS) or `import rateLimit from 'telegraf-ratelimit'` (ESM).Always provide a custom keyGenerator: `keyGenerator: (ctx) => ctx.from?.id ?? ctx.chat?.id`
No dependency data recorded yet.