Repository navigation
Upload media files of rich messages - #2640
Merged
Badiboy merged 1 commit intoOct 24, 2026
Merged
Conversation
InputRichMessage was sent with to_json() only, so a media object built from an InputFile (in a photo, video, animation, audio, voice note or document block, or in InputRichMessage.media) was sent as an attach:// reference without the file. Add InputRichMessage.convert_input_rich_message(), which returns the JSON and the files of every InputMedia in the message, including blocks nested in lists, collages, slideshows, details and quotations, and send those files with send_rich_message, send_rich_message_draft and edit_message_text, in apihelper and asyncio_helper. Items 1 and 2 of #2624.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The scoped changes consistently reuse existing media conversion and request handling, with regression coverage and no identified blocking issues.
No open issues 🎉
What changed in this PR
This PR fixes rich-message media uploads for items 1 and 2 of #2624 by sending file attachments alongside the serialized message through the existing upload handling.
Changes:
- Collects media files from rich-message media entries and nested blocks using existing media converters.
- Forwards attachments in synchronous and asynchronous send, draft, and text-edit methods.
- Adds regression tests for nested uploads, attachment-name matching, and messages without uploads.
| File | Description |
|---|---|
| tests/test_rich_message_uploads.py | Tests attachment forwarding for sync and async methods. |
| telebot/types.py | Adds recursive rich-message attachment collection. |
| telebot/asyncio_helper.py | Passes collected files to asynchronous requests. |
| telebot/apihelper.py | Passes collected files to synchronous requests. |
Review effort: Balanced
Collaborator
IMHO it's functional but highly inaccurate approach. For now it's better then nothing, but I prefer to have more convenient way, when code operate more precisely... |
Collaborator
|
Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Covers items 1 and 2 of #2624.
Rich messages were sent with
rich_message.to_json()only. A media object built from anInputFileis serialized as anattach://<name>reference, but the file itself was never sent, so uploads inInputRichBlockAnimation,InputRichBlockAudio,InputRichBlockPhoto,InputRichBlockVideo,InputRichBlockVoiceNote,InputRichBlockDocumentandInputRichMessageMediacould not work.InputRichMessage.convert_input_rich_message()returns the JSON and the files of everyInputMediain the message, collected with each media's ownconvert_input_media()(so thumbnails and video covers are included). It looks throughmediaandblocks, including blocks nested in list items, collages, slideshows, details and quotations.send_rich_message,send_rich_message_draftandedit_message_textsend those files, in bothapihelper.pyandasyncio_helper.py. They already usedPOST. A rich message without uploads has no files, so the request is the same as before.edit_ephemeral_message_textalso takes arich_message; I left it as it is because #2624 doesn't list it, but it could use the same helper.Describe your tests
New
tests/test_rich_message_uploads.py, which replaces_make_request/_process_requestand checks what would be sent:InputRichMessageMediavideo, sends both files, under the names that theattach://references in the JSON use, for each of the three methods (sync and async);The tests fail without the change and pass with it.
pytest tests --ignore=tests/test_telebot.py: 290 passed, 2 skipped. This PR is independent of #2639 (checklists andreplace_sticker_in_set, item 3 of #2624).Python version: 3.12
OS: Windows 11
Checklist: