| | | 1 | | using Microsoft.AspNetCore.Builder; |
| | | 2 | | using Microsoft.AspNetCore.Http; |
| | | 3 | | using Microsoft.AspNetCore.Routing; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | using TeleFlow.Framework.Application; |
| | | 6 | | using TeleFlow.Framework.Updates; |
| | | 7 | | |
| | | 8 | | namespace TeleFlow.Telegram.Webhooks; |
| | | 9 | | |
| | | 10 | | public static class TelegramWebhookEndpointRouteBuilderExtensions |
| | | 11 | | { |
| | | 12 | | public static RouteHandlerBuilder MapTelegramWebhook(this IEndpointRouteBuilder endpoints) |
| | | 13 | | { |
| | 10 | 14 | | ArgumentNullException.ThrowIfNull(endpoints); |
| | | 15 | | |
| | 10 | 16 | | var options = endpoints.ServiceProvider.GetRequiredService<TelegramWebhookOptions>(); |
| | 10 | 17 | | var processor = endpoints.ServiceProvider.GetRequiredService<IUpdateProcessor>(); |
| | | 18 | | |
| | 10 | 19 | | TeleFlowRuntimeValidatorRunner.Validate(endpoints.ServiceProvider); |
| | | 20 | | |
| | 9 | 21 | | return endpoints.MapTelegramWebhook( |
| | 9 | 22 | | options.Path, |
| | 9 | 23 | | async (update, _, cancellationToken) => |
| | 9 | 24 | | { |
| | 6 | 25 | | await processor.ProcessAsync(new TelegramUpdatePayload(update), cancellationToken).ConfigureAwait(false) |
| | 5 | 26 | | return Results.Ok(); |
| | 5 | 27 | | }, |
| | 18 | 28 | | rawOptions => rawOptions.SecretToken = options.SecretToken); |
| | | 29 | | } |
| | | 30 | | } |