tgbotapi/tgbotapi.behaviour_builder.fsm
InsanusMokrassar 804b991921 update kdocs 2023-03-04 21:18:50 +06:00
..
src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder fixes in media groups collecting and kdocs 2023-03-01 13:14:18 +06:00
README.md update behaviour builder fsm readme 2021-10-18 20:08:55 +06:00
build.gradle update kdocs 2023-03-04 21:18:50 +06:00

README.md

TelegramBotAPI Behaviour Builder FSM Extensions

Maven Central

What is it?

This extension has been created to integrate finite state machine in BehaviourBuilder. In case you wish to use some custom store for steps (states), you may extend StatesManager or use DefaultStatesManager with custom DefaultStatesManagerRepo. See Examples repo to get more info and see how it works on base level.

Lets see several examples:

data class StateRealization(override val context: ChatId) : State

bot.telegramBotWithBehaviourAndFSMAndStartLongPolling(TOKEN) {
    strictlyOn<StateRealization> {
        // here your logic of state
        it // you must return from state handler some other state as a result of this one or null if you want to complete the chain
    }

    onCommand("start") {
        startChain(StateRealization(it.chat.id)) // starting of chain with StateRealization state
    }
}

Currently, for the states there is only one restriction - your state must implements State interface and override context to define it. It may be important that context will be used under the hood for comparison with contexts of other states in some situations in it may be important to correctly realize equals method.

It is important, that all other methods are the same as for BehaviourBuilder.