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

BehaviourContextAndTwoTypesReceiver
Link copied to clipboard
common
typealias BehaviourContextAndTwoTypesReceiver<T, I1, I2> = suspend BehaviourContext.(I1, I2) -> T
BehaviourContextAndTypeReceiver
Link copied to clipboard
common
typealias BehaviourContextAndTypeReceiver<T, I> = suspend BehaviourContext.(I) -> T
BehaviourContextReceiver
Link copied to clipboard
common
typealias BehaviourContextReceiver<T> = suspend BehaviourContext.() -> T
DefaultBehaviourContext
Link copied to clipboard
common
class DefaultBehaviourContext(bot: TelegramBot, scope: CoroutineScope, flowsUpdatesFilter: FlowsUpdatesFilter) : FlowsUpdatesFilter, RequestsExecutor, CoroutineScope, BehaviourContext

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

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.

doInSubContext
Link copied to clipboard
common
suspend fun <T> BehaviourContext.doInSubContext(stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver<T>): T
common
suspend fun <T> BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup(newFlowsUpdatesFilterSetUp: BehaviourContextAndTypeReceiver<Unit, FlowsUpdatesFilter>?, stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver<T>): T

Creates new one BehaviourContext, adding subsequent FlowsUpdatesFilter in case newFlowsUpdatesFilterSetUp is provided and CoroutineScope as new BehaviourContext.scope. You must do all subscription/running of longPolling manually.

doInSubContextWithUpdatesFilter
Link copied to clipboard
common
suspend fun <T> BehaviourContext.doInSubContextWithUpdatesFilter(updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?, stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver<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, 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 buildBehaviour. Use this method in case you wish to make some additional actions with flowsUpdatesFilter.

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.

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