Add exception handling to MessageDispatcherHandler
This commit is contained in:
parent
5aa5c2b183
commit
4e330a2455
@ -1,6 +1,7 @@
|
|||||||
using Insight.TelegramBot;
|
using Insight.TelegramBot;
|
||||||
using Insight.TelegramBot.Models;
|
using Insight.TelegramBot.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Telegram.Bot.Exceptions;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Nocr.TelegramClient.AppServices.Bots.MessageDispatcher;
|
namespace Nocr.TelegramClient.AppServices.Bots.MessageDispatcher;
|
||||||
@ -25,7 +26,16 @@ public sealed class MessageDispatcherHandler : IMessageDispatcherHandler
|
|||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case TextMessage tm:
|
case TextMessage tm:
|
||||||
|
try
|
||||||
|
{
|
||||||
await _bot.SendMessageAsync(tm, cancellationToken);
|
await _bot.SendMessageAsync(tm, cancellationToken);
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is ApiRequestException &&
|
||||||
|
ex.Message.Equals("Forbidden: bot was blocked by the user",
|
||||||
|
StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Failed to deliver message due bot was blocked by the user [{ChatId}]", tm.ChatId);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case AnimationMessage am:
|
case AnimationMessage am:
|
||||||
await _bot.SendAnimationAsync(am, cancellationToken);
|
await _bot.SendAnimationAsync(am, cancellationToken);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user