30 рядки
624 B
Go
30 рядки
624 B
Go
package telegram
|
|
|
|
import (
|
|
"time"
|
|
|
|
ta "github.com/mymmrac/telego/telegoapi"
|
|
)
|
|
|
|
const (
|
|
apiMaxAttempts = 3
|
|
apiMaxDelay = 30 * time.Second
|
|
)
|
|
|
|
// NewCaller returns the Telegram API caller. It retries transient failures and
|
|
// honors 429 retry_after, waiting only when the requested delay fits apiMaxDelay.
|
|
func NewCaller() ta.Caller {
|
|
return newCaller()
|
|
}
|
|
|
|
func newCaller() *ta.RetryCaller {
|
|
return &ta.RetryCaller{
|
|
Caller: ta.DefaultFastHTTPCaller,
|
|
MaxAttempts: apiMaxAttempts,
|
|
ExponentBase: 2,
|
|
StartDelay: time.Second,
|
|
MaxDelay: apiMaxDelay,
|
|
RateLimit: ta.RetryRateLimitWaitOrAbort,
|
|
}
|
|
}
|