diff --git a/StatusMenuUserState.cs b/StatusMenuUserState.cs index 76df23c..7b89f5c 100644 --- a/StatusMenuUserState.cs +++ b/StatusMenuUserState.cs @@ -17,11 +17,9 @@ namespace ZaoBot class StatusMenuUserState : IUserState { public const string CMD_BACK = "Назад"; + public const string CMD_CONFIRM_ITEM = "✅ "; ITelegramBotClient botClient; - private JsonDocument config; - HttpClient http = new HttpClient(); - OpenHabClient openhab; IServiceProvider services; StatusManager statusManager; @@ -31,8 +29,6 @@ namespace ZaoBot StatusManager statusManager) { this.botClient = botClient; - this.config = config.Data; - this.openhab = openhab; this.services = services; this.statusManager = statusManager; } @@ -40,6 +36,7 @@ namespace ZaoBot public async Task ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e) { var response = ""; + List> buttons = new List>(); if (previous != this) { response = "Возможные проблемы:\n"; @@ -47,6 +44,26 @@ namespace ZaoBot { response += item.label + ": " + item.status + "\n"; } + var confirmButtons = new List(); + foreach (var item in statusManager.StatusItems) + { + if (item.notified) + { + confirmButtons.Add(GetConfirmText(item)); + } + } + if (confirmButtons.Count > 0) buttons.Add(confirmButtons); + } + else if (e.Message.Text.StartsWith(CMD_CONFIRM_ITEM)) + { + foreach (var item in statusManager.StatusItems) + { + if (e.Message.Text == GetConfirmText(item)) + { + item.notified = false; + } + } + response = CMD_CONFIRM_ITEM; } else if (e.Message.Text == CMD_BACK) { @@ -58,12 +75,11 @@ namespace ZaoBot { response = "Я не понял"; } - var replyKeyboardMarkup = new ReplyKeyboardMarkup( - new KeyboardButton[][] - { - new KeyboardButton[] { CMD_BACK }, - } - ); + buttons.Add(new List() + { + CMD_BACK + }); + var replyKeyboardMarkup = new ReplyKeyboardMarkup(buttons); await botClient.SendTextMessageAsync( chatId: e.Message.Chat, @@ -72,5 +88,10 @@ namespace ZaoBot ); return this; } + + private string GetConfirmText(Problems.Item item) + { + return CMD_CONFIRM_ITEM + item.label; + } } }