Repository navigation
Upload media files of rich messages - #2640
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
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 eternnoir#2624.
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: