Skip to content
Discussion options

You must be logged in to vote

tgbot-cpp does not include an FSM like aiogram. Keep the state in the application, keyed by chat or user ID:

enum class State { Idle, WaitingForName };
std::unordered_map<std::int64_t, State> states;

bot.getEvents().onCommand("signup", [&](TgBot::Message::Ptr message) {
    states[message->chat->id] = State::WaitingForName;
    bot.getApi().sendMessage(message->chat->id, "Enter your name");
});

bot.getEvents().onNonCommandMessage([&](TgBot::Message::Ptr message) {
    if (states[message->chat->id] != State::WaitingForName) {
        return;
    }
    const auto name = message->text.value_or("");
    states.erase(message->chat->id);
    bot.getApi().sendMessage(message->chat->id, "Regist…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by reo7sp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants