tgbotapi.keyboards
0.0.4indexedEnhances Telegram Bots API keyboards with a special DSL, enabling structured menu initialization and request handling for efficient bot interaction management.
0
Stars
—
Used by
dependents
—
Health
/ 100
Enhances Telegram Bots API keyboards with a special DSL, enabling structured menu initialization and request handling for efficient bot interaction management.
This library provides special DSL for Telegram Bots API keyboards.
Gradle Groovy:
implementation "dev.inmo:tgbotapi.keyboards.lib:$version"
Gradle Kotlin:
implementation("dev.inmo:tgbotapi.keyboards.lib:$version")
Maven:
<dependency>
<groupId>dev.inmo</groupId>
<artifactId>tgbotapi.keyboards.lib</artifactId>
<version>$version</version>
</dependency>
As you may see, there are two phases in common case:
So, we have menu and now we may setup it in bot:
val bot = telegramBot("YOUR TOKEN")
bot.buildBehaviourWithLongPolling {
setupMenuTriggers(menu) // setting up listening of buttons clicking
}
val menu = buildMenu rootMenu@{
row {
dataWithsubMenu(
id = "sample", // id for button to be used in current menu
text = "Sample", // text for button
callbacksRegex = Regex("sample") // optional regex for all callbacks to be registered in the future
) { // callback for builder, here `it` is `DataCallbackQuery?`, where null-value means initial setup
row {
dataWithOptionalSubMenu(
id = "back", // id for button to be used in current menu
text = "Back", // text for button
callbacksRegex = Regex("back") // optional regex for all callbacks to be registered in the future
) {
if (it != null) { // when real request
this@rootMenu.buildLazy()
} else { // when initial call
null
}
}
}
}
}
}
Surfaced from shared tags and platforms — no rankings paid for.