Skip to content

Commit 59fca96

Browse files
update tgbotapi and include sample of context data in custom bot
1 parent f03ba5f commit 59fca96

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

CustomBot/src/main/kotlin/CustomBot.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ import dev.inmo.kslog.common.defaultMessageFormatter
44
import dev.inmo.kslog.common.setDefaultKSLog
55
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
66
import dev.inmo.tgbotapi.extensions.api.bot.getMe
7+
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextData
78
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
9+
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
810
import kotlinx.coroutines.CoroutineScope
911
import kotlinx.coroutines.Dispatchers
1012

13+
private var BehaviourContextData.update
14+
get() = get("update")
15+
set(value) = set("update", value)
16+
1117
/**
1218
* This place can be the playground for your code.
1319
*/
@@ -38,12 +44,19 @@ suspend fun main(vararg args: String) {
3844
}
3945
}
4046
}
47+
},
48+
subcontextInitialAction = {
49+
data.update = it
4150
}
4251
) {
4352
// start here!!
4453
val me = getMe()
4554
println(me)
4655

56+
onCommand("start") {
57+
println(data.update)
58+
}
59+
4760
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
4861
println(it)
4962
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m
66

77

88
kotlin_version=2.0.21
9-
telegram_bot_api_version=20.0.1
9+
telegram_bot_api_version=20.1.0
1010
micro_utils_version=0.23.0
1111
serialization_version=1.7.3
1212
ktor_version=3.0.1

0 commit comments

Comments
 (0)