| | | 1 | | namespace TeleFlow.Telegram; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Controls how the Telegram client reacts to Bot API throttling responses that include retry timing metadata. |
| | | 5 | | /// This policy is used by the request executor for outgoing Bot API calls such as generated ctx.Bot.*Async methods. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record class TelegramRetryAfterPolicy |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Production-safe default that retries one short Telegram throttling response before surfacing the error. |
| | | 11 | | /// </summary> |
| | 1 | 12 | | public static TelegramRetryAfterPolicy Default { get; } = new() |
| | 1 | 13 | | { |
| | 1 | 14 | | Enabled = true, |
| | 1 | 15 | | MaxRetries = 1, |
| | 1 | 16 | | MaxDelay = TimeSpan.FromSeconds(5) |
| | 1 | 17 | | }; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Disables automatic retry-after waiting and surfaces Telegram throttling responses immediately. |
| | | 21 | | /// </summary> |
| | 1 | 22 | | public static TelegramRetryAfterPolicy Disabled { get; } = new() |
| | 1 | 23 | | { |
| | 1 | 24 | | Enabled = false, |
| | 1 | 25 | | MaxRetries = 0, |
| | 1 | 26 | | MaxDelay = TimeSpan.FromSeconds(5) |
| | 1 | 27 | | }; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets whether automatic retry-after waiting is enabled. |
| | | 31 | | /// </summary> |
| | | 32 | | public bool Enabled { get; init; } = true; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the maximum number of automatic retry attempts after the first throttled response. |
| | | 36 | | /// </summary> |
| | | 37 | | public int MaxRetries { get; init; } = 1; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the maximum Telegram-requested delay that the executor may wait automatically. |
| | | 41 | | /// </summary> |
| | 2 | 42 | | public TimeSpan MaxDelay { get; init; } = TimeSpan.FromSeconds(5); |
| | | 43 | | } |