BehaviourContextWithFSM

interface BehaviourContextWithFSM<T : State> : BehaviourContext, StatesMachine<T>

Interface which combine BehaviourContext and StatesMachine. Subcontext of triggers and states contexts must have one common flow of updates and must not lose updates between updates

See also

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val allowedUpdates: List<String>
Link copied to clipboard
abstract val allUpdatesFlow: Flow<Update>
Link copied to clipboard
Link copied to clipboard
open val bot: TelegramBot
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract val messagesFlow: Flow<MessageUpdate>
Link copied to clipboard
Link copied to clipboard
abstract val pollAnswersFlow: Flow<PollAnswerUpdate>
Link copied to clipboard
abstract val pollsFlow: Flow<PollUpdate>
Link copied to clipboard
Link copied to clipboard
open val scope: CoroutineScope
Link copied to clipboard
Link copied to clipboard

Will be called BEFORE handling of State will be started

Link copied to clipboard
Link copied to clipboard
abstract val unknownUpdatesFlow: Flow<UnknownUpdate>

Functions

Link copied to clipboard
abstract fun <I : T> add(kClass: KClass<I>, strict: Boolean = false, handler: BehaviourWithFSMStateHandler<I, T>)

Add NON STRICT handler to list of available in future BehaviourContextWithFSM. Non strict means that for input State will be used KClass.isInstance and any inheritor of kClass will pass this requirement

Link copied to clipboard
open fun <I : T> addStrict(kClass: KClass<I>, handler: BehaviourWithFSMStateHandler<I, T>)

Add STRICT handler to list of available in future BehaviourContextWithFSM. Strict means that for input State will be used State::class == kClass and any State with exactly the same type will pass requirements

Link copied to clipboard
suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(flowUpdatesFilter: FlowsUpdatesFilter, scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), fallbackHandler: BehaviourWithFSMStateHandlerHolder<T, T>? = null, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, stateInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContextWithFSM<T>, Unit, T> = {}, block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>): DefaultBehaviourContextWithFSM<T>

Creates BehaviourContextWithFSM via creating of DefaultBehaviourContext with this as TelegramBot, scope as target scope for that DefaultBehaviourContext and FlowsUpdatesFilter.allUpdatesFlow of flowUpdatesFilter as DefaultBehaviourContext.upstreamUpdatesFlow. Pass statesManager to customize some internal logic of states changes. Pass presetHandlers in case you have some list of BehaviourWithFSMStateHandlerHolder with presets. Use this method in case you wish to make some additional actions with flowUpdatesFilter.

suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(upstreamUpdatesFlow: Flow<Update>? = null, scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), fallbackHandler: BehaviourWithFSMStateHandlerHolder<T, T>? = null, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, stateInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContextWithFSM<T>, Unit, T> = {}, block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>): DefaultBehaviourContextWithFSM<T>

Creates BehaviourContextWithFSM via creating of DefaultBehaviourContext with this as TelegramBot, scope as target scope for that DefaultBehaviourContext and upstreamUpdatesFlow. Pass statesManager to customize some internal logic of states changes. Pass presetHandlers in case you have some list of BehaviourWithFSMStateHandlerHolder with presets.

Link copied to clipboard
suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), fallbackHandler: BehaviourWithFSMStateHandlerHolder<T, T>? = null, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), timeoutSeconds: Seconds = 30, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, stateInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContextWithFSM<T>, Unit, T> = {}, block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>): Job
suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(upstreamUpdatesFlow: Flow<Update>? = null, scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), fallbackHandler: BehaviourWithFSMStateHandlerHolder<T, T>? = null, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), timeoutSeconds: Seconds = 30, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, stateInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContextWithFSM<T>, Unit, T> = {}, block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>): Pair<DefaultBehaviourContextWithFSM<T>, Job>

Use buildBehaviourWithFSM to create BehaviourContextWithFSM and launch getting of updates using longPolling. For longPolling will be used result BehaviourContextWithFSM for both parameters flowsUpdatesFilter and scope

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract override fun copy(bot: TelegramBot, scope: CoroutineScope, broadcastChannelsSize: Int, onBufferOverflow: BufferOverflow, upstreamUpdatesFlow: Flow<Update>?, triggersHolder: TriggersHolder, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update>): BehaviourContextWithFSM<T>
abstract fun copy(bot: TelegramBot = this.bot, scope: CoroutineScope = this.scope, broadcastChannelsSize: Int = 100, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, upstreamUpdatesFlow: Flow<Update>? = null, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, triggersHolder: TriggersHolder = this.triggersHolder, stateInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContextWithFSM<T>, Unit, T> = this.stateInitialAction, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler()): BehaviourContextWithFSM<T>
Link copied to clipboard
abstract suspend fun <T : Any> execute(request: Request<T>): T
Link copied to clipboard
fun <T : State> BehaviourContext.fsmOrNull(): StatesMachine<T>?

Extracting from BehaviourContext.data exists StatesMachine by key DATA_FSM_KEY, which usually some BehaviourContextWithFSM. In case if value absent in BehaviourContext.data will return null

Link copied to clipboard
fun <T : State> BehaviourContext.fsmOrThrow(): StatesMachine<T>

Extracting from BehaviourContext.data exists StatesMachine by key DATA_FSM_KEY, which usually some BehaviourContextWithFSM. In case if value absent in BehaviourContext.data will throw NullPointerException

Link copied to clipboard
abstract suspend fun StatesMachine<in T>.handleState(state: T): T?
Link copied to clipboard
open suspend fun launchStateHandling(state: T, handlers: List<CheckableHandlerHolder<in T, T>>): T?
open suspend fun launchStateHandling(state: T, handlers: List<CheckableHandlerHolder<in T, T>>, onStateHandlingErrorHandler: StateHandlingErrorHandler<T>): T?
Link copied to clipboard

Add NON STRICT handler to list of available in future BehaviourContextWithFSM. Non strict means that for input State will be used KClass.isInstance and any inheritor of kClass will pass this requirement

Link copied to clipboard
abstract fun start(scope: CoroutineScope): Job
open suspend fun start(): Job
Link copied to clipboard
abstract suspend fun startChain(state: T)
Link copied to clipboard
inline fun <I : O, O : State> BehaviourContextWithFSM<O>.strictlyOn(handler: BehaviourWithFSMStateHandler<I, O>)

Add STRICT handler to list of available in future BehaviourContextWithFSM. Strict means that for input State will be used State::class == kClass and any State with exactly the same type will pass requirements