From 84461290033bfb72111c05c31cf96f6470d1ab95 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 Apr 2018 19:48:15 +0200 Subject: [PATCH] Enhance send_document by accepting file_ids and URLs --- pyrogram/client/client.py | 59 +++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 51f63896..90cdac10 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1394,7 +1394,9 @@ class Client: document (``str``): File to send. - Pass a file path as string to send a file that exists on your local machine. + Pass a file_id as string to send a file that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get a file from the Internet, or + pass a file path as string to upload a new file that exists on your local machine. caption (``str``, optional): Document caption, 0-200 characters. @@ -1423,26 +1425,56 @@ class Client: The size of the file. Returns: - On success, the sent Message is returned. + On success, the sent :obj:`Message ` is returned. Raises: :class:`Error ` """ + file = None style = self.html if parse_mode.lower() == "html" else self.markdown - file = self.save_file(document, progress=progress) + + if os.path.exists(document): + file = self.save_file(document, progress=progress) + media = types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"), + file=file, + attributes=[ + types.DocumentAttributeFilename(os.path.basename(document)) + ] + ) + elif document.startswith("http"): + media = types.InputMediaDocumentExternal( + url=document + ) + else: + try: + decoded = utils.decode(document) + fmt = " 24 else "