|
@@ -3,6 +3,7 @@ using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using MafiaTelegramBot.Models.Commands;
|
|
|
using MafiaTelegramBot.Models.Inlines;
|
|
|
+using MafiaTelegramBot.Models.Replies;
|
|
|
using Telegram.Bot;
|
|
|
using Telegram.Bot.Exceptions;
|
|
|
using Telegram.Bot.Types;
|
|
@@ -29,15 +30,18 @@ namespace MafiaTelegramBot.Controllers
|
|
|
return Ok();
|
|
|
}
|
|
|
*/
|
|
|
-
|
|
|
- public static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
|
|
+
|
|
|
+ public static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update,
|
|
|
+ CancellationToken cancellationToken)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var handle = update.Type switch
|
|
|
{
|
|
|
//TODO handle other update type if needed
|
|
|
- UpdateType.Message => Command.Update(update),
|
|
|
+ UpdateType.Message => update.Message.ReplyToMessage != null && update.Message.ReplyToMessage.Text != strings.start_message
|
|
|
+ ? Reply.Update(update)
|
|
|
+ : Command.Update(update),
|
|
|
UpdateType.CallbackQuery => Query.Update(update),
|
|
|
_ => UnknownUpdateHandlerAsync(update)
|
|
|
};
|
|
@@ -58,18 +62,20 @@ namespace MafiaTelegramBot.Controllers
|
|
|
await HandleErrorAsync(botClient, exception, cancellationToken);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private static Task UnknownUpdateHandlerAsync(Update update)
|
|
|
{
|
|
|
Console.WriteLine($"Unknown update type: {update.Type}");
|
|
|
return Task.CompletedTask;
|
|
|
}
|
|
|
-
|
|
|
- public static Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
|
|
|
+
|
|
|
+ public static Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception,
|
|
|
+ CancellationToken cancellationToken)
|
|
|
{
|
|
|
var errorMessage = exception switch
|
|
|
{
|
|
|
- ApiRequestException apiRequestException => $"Telegram API Error:\n[{apiRequestException.ErrorCode}]\n{apiRequestException.Message}",
|
|
|
+ ApiRequestException apiRequestException =>
|
|
|
+ $"Telegram API Error:\n[{apiRequestException.ErrorCode}]\n{apiRequestException.Message}",
|
|
|
_ => exception.ToString()
|
|
|
};
|
|
|
|