Skip to content

v2.5.0

Latest

Choose a tag to compare

@kbgod kbgod released this 22 Nov 11:42
a7339c7

Telegram Bot API 10.5 support: bot settings from code (setMySettings), getMe returning the new BotFullInfo, callback queries addressed by inline_message_id, owner invite links and expandable quotations made of blocks — plus default request timeouts, UTF-16-safe entity parsing, a sub-router middleware fix, a generator rule that lets optional fields send false, "" and 0, and two new Claude Code skills (rich messages, Mini App authentication). lumex now requires Go 1.27. Module path: github.com/kbgod/lumex/v2.

The version is a proposal (v2.5.0). Unlike 10.4, this release has breaking changes: 10.5 moved the bot's own fields out of User and changed expandable quotations upstream, fourteen fields became pointers so that their zero value can be sent at all, and the minimum Go version is now 1.27. Each one has a migration below. Verified against v2.4.0: 193 → 194 methods with one signature changed (GetMe); one generated constructor changed (NewInputRichBlockExpandableBlockQuotation); Bot.User removed; ten fields removed from User, Text replaced by Blocks in the two expandable-quotation types, and fourteen fields retyped to pointers. Nothing else was removed or retyped.

⚠️ Breaking changes

1. getMe returns BotFullInfo, and Bot embeds it instead of User. 10.5 split the bot's own account out of User into a new BotFullInfo class and made getMe return it. lumex.Bot follows. Promoted fields are unaffected — bot.ID, bot.Username, bot.CanJoinGroups, … worked through the embedded User and keep working through BotFullInfo, joined by the new bot.ActiveUsernames, bot.HasTopicSidebar, …. What breaks is code that names the embedded field itself, plus what GetMe returns:

// v2.4.0
log.Println(bot.User.Username)                                     // the README and examples wrote this
me, err := bot.GetMe(ctx)                                          // *lumex.User
r := router.New(&lumex.Bot{User: lumex.User{Username: "my_bot"}}) // in tests

// v2.5.0
log.Println(bot.Username) // also fine in v2.4.0
me, err := bot.GetMe(ctx) // *lumex.BotFullInfo
r := router.New(&lumex.Bot{Username: "my_bot"}) // Go 1.27: a promoted field set directly

2. User lost the fields only getMe ever filled in: CanJoinGroups, CanReadAllGroupMessages, SupportsGuestQueries, SupportsInlineQueries, CanConnectToBusiness, HasMainWebApp, HasTopicsEnabled, AllowsUsersToCreateTopics, CanManageBots and SupportsJoinRequestQueries. They are on BotFullInfo — and therefore on bot — and were always false for any other user.

3. Expandable quotations hold blocks. RichBlockExpandableBlockQuotation.Text and InputRichBlockExpandableBlockQuotation.Text were replaced by Blocks, so a quotation can contain lists, tables or nested quotes. The constructor follows:

// v2.4.0
lumex.NewInputRichBlockExpandableBlockQuotation(lumex.PlainText("Long text…"))

// v2.5.0
lumex.NewInputRichBlockExpandableBlockQuotation([]lumex.InputRichBlock{
    lumex.NewInputRichBlockParagraph(lumex.PlainText("Long text…")),
})

4. Fields whose zero value means something are pointers. An optional field is tagged omitempty, which silently drops false and "". For most fields that is right, but for these the docs give the zero value its own meaning — so until now lumex could not, for example, send a non-anonymous poll (Telegram's default is anonymous), clear a widget's data, remove a forum topic's icon, or ask a request-users button for regular users only. They are now pointers: nil leaves the field out, new(value) (Go 1.26+) sends it, zero included.

Type Fields
SendPollOpts IsAnonymous, AllowsRevoting
PromoteChatMemberOpts CanRestrictMembers
EditMessageWidgetDataOpts PublicData, ChatData
EditForumTopicOpts IconCustomEmojiID
ChatPermissions CanReactToMessages, CanEditTag, CanManageTopics
KeyboardButtonRequestUsers UserIsBot, UserIsPremium
KeyboardButtonRequestChat ChatIsForum, ChatHasUsername
ForumTopicEdited (received) IconCustomEmojiID — "" means the icon was removed, nil that it wasn't edited
// v2.4.0 — false was dropped, so the poll came out anonymous
bot.SendPoll(ctx, chatID, "Lunch?", options, lumex.SendPollOpts{IsAnonymous: false})

// v2.5.0
bot.SendPoll(ctx, chatID, "Lunch?", options, lumex.SendPollOpts{IsAnonymous: new(false)})
ctx.EditWidgetData(lumex.EditMessageWidgetDataOpts{ChatData: new(state)}) // new("") clears it

5. Go 1.27 is required. go.mod now says go 1.27. go get raises your module's go line to match; with the default GOTOOLCHAIN=auto the go command fetches a 1.27 toolchain by itself, otherwise install Go 1.27.

🐹 Go 1.27

Besides the requirement, 1.27 lets a composite literal set promoted fields directly, which suits lumex's embedding-heavy types:

// A field of the embedded BotFullInfo — handy in tests:
r := router.New(&lumex.Bot{Username: "my_bot", ID: 42})

// A request with its embedded XxxOpts in one literal (e.g. for lumex.Call):
req := lumex.SendPhotoRequest{ChatID: chatID, Photo: photo, Caption: "hi", MessageThreadID: 5}

Before 1.27 these needed the nested form (lumex.Bot{BotFullInfo: lumex.BotFullInfo{…}}, SendPhotoRequest{…, SendPhotoOpts: lumex.SendPhotoOpts{…}}) or assignments after the literal. The code base itself was brought up to date with go fix (promoted-field literals in menu.go / richmessage.go, atomic.Int32 in tests).

✨ Added

🤖 Bot API 10.5 surface (generated)

Bot settings

  • New method setMySettings — bot.SetMySettings(ctx, lumex.SetMySettingsOpts{…}) with all fifteen parameters: inline mode (SupportsInlineQueries, InlineQueryPlaceholder, NeedsInlineQueryLocation, InlineFeedbackShareDenominator), privacy mode (CanReadAllGroupMessages), joining groups (CanJoinGroups), guest and join request queries, business accounts, managing and talking to other bots, forum topic mode in private chats (HasTopicsEnabled, AllowsUsersToCreateTopics, HasTopicSidebar) and CallbackQueryMode. Settings left out stay unchanged, which is why every field is a pointer: new(false) switches a setting off, new("") restores the default placeholder, new(int64(0)) stops chosen inline results.
  • New enum SetMySettingsCallbackQueryMode (…Default, …Auto, …Inline).
  • New BotFullInfo type, returned by getMe, with the new ActiveUsernames, InlineQueryPlaceholder, NeedsInlineQueryLocation and HasTopicSidebar.
  • CallbackQuery.InlineMessageID can now arrive for a message the bot sent itself, instead of CallbackQuery.Message, depending on callback_query_mode.

Bot invites

  • WriteAccessAllowed.Inviter — the owner who invited the user to a private chat with the bot through https://t.me/botinvite/<bot_username> (up to 10 users at once). The bot may message invited users.

Rich messages

  • Blocks on RichBlockExpandableBlockQuotation and InputRichBlockExpandableBlockQuotation (see Breaking changes).

🧰 Framework helpers (hand-written)

  • Router
    • Context.InlineMessageID() — the inline message a callback query, chosen inline result or widget query refers to.
    • BotInvite() / OnBotInvite — a user the owner invited with the botinvite link.
    • CallbackQuerySuffix(s) / OnCallbackQuerySuffix and CallbackQueryEquals(s) / OnCallbackQueryEquals, next to CallbackPrefix / OnCallbackPrefix.
  • Entity parsing — Telegram's entity offsets are UTF-16 units, so slicing msg.Text with them breaks on emoji and most non-Latin text. ParsedMessageEntity carries the entity's Text and UTF-8 Offset/Length (and URL for a url entity):
    • msg.ParseEntities(), ParseCaptionEntities(), ParseAnyEntities() (caption, checklist, game, gift, poll texts too), ParseEntity(e), ParseCaptionEntity(e) and the …Types(map[lumex.MessageEntityType]struct{}{…}) filters — all nil-safe;
    • lumex.ParseEntities(text, entities), ParseEntity, ParseEntityTypes for any other text. A malformed entity never panics: its range is clamped.
  • Client timeouts — DefaultRequestTimeout (30 s), DefaultUploadTimeout (5 min), and the WithRequestTimeout / WithUploadTimeout client options (see Changed).
  • New example examples/tour-10.5 — a menu-driven tour of the release in one message with ⬅️ Back on every submenu: what getMe reports as BotFullInfo; a settings panel covering every setMySettings parameter (the placeholder is free text sent as a reply); the three callback modes with a button that shows whether a tap came with message or inline_message_id; an expandable quotation made of blocks; and the invite link, with a greeting for each invited user. It passes its allowed_updates, so it works on a bot whose token remembers an older list. Its RELEASE_NOTES.md is this file.

🔄 Changed

  • Every Bot API request is bounded by default: 30 s, or 5 min when it uploads files. A deadline already on the call's ctx replaces that limit, longer or shorter; <= 0 disables it. GetUpdatesChan gives each long poll its own deadline just beyond the poll timeout.
  • Context.EditMessageText edits by inline_message_id when the update carries no message — a callback from an inline message, or from the bot's own message under callback_query_mode "inline"/"auto". It then returns (nil, true, nil); before, it failed with ErrContextMessageIsNil.
  • The examples read bot.Username instead of bot.User.Username; tour-10.3 builds its expandable quotation from blocks and tour-10.4 edits widget data with new(…).

🐛 Fixed

  • Sub-routers inherit their group's middlewares consistently.
    • UseState called on a Group dropped the group's middlewares: r.Group(requireAdmin).UseState("editing").OnMessage(h) ran h without requireAdmin. It now runs the global middlewares, then requireAdmin, then the state's, then h.
    • Groups nested three or more levels deep ran their outer middlewares more than once.
    • Routes registered on one group could share a handler slice, so registering a second route could replace the first route's handler.
    • A UseState sub-router no longer keeps a stale copy of its parent's routes.
    • A sub-router fixes its middleware chain when it is created and when each route is registered: sub.Use(mw) reaches only routes registered on sub afterwards.
  • Zero values that could not be sent before can be now (Breaking change 4): non-anonymous polls, regular polls without revoting, channel admins promoted without the right to restrict members, cleared widget data, removed topic icons, ChatPermissions that differ from their defaults, request-users / request-chat buttons that ask for False.
  • ForumTopicEdited tells a removed icon ("") from an unedited one (nil).

🤖 Claude Code plugin

Plugin 1.3.0 → 1.4.0.

  • New rich-messages skill — choosing HTML, Markdown or blocks; every ready-made constructor; inline RichText formatting; media and uploads; tables, lists, quotations, details, maps, formulas and buttons; streaming drafts; the limits; and the usual mistakes.
  • New mini-app-auth skill — authenticating Mini App users on a Go backend: send the raw initData, parse it into a map of every field (a fixed struct breaks verification when Telegram adds a field), verify with the bot token (hash) for your own bot or with Telegram's Ed25519 key (signature, production and test keys) for another bot's — with an allowlist of bot ids — then check auth_date; plus constant-time comparison, duplicate keys, sessions and a tested standard-library implementation.
  • The lumex skill covers BotFullInfo and bot.Username, pointer options with new(v), SetMySettings, callback queries without a message, OnBotInvite, OnCallbackQuerySuffix / OnCallbackQueryEquals, the entity parsing helpers, default timeouts, how sub-router middlewares compose and promoted-field literals (Go 1.27); it points to the two new skills and corrects InputFilePath, which returns (*InputFile, error).
  • The telegram-widgets skill edits widget data with new(…).

⚙️ Internal

  • Generator: a new explicitZero list (internal/gen/parse.go) types an optional field as a pointer when its zero value means something different from leaving it out. zeroCandidate flags likely ones from the docs' wording ("aren't specified remain unchanged", "defaults to True", "pass an empty string to remove … if omitted, … isn't changed", …); cmd/gen prints a WARNING and TestExplicitZeroResolved fails until each is decided — true for a pointer, false when the zero value is harmless — or when a key matches no field. Covered by TestExplicitZero and TestZeroCandidate.
  • Docs snapshot bumped to 10.5; golden, determinism, no-untyped-fields and explicit-zero tests green, with 0 untyped fields across 396 object types, 69 enums, 29 unions and 194 methods.
  • A maintainer-only Claude Code skill, .claude/skills/bot-api-update, now holds the Bot API upgrade procedure — snapshot, warnings, keepPositional / explicitZero / patchUnionSubtypes, the router coverage test, tour rules, version bumps and these release notes — and CLAUDE.md points to it.
  • go.mod moved to go 1.27 and the code was modernised with go fix; CI follows go.mod (go-version-file).
  • .gitignore ignores examples/localtest.

📦 Upgrade

go get github.com/kbgod/lumex/v2@v2.5.0
  1. Build with Go 1.27 or newer (see Breaking change 5).
  2. Only where code names the embedded User field: bot.User.X → bot.X (which already worked in v2.4.0), bot.User as a whole value → bot.BotFullInfo, and lumex.Bot{User: lumex.User{Username: …}} → lumex.Bot{Username: …}.
  3. GetMe returns *lumex.BotFullInfo: read CanJoinGroups, SupportsInlineQueries and the other bot-only flags from it, not from a User.
  4. Wrap the text of an expandable quotation in a block, e.g. NewInputRichBlockParagraph.
  5. For the pointer fields in the table above: Field: v → Field: new(v), and check for nil when reading ChatPermissions or ForumTopicEdited.
  6. Timeouts. A hand-rolled GetUpdates long poll with Timeout ≥ 30 s, or an upload that takes over 5 minutes, needs its own context.WithTimeout on the call (or WithRequestTimeout / WithUploadTimeout) — otherwise the new default cuts it. GetUpdatesChan and the dispatcher already do this.

Good to know:

  • Under callback_query_mode "inline" (or "auto" for an inaccessible message), a callback query from the bot's own message has no message: ctx.Message() and ctx.Chat() are nil and ctx.ChatID() falls back to the sender — right in a private chat, wrong in a group. ctx.EditMessageText keeps working.
  • has_topic_sidebar takes effect only with topics in private chats enabled: with has_topics_enabled off, Telegram accepts the call but keeps the sidebar off.
  • The https://t.me/botinvite/… link needs a Telegram app that knows it; an older one reads botinvite as a username and says the user doesn't exist.