Package-level declarations

Types

Link copied to clipboard

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

Link copied to clipboard
data class BehaviourContextData(data: MutableMap<String, Any?> = mutableMapOf()) : MutableMap<String, Any?>
Link copied to clipboard
class CombinedSubcontextInitialAction(val subactions: List<CombinedSubcontextInitialAction.SubAction>, logger: KSLog = KSLog("CombinedSubcontextInitialAction_${subactions.size}"))

Contains SubActions which will be used in subcontextInitialAction in order they has been passed in subactions.

typealias CustomBehaviourContextAndTwoTypesReceiver<BC, T, I1, I2> = suspend BC.(I1, I2) -> T
Link copied to clipboard
typealias CustomBehaviourContextAndTypeReceiver<BC, T, I> = suspend BC.(I) -> T
Link copied to clipboard
typealias CustomBehaviourContextReceiver<BC, T> = suspend BC.() -> T
Link copied to clipboard
class DefaultBehaviourContext(val bot: TelegramBot, val scope: CoroutineScope, broadcastChannelsSize: Int = 100, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, upstreamUpdatesFlow: Flow<Update>? = null, val triggersHolder: TriggersHolder = TriggersHolder(), val subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}) : AbstractFlowsUpdatesFilter, RequestsExecutor, CoroutineScope, BehaviourContext

Properties

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

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

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

Functions

Link copied to clipboard
inline fun <T> Deferred<T>.asAction(): DeferredAction<T, T>
Link copied to clipboard
fun BehaviourContext(bot: TelegramBot, scope: CoroutineScope, flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), triggersHolder: TriggersHolder = TriggersHolder(), subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}): DefaultBehaviourContext
inline fun <T> BehaviourContext(bot: TelegramBot, scope: CoroutineScope, flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), triggersHolder: TriggersHolder = TriggersHolder(), noinline subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, crossinline block: BehaviourContext.() -> T): T
Link copied to clipboard
Link copied to clipboard
inline fun <T> BehaviourContextReceiver(noinline block: BehaviourContextReceiver<T>): suspend BehaviourContext.() -> T
Link copied to clipboard
suspend fun TelegramBot.buildBehaviour(flowUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, block: BehaviourContextReceiver<Unit>): BehaviourContext

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

Link copied to clipboard
suspend fun TelegramBot.buildBehaviourWithLongPolling(scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler<Unit>? = null, timeoutSeconds: Seconds = 30, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, 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.

Link copied to clipboard
Link copied to clipboard
fun <BC : BehaviourContext> BC.createSubContext(scope: CoroutineScope = LinkedSupervisorScope(), triggersHolder: TriggersHolder = this.triggersHolder, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = this.subcontextInitialAction): BC

Creates new BehaviourContext using its BehaviourContext.copy method

suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoAsynchronouslyWithUpdatesFilter(triggersHolder: TriggersHolder = this.triggersHolder, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, additionalSubcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update>? = null, behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>): Deferred<T>

Uses createSubContextAndDoSynchronouslyWithUpdatesFilter, but wrapping it in async. That means, that execution of this function will be asynchronous and will not block execution of code by default

suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoSynchronouslyWithUpdatesFilter(triggersHolder: TriggersHolder = this.triggersHolder, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, additionalSubcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update>? = null, behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>): T

Creates new one BehaviourContext using createSubContext and launches behaviourContextReceiver in a new context using doInContext.

Link copied to clipboard
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter(triggersHolder: TriggersHolder = this.triggersHolder, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, additionalSubcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update>? = null, behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>): Deferred<T>

It is just backward compatibility function which will be removed in next updates.

Link copied to clipboard
inline fun <BC, T> CustomBehaviourContextReceiver(noinline block: CustomBehaviourContextReceiver<BC, T>): suspend BC.() -> T
Link copied to clipboard
Link copied to clipboard
suspend fun <O> BehaviourContext.oneOf(vararg deferredActions: Deferred<O>): O
suspend fun <O> BehaviourContext.oneOf(deferredActions: Iterable<Deferred<O>>): O
Link copied to clipboard
suspend fun <O> BehaviourContext.oneOfActions(vararg deferredActions: DeferredAction<*, O>): O
suspend fun <O> BehaviourContext.oneOfActions(deferredActions: Iterable<DeferredAction<*, O>>): O
Link copied to clipboard
suspend fun <T> BehaviourContext.parallel(action: BehaviourContextReceiver<T>): Deferred<T>
Link copied to clipboard

This method will cancel ALL subsequent contexts, expectations and waiters

Link copied to clipboard
suspend fun telegramBotWithBehaviour(token: String, flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, testServer: Boolean = false, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, 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.

Link copied to clipboard
suspend fun telegramBotWithBehaviourAndLongPolling(token: String, scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, defaultExceptionsHandler: ExceptionHandler<Unit>? = null, testServer: Boolean = false, timeoutSeconds: Seconds = 30, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = {}, 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.

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