77 lines
1.8 KiB
C#
77 lines
1.8 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Args;
|
|
using Telegram.Bot.Types.ReplyMarkups;
|
|
using ZaoBot.Config;
|
|
using ZaoBot.OpenHab;
|
|
using ZaoBot.Problems;
|
|
|
|
namespace ZaoBot
|
|
{
|
|
class StatusMenuUserState : IUserState
|
|
{
|
|
public const string CMD_BACK = "Назад";
|
|
|
|
ITelegramBotClient botClient;
|
|
private JsonDocument config;
|
|
HttpClient http = new HttpClient();
|
|
OpenHabClient openhab;
|
|
IServiceProvider services;
|
|
StatusManager statusManager;
|
|
|
|
public StatusMenuUserState(IServiceProvider services, ITelegramBotClient botClient,
|
|
IConfig config,
|
|
OpenHabClient openhab,
|
|
StatusManager statusManager)
|
|
{
|
|
this.botClient = botClient;
|
|
this.config = config.Data;
|
|
this.openhab = openhab;
|
|
this.services = services;
|
|
this.statusManager = statusManager;
|
|
}
|
|
|
|
public async Task<IUserState> ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e)
|
|
{
|
|
var response = "";
|
|
if (previous != this)
|
|
{
|
|
response = "Возможные проблемы:\n";
|
|
foreach (var item in statusManager.StatusItems)
|
|
{
|
|
response += item.label + ": " + item.status + "\n";
|
|
}
|
|
}
|
|
else if (e.Message.Text == CMD_BACK)
|
|
{
|
|
var newState = services.GetRequiredService<MainMenuUserState>();
|
|
await newState.ProcessMessage(this, e);
|
|
return newState;
|
|
}
|
|
else
|
|
{
|
|
response = "Я не понял";
|
|
}
|
|
var replyKeyboardMarkup = new ReplyKeyboardMarkup(
|
|
new KeyboardButton[][]
|
|
{
|
|
new KeyboardButton[] { CMD_BACK },
|
|
}
|
|
);
|
|
|
|
await botClient.SendTextMessageAsync(
|
|
chatId: e.Message.Chat,
|
|
text: response,
|
|
replyMarkup: replyKeyboardMarkup
|
|
);
|
|
return this;
|
|
}
|
|
}
|
|
}
|