Repository navigation
EN Pagination
Русский: RU-Pagination
navigation.Pager builds a cross-platform inline keyboard and can own both opening a page and handling its callbacks.
pager := navigation.NewPager("inventory", 5, func(ctx *botctx.Context, page int) (string, error) {
return fmt.Sprintf("Inventory: page %d", page), nil
})
app.Command("inventory", func(ctx *botctx.Context) error {
return pager.Open(ctx, 1)
})
app.Callback(pager.Pattern(), pager.Handle)-
Openclamps the page, invokes the renderer, and sends the page. -
Patternreturns thenamespace.*callback pattern. -
Handleacknowledges the callback, checks ownership, renders the target page, and callsctx.Edit. - If an adapter cannot edit the message, the shared Context falls back to sending a new message.
- The
current/totalbutton usesnoopand only acknowledges the callback.
Every button is created through the shared keyboard.Builder, so callback payloads use each adapter's normal encoding path.
pager.ShowEdges = trueShowEdges adds first/last controls next to previous/next. Duplicate targets are omitted on the second and penultimate pages.
Open stores Event.UserID in every button payload. Handle does not mutate the message when another user presses a button or the owner is missing. Create the initial pager keyboard through Open instead of hand-writing its payload.
The same Pager uses the shared ctx.Edit path:
- Telegram — callback data and Bot API editing;
- VK — JSON payload and message editing;
- Discord — compact
CustomIDand component interaction update/edit.
Adapter tests cover the namespace/page/owner payload round trip on all three platforms. This proves synthetic mapping, while real-client behavior still requires live smoke testing.
The renderer receives the current Context, so page text can use the same request locale:
pager := navigation.NewPager("inventory", 5, func(ctx *botctx.Context, page int) (string, error) {
return ctx.T("inventory.page", i18n.Args{"page": page})
})Build localized custom button labels with keyboard.Builder. See Localization.
Pager{...}.Keyboard(), Clamp(), and ParsePage(...) remain compatible for manual flows. Prefer Open + Handle when the pager owns its callback lifecycle.