Catch (some) APIErrors
This commit is contained in:
parent
7b9efdf002
commit
509935a9aa
|
@ -10,6 +10,7 @@ using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Telegram.Bot.Exceptions;
|
||||||
|
|
||||||
namespace TelegramRemindMe
|
namespace TelegramRemindMe
|
||||||
{
|
{
|
||||||
|
@ -116,10 +117,16 @@ namespace TelegramRemindMe
|
||||||
{
|
{
|
||||||
case "Add a new task":
|
case "Add a new task":
|
||||||
currentChat.IsWorkingMessage = true;
|
currentChat.IsWorkingMessage = true;
|
||||||
currentChat.WorkingMsg = Bot.EditMessageTextAsync(
|
//TODO: fix
|
||||||
new ChatId(currentChat.ChatId), callbackQueryEventArgs.CallbackQuery.Message.MessageId,
|
try
|
||||||
"How should your new task be called?"
|
{
|
||||||
).Result.MessageId;
|
currentChat.WorkingMsg = Bot.EditMessageTextAsync(
|
||||||
|
new ChatId(currentChat.ChatId), callbackQueryEventArgs.CallbackQuery.Message.MessageId,
|
||||||
|
"How should your new task be called?"
|
||||||
|
).Result.MessageId;
|
||||||
|
}
|
||||||
|
catch (ApiRequestException)
|
||||||
|
{}
|
||||||
currentChat.status = ChatStatusEnum.WaitingTaskTitle;
|
currentChat.status = ChatStatusEnum.WaitingTaskTitle;
|
||||||
break;
|
break;
|
||||||
case "Set a task as completed":
|
case "Set a task as completed":
|
||||||
|
@ -134,9 +141,14 @@ namespace TelegramRemindMe
|
||||||
sb.AppendLine("Send me the number of the task you want to complete.");
|
sb.AppendLine("Send me the number of the task you want to complete.");
|
||||||
|
|
||||||
currentChat.IsWorkingMessage = true;
|
currentChat.IsWorkingMessage = true;
|
||||||
currentChat.WorkingMsg =
|
try
|
||||||
Bot.EditMessageTextAsync(currentChat.ChatId,
|
{
|
||||||
|
currentChat.WorkingMsg = Bot.EditMessageTextAsync(currentChat.ChatId,
|
||||||
callbackQueryEventArgs.CallbackQuery.Message.MessageId, sb.ToString()).Result.MessageId;
|
callbackQueryEventArgs.CallbackQuery.Message.MessageId, sb.ToString()).Result.MessageId;
|
||||||
|
}
|
||||||
|
catch (ApiRequestException)
|
||||||
|
{}
|
||||||
|
|
||||||
currentChat.status = ChatStatusEnum.WaitingTaskComplete;
|
currentChat.status = ChatStatusEnum.WaitingTaskComplete;
|
||||||
break;
|
break;
|
||||||
case "Show all tasks":
|
case "Show all tasks":
|
||||||
|
@ -184,8 +196,12 @@ namespace TelegramRemindMe
|
||||||
await Bot.SendChatActionAsync(chat.ChatId, ChatAction.Typing);
|
await Bot.SendChatActionAsync(chat.ChatId, ChatAction.Typing);
|
||||||
|
|
||||||
//TODO: why is this firing when workingmsg already deleted?
|
//TODO: why is this firing when workingmsg already deleted?
|
||||||
if (chat.IsWorkingMessage)
|
try
|
||||||
await Bot.DeleteMessageAsync(chat.ChatId, chat.WorkingMsg);
|
{
|
||||||
|
if (chat.IsWorkingMessage)
|
||||||
|
await Bot.DeleteMessageAsync(chat.ChatId, chat.WorkingMsg);
|
||||||
|
}
|
||||||
|
catch (ApiRequestException){}
|
||||||
|
|
||||||
chat.IsWorkingMessage = false;
|
chat.IsWorkingMessage = false;
|
||||||
chat.status = ChatStatusEnum.Idle;
|
chat.status = ChatStatusEnum.Idle;
|
||||||
|
|
Loading…
Reference in a new issue