2025-07-24 23:19:59 +04:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Telegram.Bot;
|
|
|
|
|
using Telegram.Bot.Polling;
|
|
|
|
|
using Telegram.Bot.Types;
|
2026-03-06 23:19:24 +04:00
|
|
|
using Telegrator.Core;
|
2026-03-09 03:22:23 +04:00
|
|
|
using Telegrator.Core.States;
|
2026-03-06 23:19:24 +04:00
|
|
|
using Telegrator.Mediation;
|
2025-07-24 23:19:59 +04:00
|
|
|
|
2026-03-09 13:23:21 +04:00
|
|
|
namespace Telegrator.Polling;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public class HostUpdateRouter : UpdateRouter
|
2025-07-24 23:19:59 +04:00
|
|
|
{
|
2026-03-09 13:23:21 +04:00
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="ILogger"/> of this router
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly ILogger<HostUpdateRouter> Logger;
|
|
|
|
|
|
2025-07-26 00:01:46 +04:00
|
|
|
/// <inheritdoc/>
|
2026-03-09 13:23:21 +04:00
|
|
|
public HostUpdateRouter(
|
|
|
|
|
IHandlersProvider handlersProvider,
|
|
|
|
|
IAwaitingProvider awaitingProvider,
|
|
|
|
|
IStateStorage stateStorage,
|
|
|
|
|
IOptions<TelegratorOptions> options,
|
|
|
|
|
ITelegramBotInfo botInfo,
|
|
|
|
|
ILogger<HostUpdateRouter> logger) : base(handlersProvider, awaitingProvider, stateStorage, options.Value, botInfo)
|
2025-07-24 23:19:59 +04:00
|
|
|
{
|
2026-03-09 13:23:21 +04:00
|
|
|
Logger = logger;
|
|
|
|
|
ExceptionHandler = new DefaultRouterExceptionHandler(HandleException);
|
|
|
|
|
}
|
2025-07-24 23:19:59 +04:00
|
|
|
|
2026-03-09 13:23:21 +04:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
//Logger.LogInformation("Received update of type \"{type}\"", update.Type);
|
|
|
|
|
return base.HandleUpdateAsync(botClient, update, cancellationToken);
|
|
|
|
|
}
|
2025-07-24 23:19:59 +04:00
|
|
|
|
2026-03-09 13:23:21 +04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Default exception handler of this router
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="botClient"></param>
|
|
|
|
|
/// <param name="exception"></param>
|
|
|
|
|
/// <param name="source"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
public void HandleException(ITelegramBotClient botClient, Exception exception, HandleErrorSource source, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
if (exception is HandlerFaultedException handlerFaultedException)
|
2025-07-24 23:19:59 +04:00
|
|
|
{
|
2026-03-09 13:23:21 +04:00
|
|
|
Logger.LogError("\"{handler}\" handler's execution was faulted :\n{exception}",
|
|
|
|
|
handlerFaultedException.HandlerInfo.ToString(),
|
|
|
|
|
handlerFaultedException.InnerException?.ToString() ?? "No inner exception");
|
|
|
|
|
return;
|
2025-07-24 23:19:59 +04:00
|
|
|
}
|
|
|
|
|
|
2026-03-09 13:23:21 +04:00
|
|
|
Logger.LogError("Exception was thrown during update routing faulted :\n{exception}", exception.ToString());
|
2025-07-24 23:19:59 +04:00
|
|
|
}
|
|
|
|
|
}
|