WithRetry()option — opt-in automatic retry for retryable API errors (HTTP 429 rate limit and attachment processing errors). Configurable intervals, respects context cancellation. Default intervals: 500ms, 1s, 2s, 5sDefaultRetryIntervals— exported default retry intervals forWithRetryCheckPhoneNumbers(ctx, phoneNumbers)— check which phone numbers are registered in Max (GET /notify/exists)SendMessageToPhones(ctx, phoneNumbers, body)— send messages to users by phone numbers (POST /messageswithphone_numbersquery parameter)
- 5 new
ChatAdminPermissionconstants:PermCanCall,PermEditLink,PermPostEditDeleteMessage,PermEditMessage,PermDeleteMessage - Upload convenience methods:
UploadPhotoFromFile,UploadPhotoFromURL,UploadMediaFromFile,UploadMediaFromURL ErrFetcherror kind for external URL and local file failures in upload helpers- Example tests for godoc documentation
FromURLupload methods validate URL scheme (only http/https allowed, prevents SSRF via file:// etc.)FromURLupload methods limit download size to 50 MB (maxFetchSize)extractFilenamesanitizes Content-Disposition filenames withfilepath.Base(prevents path traversal)
ContactAttachmentPayload.Phone()— extracts phone number from VCFInfo (vCard TEL field)
- Button type
open_app:NewOpenAppButton(text, webAppURL)constructor andButton.WebAppfield for launching mini-apps inside the messenger - 5 new update types:
BotStoppedUpdate,DialogMutedUpdate,DialogUnmutedUpdate,DialogClearedUpdate,DialogRemovedUpdate— with constants, Go structs, and JSON round-trip tests
- Upload Content-Length:
doUploadnow buffers multipart body in memory instead of streaming viaio.Pipe— the Max Bot API requires aContent-Lengthheader, which was missing with pipe-based streaming (HTTP 406: "File size is unknown")
- Optional null handling:
Optional[T].UnmarshalJSONnow treats JSONnullas unset (Set=false) instead ofSet=truewith zero value — prevents accidental field overwrites when round-tripping API responses - Nil body panic:
SendMessageandSendMessageToUserno longer panic whenbodyis nil - Upload goroutine leak:
doUploadnow closes the pipe reader on all exit paths, preventing goroutine leaks on network errors - Upload timeout:
doUploadnow applies the client's default timeout when the context has no deadline, matchingdo()behavior - Long polling timeout:
GetUpdatesno longer raceshttp.Client.Timeoutagainst the server-side polling timeout — timeouts are now managed viacontextwith an automatic 5s buffer on top of the server-side duration - JSON serialization:
NewMessageBody.Attachmentschanged fromomitemptytoomitzero— empty slice[]AttachmentRequest{}is now serialized as"attachments":[]instead of being omitted, allowing inline keyboard removal
Attachmentinterface andMessageBody.ParseAttachments()— type-safe parsing of response attachments via discriminator map (all 11 types: image, video, audio, file, sticker, contact, share, location, data, inline_keyboard, reply_keyboard); unknown types are skipped for forward compatibility- Type-safe button constructors:
NewCallbackButton,NewCallbackButtonWithIntent,NewLinkButton,NewRequestContactButton,NewRequestGeoLocationButton,NewChatButton,NewMessageButton ErrPollDeadline— returned when the context deadline is too short for the requested polling timeoutOptional[T],Some[T]()— generic optional type with three-state JSON semantics (unset / zero value / value), replaces*string/*boolpointers in request types- Type aliases:
OptString,OptBool,OptInt64
NewMessageBody.Text:*string→OptStringNewMessageBody.Notify:*bool→OptBoolNewMessageBody.Format:*TextFormat→Optional[TextFormat]BotPatch.Name,.FirstName,.Description:*string→OptStringChatPatch.Title,.Pin:*string→OptStringChatPatch.Notify:*bool→OptBoolCallbackAnswer.Notification:*string→OptStringPinMessageBody.Notify:*bool→OptBoolButton.ChatDescription,.StartPayload:*string→OptStringButton.UUID:*int64→OptInt64ReplyButton.Payload:*string→OptStringAttachmentRequest.DirectUserID:*int64→OptInt64PhotoAttachmentRequestPayload.URL,.Token:*string→OptStringContactAttachmentRequestPayload.Name,.VCFInfo,.VCFPhone:*string→OptStringContactAttachmentRequestPayload.ContactID:*int64→OptInt64ShareAttachmentPayload.URL,.Token:*string→OptString
- Query params:
message_idsandtypesare now comma-separated (style: simple) as required by the OpenAPI schema - URL-encoding:
GetChatByLinkandGetMessageByIDnow escape special characters in path viaurl.PathEscape - Security: token is sent via
Authorizationheader instead ofaccess_tokenquery parameter — prevents token leaking into proxy and CDN logs - Tests:
requestCountin upload tests replaced withatomic.Int32to eliminate race condition - Options:
WithHTTPClientnow makes a shallow copy —WithTimeoutno longer mutates the external*http.Client - Types:
Button.UUIDchanged from*intto*int64for consistency with other ID fields - Leak fix:
doUpload— addedpr.Close()on request creation error - Types:
interface{}replaced withanythroughout (AttachmentRequest.Payload,do()signature) - Types:
VideoURLsfields renamed to idiomatic Go (MP4_1080→MP41080, etc.); JSON tags unchanged - Types:
UserIdsList→UserIDsList(Go naming convention for acronyms) - Types:
User.LastNameandUser.Usernamechanged fromstringto*string(nullable in API) - Types:
NewMessageBody.Textchanged fromstringto*string—nilmeans "keep existing text" on edit,""means "clear text" - Types:
GetAdminsnow returns*ChatAdminsListinstead of*ChatMembersList - Types:
BotCommand.Descriptionchanged fromstringto*string(nullable in schema) - Types:
ContactAttachmentRequestPayload.Namechanged fromstringto*string(nullable in schema) - Code quality:
isTimeoutuseserrors.Asinstead of direct type assertion (handles wrapped errors)
- Endpoints:
SetAdmins(POST /chats/{chatId}/members/admins),RemoveAdmin(DELETE /chats/{chatId}/members/admins/{userId}),GetVideoDetails(GET /videos/{videoToken}) - Params:
DisableLinkPreviewfield onNewMessageBody(sent as query param, not JSON) - Params:
from/to(time range filter) inGetMessagesvia newGetMessagesOpts - Params:
user_idsinGetMembersvia newGetMembersOpts - Opts:
GetChatsOptsstruct forGetChatspagination parameters - Opts:
GetUpdatesOptsstruct forGetUpdateslong-polling parameters - Type-safe attachment constructors:
NewPhotoAttachment,NewVideoAttachment,NewAudioAttachment,NewFileAttachment,NewStickerAttachment,NewContactAttachment,NewShareAttachment,NewInlineKeyboardAttachment,NewLocationAttachment - Tests:
TestGetMessagesWithIDs,TestGetChatByLink,TestGetMembership,TestUnpinMessage,TestGetPinnedMessage,types_test.go(all 9 attachment constructors)