mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-09-21 16:09:28 +00:00
update examples for ktgbotapi 37.0.0
This commit is contained in:
@@ -57,7 +57,11 @@ fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) {
|
||||
val numbersRange = 1 .. count
|
||||
numericButtons.forEach {
|
||||
if (it in numbersRange) {
|
||||
dataButton(it.toString(), "$it $count")
|
||||
if (it == page) {
|
||||
disabledButton(it.toString(), style = KeyboardButtonStyle.Primary)
|
||||
} else {
|
||||
dataButton(it.toString(), "$it $count")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,7 +121,7 @@ suspend fun activateKeyboardsBot(
|
||||
val page = numberArgs.firstOrNull()?.takeIf { numberArgs.size > 1 }?.coerceAtLeast(1) ?: 1
|
||||
reply(
|
||||
message,
|
||||
replyMarkup = inlineKeyboard {
|
||||
replyMarkup = inlineKeyboard(forceReply = true) {
|
||||
includePageButtons(page, numberOfPages)
|
||||
}
|
||||
) {
|
||||
@@ -136,7 +140,7 @@ suspend fun activateKeyboardsBot(
|
||||
answer(it, "Unsupported message type :(")
|
||||
return@onMessageDataCallbackQuery
|
||||
},
|
||||
replyMarkup = inlineKeyboard {
|
||||
replyMarkup = inlineKeyboard(forceReply = true) {
|
||||
includePageButtons(page, count)
|
||||
}
|
||||
) {
|
||||
@@ -152,7 +156,7 @@ suspend fun activateKeyboardsBot(
|
||||
|
||||
editMessageText(
|
||||
it.inlineMessageId,
|
||||
replyMarkup = inlineKeyboard {
|
||||
replyMarkup = inlineKeyboard(forceReply = true) {
|
||||
includePageButtons(page, count)
|
||||
}
|
||||
) {
|
||||
@@ -173,7 +177,7 @@ suspend fun activateKeyboardsBot(
|
||||
InlineQueryId(it.query),
|
||||
"Send buttons",
|
||||
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
||||
replyMarkup = inlineKeyboard {
|
||||
replyMarkup = inlineKeyboard(forceReply = true) {
|
||||
includePageButtons(page, count)
|
||||
}
|
||||
)
|
||||
@@ -184,7 +188,11 @@ suspend fun activateKeyboardsBot(
|
||||
onUnhandledCommand {
|
||||
reply(
|
||||
it,
|
||||
replyMarkup = replyKeyboard(resizeKeyboard = true, oneTimeKeyboard = true) {
|
||||
replyMarkup = replyKeyboard(
|
||||
resizeKeyboard = true,
|
||||
oneTimeKeyboard = true,
|
||||
forceReply = true,
|
||||
) {
|
||||
row {
|
||||
simpleButton("/inline", style = KeyboardButtonStyle.Primary)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# KeyboardsBot
|
||||
|
||||
A multiplatform long-polling example that demonstrates Telegram reply keyboards, inline keyboards, callback queries, copy-text buttons, inline-mode buttons, and keyboard button styles. The shared bot behavior lives in `KeyboardsBotLib`; the project provides a browser/JS entry point and a separate JVM launcher.
|
||||
A multiplatform long-polling example that demonstrates Telegram reply keyboards, inline keyboards, callback queries, copy-text buttons, inline-mode buttons, keyboard button styles, disabled buttons, and forced reply interfaces. The shared bot behavior lives in `KeyboardsBotLib`; the project provides a browser/JS entry point and a separate JVM launcher.
|
||||
|
||||
## Bot behavior
|
||||
|
||||
@@ -16,16 +16,16 @@ At startup, the bot calls `getMe`, reports the returned bot information through
|
||||
|
||||
Only numeric command arguments are considered. Use positive integers with `page <= count`; the example does not validate the count or clamp the page to the upper bound.
|
||||
|
||||
The generated inline keyboard contains:
|
||||
The generated inline keyboard sets Bot API 10.3's `force_reply` field and contains:
|
||||
|
||||
- numbered buttons for the current page and any adjacent pages that are within `1..count`;
|
||||
- a disabled button for the current page and callback buttons for adjacent pages within `1..count`;
|
||||
- styled jump buttons for moving toward the first or last page when applicable;
|
||||
- a **Command copy button** that copies `/inline <page> <count>`;
|
||||
- a **Send somebody page** button that starts inline mode and lets the user choose a user, bot, group, or channel.
|
||||
|
||||
Pagination callbacks edit the original message and replace its text with `This is <page> of <count>`. This works for both ordinary bot messages and messages sent through inline mode. Unsupported callback data or an unsupported message type is answered with a callback notification instead.
|
||||
|
||||
Any command not handled above, including `/start`, receives a one-time reply keyboard containing a styled `/inline` button. Ordinary non-command messages are ignored.
|
||||
Any command not handled above, including `/start`, receives a one-time reply keyboard containing a styled `/inline` button. That reply keyboard also sets `force_reply`, demonstrating the field on both markup types. Ordinary non-command messages are ignored.
|
||||
|
||||
### Inline mode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user