/
d.alekseev
/
SmartMenuBot
Обзор
Документация
Войти
/
d.alekseev
/
SmartMenuBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ConsoleBot/TelegramBot/Callbacks/Implementations/AddListCallbackCommand.cs
56 строк
2 KB
d.alekseev
feat: списки задач, callback-сценарии и рефактор маршрутизации UpdateHandler
13 фев 2026, 17:30
13 фев 2026, 17:30
a225948
Код
Авторство
О чём код?
using Telegram.Bot; using SmartMenuBot.Core.Services.Interfaces; using SmartMenuBot.TelegramBot.Callbacks; using SmartMenuBot.TelegramBot.Callbacks.Interfaces; using SmartMenuBot.TelegramBot.Scenarios.Implementations; using SmartMenuBot.TelegramBot.Scenarios.Interfaces; using SmartMenuBot.TelegramBot.Scenarios.Models; namespace SmartMenuBot.TelegramBot.Callbacks.Implementations { public class AddListCallbackCommand( ITelegramBotClient botClient, IUserService userService, IScenarioContextRepository contextRepository) : ICallbackCommand { public string Action => "addlist"; 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 user = await userService.GetUserAsync(context.Query.From.Id, ct); if (user is null) { await botClient.SendMessage( context.Query.Message.Chat.Id, "Для использования этой функции необходимо авторизоваться командой /start", replyMarkup: ReplyKeyboards.PreRegistration, cancellationToken: ct); return; } // Инициализация старта сценария на уровне callback-команды сохраняет единый вход через callback Command pattern. var scenarioContext = new ScenarioContext(ScenarioType.AddList) { CurrentStep = AddListScenario.NameStep }; scenarioContext.Data[AddListScenario.UserDataKey] = user; await contextRepository.SetContext(context.Query.From.Id, scenarioContext, ct); await botClient.SendMessage( context.Query.Message.Chat.Id, "Введите название списка:", replyMarkup: ReplyKeyboards.ScenarioCancel, cancellationToken: ct); } } }