Package-level declarations

Types

Link copied to clipboard

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

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()) : 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()): DefaultBehaviourContext
inline fun <T> BehaviourContext(bot: TelegramBot, scope: CoroutineScope, flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), triggersHolder: TriggersHolder = TriggersHolder(), 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, 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, 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
fun <BC : BehaviourContext> BC.createSubContext(scope: CoroutineScope = LinkedSupervisorScope(), triggersHolder: TriggersHolder = this.triggersHolder, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow): BC

Creates new BehaviourContext using its BehaviourContext.copy method

Link copied to clipboard
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter(scope: CoroutineScope = LinkedSupervisorScope(), triggersHolder: TriggersHolder = this.triggersHolder, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, stopOnCompletion: Boolean = true, behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>): T

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

Link copied to clipboard
inline fun <BC, T> CustomBehaviourContextReceiver(noinline block: CustomBehaviourContextReceiver<BC, T>): suspend BC.() -> T
Link copied to clipboard
suspend fun <T, BC : BehaviourContext> BC.doInContext(stopOnCompletion: Boolean = false, behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>): T
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, 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, 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>