Package dev.inmo.tgbotapi.extensions.behaviour_builder

Types

BehaviourContext
Link copied to clipboard
common
interface BehaviourContext : FlowsUpdatesFilter, RequestsExecutor, CoroutineScope

This class contains all necessary tools for work with bots and especially for buildBehaviour

BehaviourContextAndTypeReceiver
Link copied to clipboard
common
BehaviourContextReceiver
Link copied to clipboard
common
BehaviourContextWithFSM
Link copied to clipboard
common
interface BehaviourContextWithFSM : BehaviourContext, StatesMachine

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

BehaviourContextWithFSMBuilder
Link copied to clipboard
common
class BehaviourContextWithFSMBuilder : BehaviourContextWithFSM
BehaviourWithFSMStateHandler
Link copied to clipboard
common
fun interface BehaviourWithFSMStateHandler<T : State>
BehaviourWithFSMStateHandlerHolder
Link copied to clipboard
common
class BehaviourWithFSMStateHandlerHolder<I : State>(inputKlass: KClass<I>, strict: Boolean, delegateTo: BehaviourWithFSMStateHandler<I>)

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

common
typealias CustomBehaviourContextAndTwoTypesReceiver<BC, T, I1, I2> = suspend BC.(I1, I2) -> T
CustomBehaviourContextAndTypeReceiver
Link copied to clipboard
common
typealias CustomBehaviourContextAndTypeReceiver<BC, T, I> = suspend BC.(I) -> T
CustomBehaviourContextReceiver
Link copied to clipboard
common
typealias CustomBehaviourContextReceiver<BC, T> = suspend BC.() -> T
DefaultBehaviourContext
Link copied to clipboard
common
class DefaultBehaviourContext(bot: TelegramBot, scope: CoroutineScope, broadcastChannelsSize: Int, onBufferOverflow: BufferOverflow, upstreamUpdatesFlow: Flow<Update>?, updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?) : AbstractFlowsUpdatesFilter, RequestsExecutor, CoroutineScope, BehaviourContext
DefaultBehaviourContextWithFSM
Link copied to clipboard
common
class DefaultBehaviourContextWithFSM(behaviourContext: BehaviourContext, statesManager: StatesManager, handlers: List<BehaviourWithFSMStateHandlerHolder<*>>) : BehaviourContext, BehaviourContextWithFSM

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

asAction
Link copied to clipboard
common
inline fun <T> Deferred<T>.asAction(): DeferredAction<T, T>
BehaviourContext
Link copied to clipboard
common
fun BehaviourContext(bot: TelegramBot, scope: CoroutineScope, flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter()): DefaultBehaviourContext
inline fun <T> BehaviourContext(bot: TelegramBot, scope: CoroutineScope, flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), crossinline block: BehaviourContext.() -> T): T
BehaviourContextAndTwoTypesReceiver
Link copied to clipboard
common
inline fun <T, I1, I2> BehaviourContextAndTwoTypesReceiver(noinline block: BehaviourContextAndTwoTypesReceiver<T, I1, I2>): suspend BehaviourContext.(I1, I2) -> T
BehaviourContextAndTypeReceiver
Link copied to clipboard
common
inline fun <T, I> BehaviourContextAndTypeReceiver(noinline block: BehaviourContextAndTypeReceiver<T, I>): suspend BehaviourContext.(I) -> T
BehaviourContextReceiver
Link copied to clipboard
common
inline fun <T> BehaviourContextReceiver(noinline block: BehaviourContextReceiver<T>): suspend BehaviourContext.() -> T
buildBehaviour
Link copied to clipboard
common
suspend fun TelegramBot.buildBehaviour(flowUpdatesFilter: FlowsUpdatesFilter, scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, block: BehaviourContextReceiver<Unit>)

Use this method in case you wish to make some additional actions with flowUpdatesFilter.

buildBehaviourWithFSM
Link copied to clipboard
common
suspend fun TelegramBot.buildBehaviourWithFSM(flowUpdatesFilter: FlowsUpdatesFilter, scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(), block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>): BehaviourContextWithFSM

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 TelegramBot.buildBehaviourWithFSM(upstreamUpdatesFlow: Flow<Update>? = null, scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(), block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>): BehaviourContextWithFSM

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.

common
suspend fun TelegramBot.buildBehaviourWithFSMAndStartLongPolling(scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(), block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>): Job
suspend fun TelegramBot.buildBehaviourWithFSMAndStartLongPolling(upstreamUpdatesFlow: Flow<Update>? = null, scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(), block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>): Pair<BehaviourContextWithFSM, 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

buildBehaviourWithLongPolling
Link copied to clipboard
common
suspend fun TelegramBot.buildBehaviourWithLongPolling(scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, block: BehaviourContextReceiver<Unit>): Job

Use this method to build bot behaviour and run it via long polling. In case you wish to get FlowsUpdatesFilter for additional manipulations, you must provide external FlowsUpdatesFilter in other buildBehaviour function.

CustomBehaviourContextReceiver
Link copied to clipboard
common
inline fun <BC, T> CustomBehaviourContextReceiver(noinline block: CustomBehaviourContextReceiver<BC, T>): suspend BC.() -> T
doInSubContext
Link copied to clipboard
common
suspend fun <T> BehaviourContext.doInSubContext(stopOnCompletion: Boolean = true, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, scope: CoroutineScope = LinkedSupervisorScope(), behaviourContextReceiver: BehaviourContextReceiver<T>): T
doInSubContextWithUpdatesFilter
Link copied to clipboard
common
suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?, stopOnCompletion: Boolean = true, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, scope: CoroutineScope = LinkedSupervisorScope(), behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>): T

Creates new one BehaviourContext, adding subsequent FlowsUpdatesFilter in case updatesFilter is provided and CoroutineScope as new BehaviourContext.scope

oneOf
Link copied to clipboard
common
suspend fun <O> BehaviourContext.oneOf(vararg deferredActions: Deferred<O>): O
suspend fun <O> BehaviourContext.oneOf(deferredActions: Iterable<Deferred<O>>): O
oneOfActions
Link copied to clipboard
common
suspend fun <O> BehaviourContext.oneOfActions(vararg deferredActions: DeferredAction<*, O>): O
suspend fun <O> BehaviourContext.oneOfActions(deferredActions: Iterable<DeferredAction<*, O>>): O
parallel
Link copied to clipboard
common
suspend fun <T> BehaviourContext.parallel(action: BehaviourContextReceiver<T>): Deferred<T>
stop
Link copied to clipboard
common
fun BehaviourContext.stop()

This method will cancel ALL subsequent contexts, expectations and waiters

telegramBotWithBehaviour
Link copied to clipboard
common
suspend fun telegramBotWithBehaviour(token: String, flowsUpdatesFilter: FlowsUpdatesFilter, scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, block: BehaviourContextReceiver<Unit>): TelegramBot

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

telegramBotWithBehaviourAndFSM
Link copied to clipboard
common
suspend fun telegramBotWithBehaviourAndFSM(token: String, flowsUpdatesFilter: FlowsUpdatesFilter, scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(), block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, 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.

common
suspend fun telegramBotWithBehaviourAndFSMAndStartLongPolling(token: String, scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(), block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, 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

telegramBotWithBehaviourAndLongPolling
Link copied to clipboard
common
suspend fun telegramBotWithBehaviourAndLongPolling(token: String, scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, block: BehaviourContextReceiver<Unit>): Pair<TelegramBot, Job>

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

withAction
Link copied to clipboard
common
infix inline fun <T, O> Deferred<T>.withAction(noinline callback: suspend (T) -> O): DeferredAction<T, O>

Properties

defaultCoroutineScopeProvider
Link copied to clipboard
var defaultCoroutineScopeProvider: () -> CoroutineScope

This function is used in buildBehaviour extensions to provide default CoroutineScope and allow to avoid all unnecessary parameters except of block

var defaultCoroutineScopeProvider: () -> CoroutineScope
var defaultCoroutineScopeProvider: () -> CoroutineScope