Skip to content

fix missing type in the media of rich message blocks - #339

Merged
ayrat555 merged 2 commits into
ayrat555:masterfrom
mmahdi-sz:fix/rich-block-media-type
Sep 25, 2026
Merged

ayrat555 merged 2 commits into
ayrat555:masterfrom
mmahdi-sz:fix/rich-block-media-type

Conversation

@mmahdi-sz

Copy link
Copy Markdown
Contributor

Sending a rich message with a media block fails with:

Bad Request: can't parse InputRichBlock: Can't find field "type"

InputRichBlockVideo holds an InputMediaVideo, and that struct has no type field of its own - it normally gets one from the InputMedia enum tag. Inside a block there is no tag, so the media goes out without a type and Telegram rejects it. Same for the photo, animation, audio, voice note and document blocks.

Fixed with a serialize_with that writes the type next to the flattened media. Public API and deserialization are unchanged.

Sending a rich message with a media block fails with:

    Bad Request: can't parse InputRichBlock: Can't find field "type"

InputRichBlockVideo holds an InputMediaVideo, and that struct has no type field
of its own - it normally gets one from the InputMedia enum tag. Inside a block
there is no tag, so the media goes out without a type and Telegram rejects it.
Same for the photo, animation, audio, voice note and document blocks.

Fixed with a serialize_with that writes the type next to the flattened media.
Public API and deserialization are unchanged.
@EdJoPaTo

EdJoPaTo commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Why not something with https://serde.rs/enum-representations.html#internally-tagged ?

This looks overly complex currently with the additional module needed and having that as an enum seems like a better solution? 🤔

@ayrat555

Copy link
Copy Markdown
Owner

@mmahdi-sz what do you think about @EdJoPaTo 's suggestion?

@mmahdi-sz

Copy link
Copy Markdown
Contributor Author

@ayrat555 @EdJoPaTo

Serde's tag = "type" only works on enums, but here blocks like InputRichBlockPhoto directly hold the concrete InputMediaPhoto struct. Changing that field to an enum breaks backward compatibility and drops compile-time type safety (allows passing audio into a photo block).

That's why #340 went with the exact same serialize_with approach.

I improved my PR and pushed an update to cover all 6 media types in the tests.

@ayrat555
ayrat555 merged commit 8aeb176 into ayrat555:master Sep 25, 2026
31 of 32 checks passed
@ayrat555

Copy link
Copy Markdown
Owner

thank you! merged

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.

3 participants