go-telegram/bot v1.24.0 fixes getUpdates to honour Telegram's retry_after on a 429 instead of its own 100ms-doubling-to-5s backoff (release notes: https://github.com/go-telegram/bot/releases/tag/v1.24.0). pipelineErrorHandler was our workaround for that upstream gap -- it now just logs.
27 lines
862 B
Go
27 lines
862 B
Go
package telegram
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/go-telegram/bot"
|
|
)
|
|
|
|
// pipelineErrorHandler logs update-loop failures.
|
|
//
|
|
// go-telegram/bot v1.24.0 fixed getUpdates to honour retry_after on a 429
|
|
// itself (https://github.com/go-telegram/bot/releases/tag/v1.24.0), instead
|
|
// of retrying on its own 100ms-doubling-to-5s schedule regardless of what
|
|
// Telegram asked for. This handler used to block for RetryAfter itself to
|
|
// compensate; that workaround is gone now that the library does it.
|
|
func (g *Gateway) pipelineErrorHandler(_ context.Context) func(error) {
|
|
return func(err error) {
|
|
if tooMany, ok := errors.AsType[*bot.TooManyRequestsError](err); ok {
|
|
g.log.Warn("telegram rate limited", "retry_after", tooMany.RetryAfter,
|
|
"component", "gateway-telegram")
|
|
return
|
|
}
|
|
g.log.Error("telegram pipeline error", "error", err)
|
|
}
|
|
}
|