Telegraf Rate Limit
Rate-limiting middleware for Telegraf (Telegram bot framework).
This repository is forked from telegraf/telegraf-ratelimit in order to add limitation based on number of users who are using bot.
Installation
$ npm install telegraf-userbased-ratelimit
Example
const Telegraf = const rateLimit = // Set limit to 1 message per 3 secondsconst limitConfig = window: 3000 limit: 1 ctxconst telegraf = processenvBOT_TOKENtelegraftelegraftelegraf
API
Options
window
: how long to keep records of requests in memory in ms (default: 1 second)limit
: max number of messages during window (default: 1)keyGenerator
: key generator function (context -> any)onLimitExceeded
: rate-limit middleware
Default implementation of keyGenerator
:
{ return ctxfromid}