join To Inline Keyboard
fun <T> Collection<T>.joinToInlineKeyboard(nameSelector: T.() -> String, callbackSelector: T.() -> String, paginationCallbackPattern: String, currentPage: Int = 1, perPage: Int = 5, perLine: Int = 1): InlineKeyboardMarkup
Helper function to paginate over a collection.
Return
InlineKeyboardMarkup.
Example of Usage:
@CommandHandler(["/start"])
suspend fun start(bot: TelegramBot, user: User) {
message("Hello").markup(
elements.joinToInlineKeyboard(
{ "button $name" },
{ "selector?id=$id" },
"/start?page=%P",
)
).sendAsync(user, bot).getOrNull()?.also {
bot.userData[user, "startPage"] = it.messageId
}
}
@CommandHandler.CallbackQuery(["/start"])
suspend fun paginator(bot: TelegramBot, user: User, page: Int) {
editMarkup(
bot.userData.get<Long>(user.id, "startPage")!!
).markup(
elements.joinToInlineKeyboard(
{ "button $name" },
{ "selector?id=$id" },
"/start?page=%P",
currentPage = page
)
).send(user, bot)
}
Content copied to clipboard
Parameters
T
generic for paginating data.
name Selector
selector for button name.
callback Selector
selector for callback data.
pagination Callback Pattern
pattern that will be used for pagination buttons. ex: /start?page=%P
where %P
will be replaced with page number.
current Page
current page
per Page
elements per page.
per Line
elements per line.