From 4f615bd6dc22cf85f15d7ad3dd3328119f6be5a9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 Apr 2018 19:56:11 +0200 Subject: [PATCH] Enhance send_sticker 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 90cdac10..b23e3cda 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1508,7 +1508,9 @@ class Client: sticker (``str``): Sticker to send. - Pass a file path as string to send a sticker that exists on your local machine. + Pass a file_id as string to send a sticker that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get a .webp sticker file from the Internet, or + pass a file path as string to upload a new sticker that exists on your local machine. disable_notification (``bool``, optional): Sends the message silently. @@ -1529,25 +1531,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 = self.save_file(sticker, progress=progress) + file = None + + if os.path.exists(sticker): + file = self.save_file(sticker, progress=progress) + media = types.InputMediaUploadedDocument( + mime_type="image/webp", + file=file, + attributes=[ + types.DocumentAttributeFilename(os.path.basename(sticker)) + ] + ) + elif sticker.startswith("http"): + media = types.InputMediaDocumentExternal( + url=sticker + ) + else: + try: + decoded = utils.decode(sticker) + fmt = " 24 else "