Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@mediv0/rate-limit
Advanced tools
dead simple rate limiter for telegram bots with typescript support.
can be used to limit the number of messages sent by a user, using a token bucket algorithm. works fine with both telegraf and Telegram-Bot-API packages.
Supported Drivers:
adding other drivers is not supported yet. ( will be soon )
yarn add @mediv0/rate-limit
or
npm install @mediv0/rate-limit
import { Limiter } from "@mediv0/rate-limit";
// init
const limiter = new Limiter("memory", {
interval: 10,
max: 5,
driverOptions: {},
});
// Telegram-Bot-API example
bot.on("message", async (msg) => {
try {
const userId = msg.chat.id;
await limiter.limit(userId);
bot.sendMessage(chatId, "Hello World!");
} catch (e) {
// catch rate limit errors
}
});
Limiter<K extends keyof driver>
K
, options: ILimiterOptions<driver[K]>
)driver -> memory
| redis
ILimiterOptions ->
{
max: number; // maximum number of messages allowed in the interval
interval: number; // interval in minutes e.g -> 2
driverOptions: T; // driver specific options
}
for example, in snipet below, a user can send maximum 100 messages in interval of 5 minutes. if the user sends more than 100 messages, the limiter will throw an error.
const limiter = new Limiter("memory", {
interval: 5,
max: 100,
driverOptions: {},
});
driver used in this packages is from npm redis
you can pass options used in redis package to rate limiter.
limiter = new Limiter("redis", {
interval: 10,
max: 5,
driverOptions: {
url: "redis://localhost:6379",
name: "test",
password: "test",
legacyMode: false,
// other options
},
});
FAQs
rate limit telegram bots
The npm package @mediv0/rate-limit receives a total of 14 weekly downloads. As such, @mediv0/rate-limit popularity was classified as not popular.
We found that @mediv0/rate-limit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.