| | | 1 | | namespace TeleFlow.Telegram.Webhooks.Internal; |
| | | 2 | | |
| | | 3 | | internal static class TelegramRawWebhookOptionsValidator |
| | | 4 | | { |
| | | 5 | | public static void Validate(TelegramRawWebhookOptions options) |
| | | 6 | | { |
| | 24 | 7 | | ArgumentNullException.ThrowIfNull(options); |
| | | 8 | | |
| | 24 | 9 | | if (options.SecretToken is not null) |
| | | 10 | | { |
| | 7 | 11 | | if (string.IsNullOrWhiteSpace(options.SecretToken)) |
| | | 12 | | { |
| | 0 | 13 | | throw new InvalidOperationException("Telegram webhook secret token must not be empty."); |
| | | 14 | | } |
| | | 15 | | |
| | 7 | 16 | | options.SecretToken = options.SecretToken.Trim(); |
| | | 17 | | } |
| | | 18 | | |
| | 24 | 19 | | ValidateStatusCode( |
| | 24 | 20 | | options.InvalidPayloadStatusCode, |
| | 24 | 21 | | nameof(TelegramRawWebhookOptions.InvalidPayloadStatusCode)); |
| | 23 | 22 | | ValidateStatusCode( |
| | 23 | 23 | | options.SecretTokenFailureStatusCode, |
| | 23 | 24 | | nameof(TelegramRawWebhookOptions.SecretTokenFailureStatusCode)); |
| | 22 | 25 | | } |
| | | 26 | | |
| | | 27 | | private static void ValidateStatusCode(int statusCode, string optionName) |
| | | 28 | | { |
| | 47 | 29 | | if (statusCode is < 100 or > 599) |
| | | 30 | | { |
| | 2 | 31 | | throw new InvalidOperationException( |
| | 2 | 32 | | $"{optionName} must be a valid HTTP status code between 100 and 599."); |
| | | 33 | | } |
| | 45 | 34 | | } |
| | | 35 | | } |