From 59fca968d7799565dfe44462469277122115b2c1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Nov 2024 12:50:33 +0600 Subject: [PATCH] update tgbotapi and include sample of context data in custom bot --- CustomBot/src/main/kotlin/CustomBot.kt | 13 +++++++++++++ gradle.properties | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CustomBot/src/main/kotlin/CustomBot.kt b/CustomBot/src/main/kotlin/CustomBot.kt index 3c19749..ad4453c 100644 --- a/CustomBot/src/main/kotlin/CustomBot.kt +++ b/CustomBot/src/main/kotlin/CustomBot.kt @@ -4,10 +4,16 @@ import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.setDefaultKSLog import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.api.bot.getMe +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextData import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +private var BehaviourContextData.update + get() = get("update") + set(value) = set("update", value) + /** * This place can be the playground for your code. */ @@ -38,12 +44,19 @@ suspend fun main(vararg args: String) { } } } + }, + subcontextInitialAction = { + data.update = it } ) { // start here!! val me = getMe() println(me) + onCommand("start") { + println(data.update) + } + allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) } diff --git a/gradle.properties b/gradle.properties index 14812d2..905b493 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m kotlin_version=2.0.21 -telegram_bot_api_version=20.0.1 +telegram_bot_api_version=20.1.0 micro_utils_version=0.23.0 serialization_version=1.7.3 ktor_version=3.0.1