Limiter
A fluent API builder for constructing rate-limiter rules.
Type Parameters
C
C extends GrammyContextConstructors
Limiter();Methods
fixedWindow
fixedWindow();
Sets the limiting strategy to Fixed Window.
tokenBucket
tokenBucket();
Sets the limiting strategy to Token Bucket.
customStrategy
customStrategy();
Sets a custom limiting strategy.
useStorage
useStorage();
Sets the storage engine for the rule.
limitFor
limitFor();
Defines what entity to rate-limit.
on
on();
Registers an event listener for this limiter instance. This allows for observing the limiter’s behavior for logging or analytics.
off
off();
Unregisters an event listener.
withKeyPrefix
withKeyPrefix();
Sets a prefix for all keys generated for this rule. Useful for preventing key collisions between different rules in the same storage.
onlyIf
onlyIf();
Rate limiter will only run if this function returns true.
onThrottled
onThrottled();
Defines the callback to execute when a request is throttled (rate-limited).
withPenalty
withPenalty();
Enables and configures the “Penalty Box” feature.
build
build();
Finalizes the configuration and returns a validated Rule instance.