Files
go-telegram/examples/pagination
lukaszraczyloandGitHub cec37b7b95 chore(api): regenerate for BotFullInfo and optional chat_id (#53)
* chore(api): regenerate for BotFullInfo and optional chat_id

Telegram split BotFullInfo out of User and getMe now returns it, and
chat_id is optional in the methods that accept an ephemeral callback
reply. Regenerate the API, make MeCache cache BotFullInfo, and wrap the
now-optional chat_id arguments in the examples. This is the output of
make regen, so the weekly regen job no longer fails its api test.

* chore(api): pin the 2026-11-29 API snapshot the regen used

codegen-clean regenerates from testdata/html/latest.html, so the new
BotFullInfo output needs a matching snapshot.
2026-11-29 04:42:42 +00:00
..
2026-05-09 13:09:27 +01:00

pagination

Multi-page inline keyboard for browsing a list. No server-side session required — page state is encoded in callback data.

What it shows

  • OnCommand("/list") sends the first page with inline navigation buttons
  • OnCallback("^page:(\\d+)$") parses page number from callback data via c.Values["regex_match"]
  • api.EditMessageText edits the message in-place on each page turn
  • api.AnswerCallbackQuery dismisses the loading spinner

Pattern

Callback data format: page:<n> where n is the 0-based page index.

The renderPage helper builds both the text content and the keyboard in one call. Only [« Prev] or [Next »] buttons that make sense for the current page are rendered, so the keyboard is always minimal.

Running

export TELEGRAM_BOT_TOKEN=123456:ABC...
go run ./examples/pagination

Send /list to the bot. Tap Next/Prev to navigate 20 sample items, 5 per page.

Extending

To paginate dynamic data (database results, API responses), replace sampleItems with a function that takes (page, pageSize) and returns items + total count.