【发布时间】:2017-10-26 05:26:20
【问题描述】:
我正在尝试使用 C# API 获取 Telegram 消息。问题是当我的互联网连接中断然后重新连接时,机器人没有收到我的消息。有什么解决办法吗?
public async Task StartAsync()
{
var botClient = new Telegram.Bot.TelegramBotClient("API_KEY");
// check if last message is newer than already processed message
DateTime lastChecked = DateTime.Now;
while (true)
{
var listenForChanges = await botClient.GetUpdatesAsync();
if (lastChecked < listenForChanges.Last().Message.Date)
{
lastChecked = DateTime.Now;
//do something
}
}
}
【问题讨论】:
-
它会抛出异常吗?你试过调试吗?
-
没有例外。在我放“//做某事”的地方,程序会向 Telegram 发送响应,但在这种情况下,它看起来程序正在无异常运行,但它不发送消息,所以我猜也没有收到消息。