Closed Caycedo closed 2 months ago
When initializing the Echotron client, the following default rate limit settings are applied:
Global Rate Limit:
Per-Chat Rate Limit:
Cleanup Interval: 1 minute
Rate Limiting: Enabled by default
Sets the global rate limit for all requests.
func SetGlobalRequestLimit(rps rate.Limit, burst int)
rps
burst
Example:
// Set global limit to 50 requests per second with a burst of 20 echotron.SetGlobalRequestLimit(rate.Every(20*time.Millisecond), 20)
Sets the per-chat rate limit and cleanup interval.
func SetChatRequestLimit(rps rate.Limit, burst int, cleanup time.Duration)
cleanup
// Set chat limit to 30 requests per minute with a burst of 10, cleanup every 5 minutes echotron.SetChatRequestLimit(rate.Every(2*time.Second), 10, 5*time.Minute)
Enables or disables the rate limiter.
func SetRateLimiterEnabled(enabled bool)
// Disable rate limiting echotron.SetRateLimiterEnabled(false) // Enable rate limiting echotron.SetRateLimiterEnabled(true)
SetChatRequestLimit
Remember, excessive API calls may lead to your bot being temporarily or permanently blocked by Telegram. Always use rate limiting responsibly.
Echotron Rate Limiter Documentation
Default Settings
When initializing the Echotron client, the following default rate limit settings are applied:
Global Rate Limit:
Per-Chat Rate Limit:
Cleanup Interval: 1 minute
Rate Limiting: Enabled by default
Helper Functions
1. SetGlobalRequestLimit
Sets the global rate limit for all requests.
rps
: Requests per secondburst
: Maximum burst sizeExample:
2. SetChatRequestLimit
Sets the per-chat rate limit and cleanup interval.
rps
: Requests per second (or any other time unit)burst
: Maximum burst sizecleanup
: Interval for cleaning up inactive chat limitersExample:
3. SetRateLimiterEnabled
Enables or disables the rate limiter.
Example:
Usage Notes
SetChatRequestLimit
, existing chat limiters are updated to the new settings.Best Practices
Remember, excessive API calls may lead to your bot being temporarily or permanently blocked by Telegram. Always use rate limiting responsibly.