Skip to content

Commit

Permalink
update tgbotapi and include sample of context data in custom bot
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Nov 29, 2024
1 parent f03ba5f commit 59fca96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CustomBot/src/main/kotlin/CustomBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 59fca96

Please sign in to comment.