Grammy Throttler (Transformer)
Throttling transformer for Grammy bot framework, written in Typescript and built with Bottleneck.
About
This throttler aims to limit and queue outgoing Telegram API calls to conform to the official Telegram API rate limits.
Configuration
The throttler accepts a single optional argument of the following form:
type ThrottlerOptions = {
global? Bottleneck.ConstructorOptions;
group?: Bottleneck.ConstructorOptions;
out?: Bottleneck.ConstructorOptions;
};
The full list of object properties available for Bottleneck.ConstructorOptions
can be found at Bottleneck.
If no argument is passed, the throttler created will use the default configuration settings which should be appropriate for most use cases. The default configuration are as follows:
const globalConfig = {
reservoir: 30,
reservoirRefreshAmount: 30,
reservoirRefreshInterval: 1000,
};
const groupConfig = {
maxConcurrent: 1,
minTime: 1000,
reservoir: 20,
reservoirRefreshAmount: 20,
reservoirRefreshInterval: 60000,
};
const outConfig = {
maxConcurrent: 1,
minTime: 1000,
};
Usage
import { Bot } from 'https://dsr.edjopato.de/grammy/^1.0.0/mod.ts';
import { apiThrottler } from 'https://dsr.edjopato.de/grammy_transformer_throttler/^0.1.0/mod.ts';
const botToken = Deno.env.get('BOT_TOKEN');
if (!botToken) {
throw Error('BOT_TOKEN is required');
}
const bot = new Bot(botToken);
const throttler = apiThrottler();
bot.api.config.use(throttler);
bot.command('/example', ctx => ctx.reply('I am throttled'));
bot.start();