Kotlin Telegram Bot 0.10.3 Help

Static chains

Entry point will be command, callback, reaction etc.:

fun BotHandling.startHandler() { command("/start") { sendMessage("Enter your name") } }

Then it is very simply add the next step of the chain using parameter next = and method step():

fun BotHandling.startCommand() { command("/start", next = "get_name") { sendMessage("Enter your name") } step("get_name") { sendMessage("Hello, $text!") } }

This way we can make chains of any length:

fun BotHandling.startCommand() { command("/start", next = "get_name") { sendMessage("Please enter your name") } step("get_name", next = "get_age") { sendMessage("Hello, $text!") sendMessage("Please enter your age") } step("get_age") { val age = text.toIntOrNull() ?: throw ChatException("An integer is expected") sendMessage("$age years - recorded") } }
Last modified: 07 September 2024