I have an ASP.Net Core Web API. This web api application would make a post request to Telegram Bot API to send message to a Telegram group when a user create a content. Absolutely, the request to Telegram bot api from my web api was working fine for almost a year and a half. Until recently, the request will always fail as it exceeds timeout, and this happen only on Windows Server.
After facing this issue, I tried to copy that app to run on IIS on my local computer, and the api is working fine. To make sure if there was a problem with my code, I even built 2 small web applications using ASP.Net Core; one using Telegram Bot NUGET package, the same as my current API, and another using IHTTPClientFactory to make request directly to Telegram Bot API without the any thirdparty package. And, unfortunately, the apps request to Telegram API also exceed timeout. And in that new apps for testing, I added an action to request to thirdparty api on the web and it was working fine.
This is the code using in my ASP.Net Core Web API.
public async Task SendAsync(long receiver, Notification notification)
{
try
{
var response = await _bot.SendTextMessageAsync(new ChatId(receiver),
text:notification.Body,
parseMode:ParseMode.Html);
if (response != null) return;
throw new Exception($"Telegram Send Failed");
}
catch (Exception e)
{
_logger.LogError(e.Message);
}
}
And this is the exception that I get:
An unhandled exception has occurred while executing the request.
Exception:
Telegram.Bot.Exceptions.RequestException: Request timed out
System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
System.TimeoutException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
I appreciate your time reading my question and if anyone can help me, I would like to say “Thank you :)”