Skip to content

Fix Bot API request serialization parity gaps - #82

Merged
iamwavecut merged 2 commits into
masterfrom
bot-api-request-serialization-fixes
Jul 6, 2026
Merged

Fix Bot API request serialization parity gaps#82
iamwavecut merged 2 commits into
masterfrom
bot-api-request-serialization-fixes

Conversation

@iamwavecut

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes a set of request-serialization gaps found while comparing the library against the current Telegram Bot API request contract and behavior in other connectors.

  • Serialize sendPaidMedia.media as a JSON array, as required by the Bot API, while keeping NewPaidMedia(..., *InputPaidMedia) source-compatible for single-item usage.
  • Add PaidMediaConfig.MediaItems and NewPaidMediaGroup for the official 1-10 paid media item shape.
  • Serialize InputSticker.sticker as the file string expected by Telegram: file_id/URL for remote files or attach://... for multipart uploads.
  • Make sticker upload file collection upload-only, so FileID and URL sticker values do not overwrite the JSON InputSticker object during request preparation.
  • Send required boolean false values for answerShippingQuery.ok, answerPreCheckoutQuery.ok, and editUserStarSubscription.is_canceled.
  • Stop sending empty optional business_connection_id, zero reply_parameters, and zero link_preview_options objects from shared base configs.
  • Make Params.AddInterface skip typed nil slices/maps/interfaces instead of serializing them as null, while preserving explicit non-nil empty slices as [].
  • Add explicit opt-in flags for Bot API fields where an empty string has active semantics: sendMessageDraft, setUserEmojiStatus, setCustomEmojiStickerSetThumbnail, editForumTopic, setMyName, setMyDescription, and setMyShortDescription.

Compatibility

This is intended to be source-compatible for existing callers:

  • Existing NewPaidMedia and PaidMediaConfig.Media callers continue to compile; their request payload now matches the official array shape.
  • Empty-string actions are opt-in via new booleans, so accidental zero-value configs do not start clearing names, descriptions, emoji status, thumbnails, or forum icons.
  • AddInterface no longer emits null for typed nil slices/maps/interfaces. Explicit empty slices still serialize as [], matching the API contract for list values.
  • The only behavioral changes are request payload corrections where the previous output was missing required fields, sending non-spec shapes, or sending unintended empty optional objects.

References Checked

  • Official Telegram Bot API: sendPaidMedia.media is an array of InputPaidMedia items.
  • Official Telegram Bot API: InputSticker.sticker is a string accepting file_id, URL, or attach://<file_attach_name>.
  • Official Telegram Bot API: selected empty strings are meaningful for draft text placeholders, emoji status removal, forum icon removal, sticker set thumbnail dropping, and bot name/description removal.
  • Cross-checks against aiogram and grammY show sendPaidMedia modeled with media as a list/array and optional business parameters omitted when absent.

Verification

  • go test ./...
  • go vet ./...

@iamwavecut
iamwavecut requested a review from zhuk-kk as a code owner July 5, 2026 22:03
@iamwavecut iamwavecut self-assigned this Jul 5, 2026
@iamwavecut
iamwavecut merged commit ac50f6f into master Jul 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant