1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-03 00:15:27 +00:00
tgbotapi/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt

54 lines
1.6 KiB
Kotlin
Raw Normal View History

package dev.inmo.tgbotapi.extensions.behaviour_builder
2021-01-06 17:06:48 +00:00
import dev.inmo.tgbotapi.bot.TelegramBot
2021-01-06 17:21:33 +00:00
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
2021-01-06 17:06:48 +00:00
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.PreviewFeature
2021-01-06 17:06:48 +00:00
import kotlinx.coroutines.CoroutineScope
/**
* Use this method in case you wish to make some additional actions with [flowUpdatesFilter].
*
* **WARNING** This method WILL NOT launch any listening of updates. Use something like
* [startGettingOfUpdatesByLongPolling] or tools for work with webhooks
*
* @see [BehaviourContext]
* @see startGettingOfUpdatesByLongPolling
*/
@PreviewFeature
2021-01-07 12:11:01 +00:00
suspend fun TelegramBot.buildBehaviour(
2021-01-06 17:06:48 +00:00
scope: CoroutineScope,
2021-01-06 17:21:33 +00:00
flowUpdatesFilter: FlowsUpdatesFilter,
2021-01-07 12:11:01 +00:00
block: BehaviourContextReceiver<Unit>
2021-01-06 17:06:48 +00:00
) {
2021-01-07 12:11:01 +00:00
BehaviourContext(
2021-01-06 17:06:48 +00:00
this,
2021-01-06 17:21:33 +00:00
scope,
flowUpdatesFilter
2021-01-06 17:06:48 +00:00
).block()
}
2021-01-06 17:21:33 +00:00
/**
* 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.
*
* @see buildBehaviour
* @see BehaviourContext
* @see startGettingOfUpdatesByLongPolling
*/
@PreviewFeature
2021-01-07 12:11:01 +00:00
suspend fun TelegramBot.buildBehaviour(
2021-01-06 17:21:33 +00:00
scope: CoroutineScope,
2021-01-07 12:11:01 +00:00
block: BehaviourContextReceiver<Unit>
) = FlowsUpdatesFilter().let {
2021-01-07 12:11:01 +00:00
buildBehaviour(
2021-01-06 17:21:33 +00:00
scope,
it,
block
)
startGettingOfUpdatesByLongPolling(
updatesFilter = it,
scope = scope
)
}