Package-level declarations

Types

Link copied to clipboard
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

Link copied to clipboard
fun interface BehaviourWithFSMStateHandler<I : O, O : State> : StatesHandler<I, O>
Link copied to clipboard
class BehaviourWithFSMStateHandlerHolder<I : O, O : State>(inputKlass: KClass<I>, strict: Boolean = false, delegateTo: BehaviourWithFSMStateHandler<I, O>) : CheckableHandlerHolder<O, O> , BehaviourWithFSMStateHandler<O, O>

Special holder for BehaviourContextWithFSM. This holder helps BehaviourContextWithFSM to understand whether it can handle input State with delegateTo or not

Link copied to clipboard
class DefaultBehaviourContextWithFSM<T : State>(behaviourContext: BehaviourContext, statesManager: StatesManager<T>, handlers: List<BehaviourWithFSMStateHandlerHolder<*, T>>, fallbackHandler: BehaviourWithFSMStateHandlerHolder<T, T>? = null, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler()) : BehaviourContext, BehaviourContextWithFSM<T>

Default realization of BehaviourContextWithFSM. It uses behaviourContext as a base for this object as BehaviourContext, but managing substates contexts updates for avoiding of updates lost between states

Functions

Link copied to clipboard
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(), 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(), 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, 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, 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

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
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

Link copied to clipboard
suspend fun <T : State> telegramBotWithBehaviourAndFSM(token: String, flowsUpdatesFilter: FlowsUpdatesFilter, scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), fallbackHandler: BehaviourWithFSMStateHandlerHolder<T, T>? = null, testServer: Boolean = false, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), timeoutSeconds: Seconds = 30, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000, block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>): TelegramBot

Create bot using telegramBot and start listening for updates using buildBehaviourWithFSM. Use this method in case you wish to make some additional actions with flowsUpdatesFilter.

suspend fun <T : State> telegramBotWithBehaviourAndFSMAndStartLongPolling(token: String, scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), fallbackHandler: BehaviourWithFSMStateHandlerHolder<T, T>? = null, testServer: Boolean = false, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), timeoutSeconds: Seconds = 30, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000, block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>): Pair<TelegramBot, Job>

Create bot using telegramBot and start listening for updates using buildBehaviourWithFSMAndStartLongPolling. This method will launch updates retrieving via long polling inside of buildBehaviourWithFSMAndStartLongPolling