mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-12-02 06:50:12 +00:00
upgrade custom bot to include context data and additional context data
This commit is contained in:
parent
59fca968d7
commit
c3ad2d4319
@ -5,15 +5,22 @@ import dev.inmo.kslog.common.setDefaultKSLog
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextData
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextData
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildSubcontextInitialAction
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
private var BehaviourContextData.update
|
private var BehaviourContextData.update: Update?
|
||||||
get() = get("update")
|
get() = get("update") as? Update
|
||||||
set(value) = set("update", value)
|
set(value) = set("update", value)
|
||||||
|
|
||||||
|
private var BehaviourContextData.commonMessage: CommonMessage<*>?
|
||||||
|
get() = get("commonMessage") as? CommonMessage<*>
|
||||||
|
set(value) = set("commonMessage", value)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This place can be the playground for your code.
|
* This place can be the playground for your code.
|
||||||
*/
|
*/
|
||||||
@ -45,8 +52,10 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subcontextInitialAction = {
|
subcontextInitialAction = buildSubcontextInitialAction {
|
||||||
data.update = it
|
add {
|
||||||
|
data.update = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
// start here!!
|
// start here!!
|
||||||
@ -55,6 +64,17 @@ suspend fun main(vararg args: String) {
|
|||||||
|
|
||||||
onCommand("start") {
|
onCommand("start") {
|
||||||
println(data.update)
|
println(data.update)
|
||||||
|
println(data.commonMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand(
|
||||||
|
"additional_command",
|
||||||
|
additionalSubcontextInitialAction = { update, commonMessage ->
|
||||||
|
data.commonMessage = commonMessage
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
println(data.update)
|
||||||
|
println(data.commonMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=2.0.21
|
kotlin_version=2.0.21
|
||||||
telegram_bot_api_version=20.1.0
|
telegram_bot_api_version=21.0.0
|
||||||
micro_utils_version=0.23.0
|
micro_utils_version=0.23.0
|
||||||
serialization_version=1.7.3
|
serialization_version=1.7.3
|
||||||
ktor_version=3.0.1
|
ktor_version=3.0.1
|
||||||
|
Loading…
Reference in New Issue
Block a user