From 2617618cef93a4484eaf691aa5158b0351168892 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 23 Aug 2018 21:21:27 +0200 Subject: [PATCH] Add support for Document message edits --- .../methods/messages/edit_message_media.py | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 086d8dc2..7bf66d5e 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -26,7 +26,7 @@ from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( InputMediaPhoto, InputMediaVideo, InputMediaAudio, - InputMediaAnimation + InputMediaAnimation, InputMediaDocument ) @@ -245,6 +245,54 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaDocument): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "text/plain"), + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeFilename(os.path.basename(media.media)) + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else "