Skip to content

Commit

Permalink
possible fix for blocking error
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed May 13, 2024
1 parent 5f7d002 commit bd0a1f6
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public static async Task Main(string[] args)
pollingErrorHandler: HandlePollingErrorAsync,
receiverOptions: receiverOptions,
cancellationToken: cts.Token

);


User me = await botClient.GetMeAsync(cancellationToken: cts.Token);

Expand Down Expand Up @@ -144,14 +146,22 @@ static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update,
async Task SendResponse(string msg)
{
Console.WriteLine($"Chat response:\n{msg}");
bool isTopic = message.IsTopicMessage ?? false;
await botClient.SendTextMessageAsync(
chatId: chatId,
text: msg,
parseMode: ParseMode.MarkdownV2,
messageThreadId: isTopic ? message.MessageThreadId : null,
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
try
{
bool isTopic = message.IsTopicMessage ?? false;
await botClient.SendTextMessageAsync(
chatId: chatId,
text: msg,
parseMode: ParseMode.MarkdownV2,
messageThreadId: isTopic ? message.MessageThreadId : null,
replyToMessageId: message.MessageId,

cancellationToken: cancellationToken);
}
catch (Exception ex)
{
Console.WriteLine($"Unable to send msg: {ex.Message}");
}
}
}

Expand Down Expand Up @@ -298,7 +308,7 @@ static Task HandlePollingErrorAsync(ITelegramBotClient botClient, Exception exce
string errorMessage = exception switch
{
ApiRequestException apiRequestException
=> $"Telegram API Error:\n[{apiRequestException.ErrorCode}]\n{apiRequestException.Message}",
=> $"Telegram API Error:\n[{apiRequestException.ErrorCode}] {apiRequestException.Message}",
_ => exception.ToString()
};

Expand Down

0 comments on commit bd0a1f6

Please sign in to comment.