/
d.alekseev
/
SmartMenuBot
Обзор
Документация
Войти
/
d.alekseev
/
SmartMenuBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ConsoleBot/TelegramBot/Callbacks/Implementations/DeleteTaskCallbackCommand.cs
67 строк
3 KB
d.alekseev
feat: постраничная навигация задач и callback-управление карточкой задачи
15 фев 2026, 15:04
15 фев 2026, 15:04
69f4d23
Код
Авторство
О чём код?
using Telegram.Bot; using SmartMenuBot.Core.Services.Interfaces; using SmartMenuBot.TelegramBot.Callbacks; using SmartMenuBot.TelegramBot.Callbacks.Interfaces; using SmartMenuBot.TelegramBot.Dto; using SmartMenuBot.TelegramBot.Scenarios.Implementations; using SmartMenuBot.TelegramBot.Scenarios.Interfaces; using SmartMenuBot.TelegramBot.Scenarios.Models; namespace SmartMenuBot.TelegramBot.Callbacks.Implementations { public class DeleteTaskCallbackCommand( ITelegramBotClient botClient, IToDoService toDoService, IScenarioContextRepository contextRepository) : ICallbackCommand { public string Action => "deletetask"; public bool CanExecute(CallbackCommandContext context) { return string.Equals(context.Dto.Action, Action, StringComparison.OrdinalIgnoreCase); } public async Task ExecuteAsync(CallbackCommandContext context) { if (context.Query.Message is null) return; var ct = context.CancellationToken; var dto = ToDoItemCallbackDto.FromString(context.Query.Data ?? string.Empty); if (dto.ToDoItemId == Guid.Empty) { await botClient.EditMessageText( context.Query.Message.Chat.Id, context.Query.Message.MessageId, "Некорректный идентификатор задачи.", cancellationToken: ct); return; } var task = await toDoService.GetAsync(dto.ToDoItemId, ct); if (task is null || task.User.TelegramUserId != context.Query.From.Id) { await botClient.EditMessageText( context.Query.Message.Chat.Id, context.Query.Message.MessageId, "Задача не найдена.", cancellationToken: ct); return; } var scenarioContext = new ScenarioContext(ScenarioType.DeleteTask) { CurrentStep = DeleteTaskScenario.ConfirmStep }; scenarioContext.Data[DeleteTaskScenario.TaskIdDataKey] = dto.ToDoItemId; await contextRepository.SetContext(context.Query.From.Id, scenarioContext, ct); await botClient.SendMessage( context.Query.Message.Chat.Id, $"Подтверждаете удаление задачи \"{task.Name}\"?", replyMarkup: DeleteTaskScenario.BuildDeleteConfirmKeyboard(), cancellationToken: ct); } } }