diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 34b4273f..74dfdafd 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -45,14 +45,16 @@ from pyrogram.api.errors import ( PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing, ChatAdminRequired, FirstnameInvalid, PhoneNumberBanned, - VolumeLocNotFound, UserMigrate) + VolumeLocNotFound, UserMigrate, FileIdInvalid) from pyrogram.crypto import AES from pyrogram.session import Auth, Session from pyrogram.session.internals import MsgId +from . import message_parser from .dispatcher import Dispatcher from .handler import Handler from .input_media import InputMedia from .style import Markdown, HTML +from .utils import decode log = logging.getLogger(__name__) @@ -133,6 +135,18 @@ class Client: UPDATES_WORKERS = 1 DOWNLOAD_WORKERS = 1 + MEDIA_TYPE_ID = { + 0: "Thumbnail", + 2: "Photo", + 3: "Voice", + 4: "Video", + 5: "Document", + 8: "Sticker", + 9: "Audio", + 10: "GIF", + 13: "VideoNote" + } + def __init__(self, session_name: str, api_id: int or str = None, @@ -1075,7 +1089,9 @@ class Client: photo (``str``): Photo to send. - Pass a file path as string to send a photo that exists on your local machine. + Pass a file_id as string to send a photo that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get a photo from the Internet, or + pass a file path as string to upload a new photo that exists on your local machine. caption (``bool``, optional): Photo caption, 0-200 characters. @@ -1109,23 +1125,55 @@ 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(photo, progress=progress) + + if os.path.exists(photo): + file = self.save_file(photo, progress=progress) + media = types.InputMediaUploadedPhoto( + file=file, + ttl_seconds=ttl_seconds + ) + elif photo.startswith("http"): + media = types.InputMediaPhotoExternal( + url=photo, + ttl_seconds=ttl_seconds + ) + else: + try: + decoded = decode(photo) + fmt = " 24 else "