#include "SubscribeCaseDialog.h" #include "CourtApi.h" #include "DialogHelpers.h" #include "Logger.h" #include #include #include namespace { // clang-format off // Состояния struct WaitingForInput; struct GettingCaseDetails; struct WaitingForConfirmation; // События struct CaseDetailsFetched : statechart::event { }; struct SubscriptionConfirmed : statechart::event { }; // clang-format on } // namespace struct SubscribeCaseStateMachine : StateMachine { using StateMachine::StateMachine; }; namespace { struct WaitingForInput : State { using reactions = statechart::custom_reaction; explicit WaitingForInput(const my_context& ctx) : State(ctx, "WaitingForInput") { auto& dialog = context().dialog; std::string text = "Введите номер дела"; banana::api::send_message(dialog.getAgent(), {.chat_id = dialog.getUserId(), .text = std::move(text)}, [](auto) {}); } statechart::result react(const NewMessageEvent& event) { return transit(); } }; struct GettingCaseDetails : State { explicit GettingCaseDetails(const my_context& ctx) : State(ctx, "GettingCaseDetails") {} }; struct WaitingForConfirmation : State { explicit WaitingForConfirmation(const my_context& ctx) : State(ctx, "WaitingForConfirmation") {} }; } // namespace ///////////////////////////////////////////////////////////////////////////// SubscribeCaseDialog::SubscribeCaseDialog(banana::agent::beast_callback& agent, banana::integer_t userId) : Dialog(agent, userId, "SubscribeCase"), machine_(std::make_unique(*this)) { machine_->initiate(); } SubscribeCaseDialog::~SubscribeCaseDialog() = default; bool SubscribeCaseDialog::processMessage(const banana::api::message_t& message) { machine_->process_event(NewMessageEvent{message}); return machine_->state_cast().isFinal(); } bool SubscribeCaseDialog::processCallbackQuery(const banana::api::callback_query_t& query) { machine_->process_event(NewCallbackQueryEvent{query}); return machine_->state_cast().isFinal(); }