public async Task InvokeAsync(HttpContext context, ITelegramHolder holder, IServiceProvider provider, ILogger <TelegramRouting> logger) { Update update; var serializer = new JsonSerializer(); using (var sr = new StreamReader(context.Request.Body)) using (var jsonTextReader = new JsonTextReader(sr)) { update = serializer.Deserialize <Update>(jsonTextReader); } if (update != null) { // Avoid multiple dispatching of the same update in case of delays if (_lastUpdateId.GetValueOrDefault(-1) != update.Id) { var botData = holder.Get(_endpoint); if (botData is not null) { await botData.Dispatcher.DispatchUpdateAsync(update, provider); } else { logger.LogWarning("No bots found that can manage this request"); } } else { logger.LogInformation("Duplicate update received - Ignoring..."); } } else { logger.LogError("Cannot parse webhook request into Update"); } context.Response.StatusCode = 200; await context.Response.WriteAsync("Ok"); }
public TestController(ITelegramHolder holder, IConfiguration configuration) { _holder = holder; _configuration = configuration; }