Kotlin Telegram Bot 0.10.3 Help

Update handling

If you need to handle more updates than are available in the Message chains, you can receive any updates in easy way.

com/example/myproject/handler/update/SomeUpdateHandler.kt

@HandlerComponent class SomeUpdateHandler : BotUpdateHandler({ val logger = LoggerFactory.getLogger(javaClass) // for example handle any message message { logger.info("Received message text: $text") } // for example handle any inline query inlineQuery { logger.info("Received query: $query") bot.answerInlineQuery(inlineQueryId = id, results = listOf()) } })

com/example/myproject/handler/update/SomeUpdateHandler.kt

@Factory class SomeUpdateHandler : BotUpdateHandler({ val logger = LoggerFactory.getLogger(javaClass) // for example handle any message message { logger.info("Received message text: $text") } // for example handle any inline query inlineQuery { logger.info("Received query: $query") bot.answerInlineQuery(inlineQueryId = id, results = listOf()) } })

com/example/myproject/handling/update/SomeUpdateHandler.kt

fun BotUpdateHandling.onSomeEvent() { val logger = LoggerFactory.getLogger("io.github.dehuckakpyt.telegrambotexample.handling.update.BotEventHandling.onSomeEvent") // for example handle any message message { logger.info("Received message text: $text") } // for example handle any inline query inlineQuery { logger.info("Received query: $query") bot.answerInlineQuery(inlineQueryId = id, results = listOf()) } }

First BotUpdateHandling is invoked, then BotHandling is invoked. You can set the next step in update if you really want to (use it carefully). Also, you can use templating and button factory.

com/example/myproject/handler/update/SomeUpdateHandler.kt

@HandlerComponent class SomeUpdateHandler : BotUpdateHandler({ val template = "some \${arg}" preCheckoutQuery { bot.answerPreCheckoutQuery(preCheckoutQueryId = id, ok = true) bot.sendMessage(123L, template with ("arg" to 321)) // and you can set next step for specified user (or chat and user) next(userId = from.id, step = "test") } })

com/example/myproject/handler/update/SomeUpdateHandler.kt

@Factory class SomeUpdateHandler : BotUpdateHandler({ val template = "some \${arg}" preCheckoutQuery { bot.answerPreCheckoutQuery(preCheckoutQueryId = id, ok = true) bot.sendMessage(123L, template with ("arg" to 321)) // and you can set next step for specified user (or chat and user) next(userId = from.id, step = "test") } })

com/example/myproject/handling/update/SomeUpdateHandler.kt

fun BotUpdateHandling.onSomeEvent() { val template = "some \${arg}" preCheckoutQuery { bot.answerPreCheckoutQuery(preCheckoutQueryId = id, ok = true) bot.sendMessage(123L, template with ("arg" to 321)) // and you can set next step for specified user (or chat and user) next(userId = from.id, step = "test") } }
Last modified: 07 September 2024