mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-25 19:38:31 +00:00
Fix FILE_REFERENCE_* errors for uploads
This commit is contained in:
parent
1cd94520bf
commit
92c1b48132
@ -1869,7 +1869,7 @@ class Client(Methods, BaseClient):
|
||||
peer_access_hash: int,
|
||||
volume_id: int,
|
||||
local_id: int,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
file_size: int,
|
||||
is_big: bool,
|
||||
progress: callable,
|
||||
@ -1910,6 +1910,8 @@ class Client(Methods, BaseClient):
|
||||
|
||||
self.media_sessions[dc_id] = session
|
||||
|
||||
file_ref = utils.decode_file_ref(file_ref)
|
||||
|
||||
if media_type == 1:
|
||||
location = types.InputPeerPhotoFileLocation(
|
||||
peer=types.InputPeerUser(
|
||||
|
@ -22,7 +22,7 @@ class FileData:
|
||||
self, *, media_type: int = None, dc_id: int = None, document_id: int = None, access_hash: int = None,
|
||||
thumb_size: str = None, peer_id: int = None, peer_access_hash: int = None, volume_id: int = None,
|
||||
local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None, file_name: str = None,
|
||||
date: int = None, file_ref: bytes = None
|
||||
date: int = None, file_ref: str = None
|
||||
):
|
||||
self.media_type = media_type
|
||||
self.dc_id = dc_id
|
||||
|
@ -70,6 +70,17 @@ def encode(s: bytes) -> str:
|
||||
return base64.urlsafe_b64encode(r).decode().rstrip("=")
|
||||
|
||||
|
||||
def encode_file_ref(file_ref: bytes) -> str:
|
||||
return base64.urlsafe_b64encode(file_ref).decode().rstrip("=")
|
||||
|
||||
|
||||
def decode_file_ref(file_ref: str) -> bytes:
|
||||
if file_ref is None:
|
||||
return b""
|
||||
|
||||
return base64.urlsafe_b64decode(file_ref + "=" * (-len(file_ref) % 4))
|
||||
|
||||
|
||||
def get_offset_date(dialogs):
|
||||
for m in reversed(dialogs.messages):
|
||||
if isinstance(m, types.MessageEmpty):
|
||||
@ -82,6 +93,7 @@ def get_offset_date(dialogs):
|
||||
|
||||
def get_input_media_from_file_id(
|
||||
file_id_str: str,
|
||||
file_ref: str = None,
|
||||
expected_media_type: int = None
|
||||
) -> Union[types.InputMediaPhoto, types.InputMediaDocument]:
|
||||
try:
|
||||
@ -111,7 +123,7 @@ def get_input_media_from_file_id(
|
||||
id=types.InputPhoto(
|
||||
id=file_id,
|
||||
access_hash=access_hash,
|
||||
file_reference=b""
|
||||
file_reference=decode_file_ref(file_ref)
|
||||
)
|
||||
)
|
||||
|
||||
@ -123,7 +135,7 @@ def get_input_media_from_file_id(
|
||||
id=types.InputDocument(
|
||||
id=file_id,
|
||||
access_hash=access_hash,
|
||||
file_reference=b""
|
||||
file_reference=decode_file_ref(file_ref)
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -35,7 +35,7 @@ class DownloadMedia(BaseClient):
|
||||
def download_media(
|
||||
self,
|
||||
message: Union["pyrogram.Message", str],
|
||||
file_ref: bytes = None,
|
||||
file_ref: str = None,
|
||||
file_name: str = DEFAULT_DOWNLOAD_DIR,
|
||||
block: bool = True,
|
||||
progress: callable = None,
|
||||
@ -48,8 +48,9 @@ class DownloadMedia(BaseClient):
|
||||
Pass a Message containing the media, the media itself (message.audio, message.video, ...) or
|
||||
the file id as string.
|
||||
|
||||
file_ref (``bytes``, *optional*):
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
file_name (``str``, *optional*):
|
||||
A custom *file_name* to be used instead of the one provided by Telegram.
|
||||
@ -133,7 +134,7 @@ class DownloadMedia(BaseClient):
|
||||
file_size=file_size,
|
||||
mime_type=mime_type,
|
||||
date=date,
|
||||
file_ref=file_ref or b""
|
||||
file_ref=file_ref
|
||||
)
|
||||
|
||||
def get_existing_attributes() -> dict:
|
||||
|
@ -77,35 +77,35 @@ class EditInlineMedia(BaseClient):
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 2)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 2)
|
||||
elif isinstance(media, InputMediaVideo):
|
||||
if media.media.startswith("http"):
|
||||
media = types.InputMediaDocumentExternal(
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 4)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 4)
|
||||
elif isinstance(media, InputMediaAudio):
|
||||
if media.media.startswith("http"):
|
||||
media = types.InputMediaDocumentExternal(
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 9)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 9)
|
||||
elif isinstance(media, InputMediaAnimation):
|
||||
if media.media.startswith("http"):
|
||||
media = types.InputMediaDocumentExternal(
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 10)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 10)
|
||||
elif isinstance(media, InputMediaDocument):
|
||||
if media.media.startswith("http"):
|
||||
media = types.InputMediaDocumentExternal(
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 5)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 5)
|
||||
|
||||
return self.send(
|
||||
functions.messages.EditInlineBotMessage(
|
||||
|
@ -100,7 +100,7 @@ class EditMessageMedia(BaseClient):
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 2)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 2)
|
||||
elif isinstance(media, InputMediaVideo):
|
||||
if os.path.exists(media.media):
|
||||
media = self.send(
|
||||
@ -137,7 +137,7 @@ class EditMessageMedia(BaseClient):
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 4)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 4)
|
||||
elif isinstance(media, InputMediaAudio):
|
||||
if os.path.exists(media.media):
|
||||
media = self.send(
|
||||
@ -173,7 +173,7 @@ class EditMessageMedia(BaseClient):
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 9)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 9)
|
||||
elif isinstance(media, InputMediaAnimation):
|
||||
if os.path.exists(media.media):
|
||||
media = self.send(
|
||||
@ -211,7 +211,7 @@ class EditMessageMedia(BaseClient):
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 10)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 10)
|
||||
elif isinstance(media, InputMediaDocument):
|
||||
if os.path.exists(media.media):
|
||||
media = self.send(
|
||||
@ -242,7 +242,7 @@ class EditMessageMedia(BaseClient):
|
||||
url=media.media
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(media.media, 5)
|
||||
media = utils.get_input_media_from_file_id(media.media, media.file_ref, 5)
|
||||
|
||||
r = self.send(
|
||||
functions.messages.EditMessage(
|
||||
|
@ -30,6 +30,7 @@ class SendAnimation(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
animation: str,
|
||||
file_ref: str = None,
|
||||
caption: str = "",
|
||||
unsave: bool = False,
|
||||
parse_mode: Union[str, None] = object,
|
||||
@ -63,6 +64,10 @@ class SendAnimation(BaseClient):
|
||||
pass an HTTP URL as a string for Telegram to get an animation from the Internet, or
|
||||
pass a file path as string to upload a new animation that exists on your local machine.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
caption (``str``, *optional*):
|
||||
Animation caption, 0-1024 characters.
|
||||
|
||||
@ -176,7 +181,7 @@ class SendAnimation(BaseClient):
|
||||
url=animation
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(animation, 10)
|
||||
media = utils.get_input_media_from_file_id(animation, file_ref, 10)
|
||||
|
||||
while True:
|
||||
try:
|
||||
@ -209,7 +214,7 @@ class SendAnimation(BaseClient):
|
||||
|
||||
if unsave:
|
||||
document = message.animation or message.document
|
||||
document_id = utils.get_input_media_from_file_id(document.file_id).id
|
||||
document_id = utils.get_input_media_from_file_id(document.file_id, document.file_ref).id
|
||||
|
||||
self.send(
|
||||
functions.messages.SaveGif(
|
||||
|
@ -30,6 +30,7 @@ class SendAudio(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
audio: str,
|
||||
file_ref: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
duration: int = 0,
|
||||
@ -64,6 +65,10 @@ class SendAudio(BaseClient):
|
||||
pass an HTTP URL as a string for Telegram to get an audio file from the Internet, or
|
||||
pass a file path as string to upload a new audio file that exists on your local machine.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
caption (``str``, *optional*):
|
||||
Audio caption, 0-1024 characters.
|
||||
|
||||
@ -174,7 +179,7 @@ class SendAudio(BaseClient):
|
||||
url=audio
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(audio, 9)
|
||||
media = utils.get_input_media_from_file_id(audio, file_ref, 9)
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -28,6 +28,7 @@ class SendCachedMedia(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
file_id: str,
|
||||
file_ref: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
disable_notification: bool = None,
|
||||
@ -56,6 +57,10 @@ class SendCachedMedia(BaseClient):
|
||||
Media to send.
|
||||
Pass a file_id as string to send a media that exists on the Telegram servers.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
caption (``bool``, *optional*):
|
||||
Media caption, 0-1024 characters.
|
||||
|
||||
@ -92,7 +97,7 @@ class SendCachedMedia(BaseClient):
|
||||
r = self.send(
|
||||
functions.messages.SendMedia(
|
||||
peer=self.resolve_peer(chat_id),
|
||||
media=utils.get_input_media_from_file_id(file_id),
|
||||
media=utils.get_input_media_from_file_id(file_id, file_ref),
|
||||
silent=disable_notification or None,
|
||||
reply_to_msg_id=reply_to_message_id,
|
||||
random_id=self.rnd_id(),
|
||||
|
@ -30,6 +30,7 @@ class SendDocument(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
document: str,
|
||||
file_ref: str = None,
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
@ -59,6 +60,10 @@ class SendDocument(BaseClient):
|
||||
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.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
thumb (``str``, *optional*):
|
||||
Thumbnail of the file sent.
|
||||
The thumbnail should be in JPEG format and less than 200 KB in size.
|
||||
@ -149,7 +154,7 @@ class SendDocument(BaseClient):
|
||||
url=document
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(document, 5)
|
||||
media = utils.get_input_media_from_file_id(document, file_ref, 5)
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -119,7 +119,7 @@ class SendMediaGroup(BaseClient):
|
||||
)
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(i.media, 2)
|
||||
media = utils.get_input_media_from_file_id(i.media, i.file_ref, 2)
|
||||
elif isinstance(i, pyrogram.InputMediaVideo):
|
||||
if os.path.exists(i.media):
|
||||
while True:
|
||||
@ -174,7 +174,7 @@ class SendMediaGroup(BaseClient):
|
||||
)
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(i.media, 4)
|
||||
media = utils.get_input_media_from_file_id(i.media, i.file_ref, 4)
|
||||
|
||||
multi_media.append(
|
||||
types.InputSingleMedia(
|
||||
|
@ -30,6 +30,7 @@ class SendPhoto(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
photo: str,
|
||||
file_ref: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
ttl_seconds: int = None,
|
||||
@ -59,6 +60,10 @@ class SendPhoto(BaseClient):
|
||||
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.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
caption (``bool``, *optional*):
|
||||
Photo caption, 0-1024 characters.
|
||||
|
||||
@ -144,7 +149,7 @@ class SendPhoto(BaseClient):
|
||||
ttl_seconds=ttl_seconds
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(photo, 2)
|
||||
media = utils.get_input_media_from_file_id(photo, file_ref, 2)
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -30,6 +30,7 @@ class SendSticker(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
sticker: str,
|
||||
file_ref: str = None,
|
||||
disable_notification: bool = None,
|
||||
reply_to_message_id: int = None,
|
||||
schedule_date: int = None,
|
||||
@ -56,6 +57,10 @@ class SendSticker(BaseClient):
|
||||
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.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
disable_notification (``bool``, *optional*):
|
||||
Sends the message silently.
|
||||
Users will receive a notification with no sound.
|
||||
@ -122,7 +127,7 @@ class SendSticker(BaseClient):
|
||||
url=sticker
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(sticker, 8)
|
||||
media = utils.get_input_media_from_file_id(sticker, file_ref, 8)
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -30,6 +30,7 @@ class SendVideo(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
video: str,
|
||||
file_ref: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
duration: int = 0,
|
||||
@ -63,6 +64,10 @@ class SendVideo(BaseClient):
|
||||
pass an HTTP URL as a string for Telegram to get a video from the Internet, or
|
||||
pass a file path as string to upload a new video that exists on your local machine.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
caption (``str``, *optional*):
|
||||
Video caption, 0-1024 characters.
|
||||
|
||||
@ -172,7 +177,7 @@ class SendVideo(BaseClient):
|
||||
url=video
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(video, 4)
|
||||
media = utils.get_input_media_from_file_id(video, file_ref, 4)
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -30,6 +30,7 @@ class SendVideoNote(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
video_note: str,
|
||||
file_ref: str = None,
|
||||
duration: int = 0,
|
||||
length: int = 1,
|
||||
thumb: str = None,
|
||||
@ -59,6 +60,10 @@ class SendVideoNote(BaseClient):
|
||||
pass a file path as string to upload a new video note that exists on your local machine.
|
||||
Sending video notes by a URL is currently unsupported.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
duration (``int``, *optional*):
|
||||
Duration of sent video in seconds.
|
||||
|
||||
@ -140,7 +145,7 @@ class SendVideoNote(BaseClient):
|
||||
]
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(video_note, 13)
|
||||
media = utils.get_input_media_from_file_id(video_note, file_ref, 13)
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -30,6 +30,7 @@ class SendVoice(BaseClient):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
voice: str,
|
||||
file_ref=None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
duration: int = 0,
|
||||
@ -59,6 +60,10 @@ class SendVoice(BaseClient):
|
||||
pass an HTTP URL as a string for Telegram to get an audio from the Internet, or
|
||||
pass a file path as string to upload a new audio that exists on your local machine.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
caption (``str``, *optional*):
|
||||
Voice message caption, 0-1024 characters.
|
||||
|
||||
@ -144,7 +149,7 @@ class SendVoice(BaseClient):
|
||||
url=voice
|
||||
)
|
||||
else:
|
||||
media = utils.get_input_media_from_file_id(voice, 3)
|
||||
media = utils.get_input_media_from_file_id(voice, file_ref, 3)
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -31,9 +31,10 @@ class InputMedia(Object):
|
||||
- :obj:`InputMediaVideo`
|
||||
"""
|
||||
|
||||
def __init__(self, media: str, caption: str, parse_mode: str):
|
||||
def __init__(self, media: str, file_ref: str, caption: str, parse_mode: str):
|
||||
super().__init__()
|
||||
|
||||
self.media = media
|
||||
self.file_ref = file_ref
|
||||
self.caption = caption
|
||||
self.parse_mode = parse_mode
|
||||
|
@ -30,6 +30,10 @@ class InputMediaAnimation(InputMedia):
|
||||
Pass a file_id as string to send a file that exists on the Telegram servers or
|
||||
pass a file path as string to upload a new file that exists on your local machine.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
thumb (``str``, *optional*):
|
||||
Thumbnail of the animation file sent.
|
||||
The thumbnail should be in JPEG format and less than 200 KB in size.
|
||||
@ -59,6 +63,7 @@ class InputMediaAnimation(InputMedia):
|
||||
def __init__(
|
||||
self,
|
||||
media: str,
|
||||
file_ref: str = None,
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
@ -66,7 +71,7 @@ class InputMediaAnimation(InputMedia):
|
||||
height: int = 0,
|
||||
duration: int = 0
|
||||
):
|
||||
super().__init__(media, caption, parse_mode)
|
||||
super().__init__(media, file_ref, caption, parse_mode)
|
||||
|
||||
self.thumb = thumb
|
||||
self.width = width
|
||||
|
@ -32,6 +32,10 @@ class InputMediaAudio(InputMedia):
|
||||
Pass a file_id as string to send an audio that exists on the Telegram servers or
|
||||
pass a file path as string to upload a new audio that exists on your local machine.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
thumb (``str``, *optional*):
|
||||
Thumbnail of the music file album cover.
|
||||
The thumbnail should be in JPEG format and less than 200 KB in size.
|
||||
@ -61,6 +65,7 @@ class InputMediaAudio(InputMedia):
|
||||
def __init__(
|
||||
self,
|
||||
media: str,
|
||||
file_ref: str = None,
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
@ -68,7 +73,7 @@ class InputMediaAudio(InputMedia):
|
||||
performer: int = "",
|
||||
title: str = ""
|
||||
):
|
||||
super().__init__(media, caption, parse_mode)
|
||||
super().__init__(media, file_ref, caption, parse_mode)
|
||||
|
||||
self.thumb = thumb
|
||||
self.duration = duration
|
||||
|
@ -30,6 +30,10 @@ class InputMediaDocument(InputMedia):
|
||||
Pass a file_id as string to send a file that exists on the Telegram servers or
|
||||
pass a file path as string to upload a new file that exists on your local machine.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
thumb (``str``):
|
||||
Thumbnail of the file sent.
|
||||
The thumbnail should be in JPEG format and less than 200 KB in size.
|
||||
@ -50,10 +54,11 @@ class InputMediaDocument(InputMedia):
|
||||
def __init__(
|
||||
self,
|
||||
media: str,
|
||||
file_ref: str = None,
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object
|
||||
):
|
||||
super().__init__(media, caption, parse_mode)
|
||||
super().__init__(media, file_ref, caption, parse_mode)
|
||||
|
||||
self.thumb = thumb
|
||||
|
@ -32,6 +32,10 @@ class InputMediaPhoto(InputMedia):
|
||||
pass a file path as string to upload a new photo that exists on your local machine.
|
||||
Sending photo by a URL is currently unsupported.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
caption (``str``, *optional*):
|
||||
Caption of the photo to be sent, 0-1024 characters
|
||||
|
||||
@ -46,7 +50,8 @@ class InputMediaPhoto(InputMedia):
|
||||
def __init__(
|
||||
self,
|
||||
media: str,
|
||||
file_ref: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object
|
||||
):
|
||||
super().__init__(media, caption, parse_mode)
|
||||
super().__init__(media, file_ref, caption, parse_mode)
|
||||
|
@ -32,6 +32,10 @@ class InputMediaVideo(InputMedia):
|
||||
pass a file path as string to upload a new video that exists on your local machine.
|
||||
Sending video by a URL is currently unsupported.
|
||||
|
||||
file_ref (``str``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
To be used in combination with a file id in case a file reference is needed.
|
||||
|
||||
thumb (``str``):
|
||||
Thumbnail of the video sent.
|
||||
The thumbnail should be in JPEG format and less than 200 KB in size.
|
||||
@ -64,6 +68,7 @@ class InputMediaVideo(InputMedia):
|
||||
def __init__(
|
||||
self,
|
||||
media: str,
|
||||
file_ref: str = None,
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
@ -72,7 +77,7 @@ class InputMediaVideo(InputMedia):
|
||||
duration: int = 0,
|
||||
supports_streaming: bool = True
|
||||
):
|
||||
super().__init__(media, caption, parse_mode)
|
||||
super().__init__(media, file_ref, caption, parse_mode)
|
||||
|
||||
self.thumb = thumb
|
||||
self.width = width
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class Animation(Object):
|
||||
@ -33,7 +33,7 @@ class Animation(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
@ -66,7 +66,7 @@ class Animation(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
width: int,
|
||||
height: int,
|
||||
duration: int,
|
||||
@ -106,7 +106,7 @@ class Animation(Object):
|
||||
animation.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=animation.file_reference,
|
||||
file_ref=encode_file_ref(animation.file_reference),
|
||||
width=getattr(video_attributes, "w", 0),
|
||||
height=getattr(video_attributes, "h", 0),
|
||||
duration=getattr(video_attributes, "duration", 0),
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class Audio(Object):
|
||||
@ -33,7 +33,7 @@ class Audio(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
duration (``int``):
|
||||
@ -66,7 +66,7 @@ class Audio(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
duration: int,
|
||||
file_name: str = None,
|
||||
mime_type: str = None,
|
||||
@ -106,7 +106,7 @@ class Audio(Object):
|
||||
audio.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=audio.file_reference,
|
||||
file_ref=encode_file_ref(audio.file_reference),
|
||||
duration=audio_attributes.duration,
|
||||
performer=audio_attributes.performer,
|
||||
title=audio_attributes.title,
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class Document(Object):
|
||||
@ -33,7 +33,7 @@ class Document(Object):
|
||||
file_id (``str``):
|
||||
Unique file identifier.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
file_name (``str``, *optional*):
|
||||
@ -57,7 +57,7 @@ class Document(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
file_name: str = None,
|
||||
mime_type: str = None,
|
||||
file_size: int = None,
|
||||
@ -86,7 +86,7 @@ class Document(Object):
|
||||
document.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=document.file_reference,
|
||||
file_ref=encode_file_ref(document.file_reference),
|
||||
file_name=file_name,
|
||||
mime_type=document.mime_type,
|
||||
file_size=document.size,
|
||||
|
@ -2642,20 +2642,28 @@ class Message(Object, Update):
|
||||
|
||||
if self.photo:
|
||||
file_id = self.photo.file_id
|
||||
file_ref = self.photo.file_ref
|
||||
elif self.audio:
|
||||
file_id = self.audio.file_id
|
||||
file_ref = self.audio.file_ref
|
||||
elif self.document:
|
||||
file_id = self.document.file_id
|
||||
file_ref = self.document.file_ref
|
||||
elif self.video:
|
||||
file_id = self.video.file_id
|
||||
file_ref = self.video.file_ref
|
||||
elif self.animation:
|
||||
file_id = self.animation.file_id
|
||||
file_ref = self.animation.file_ref
|
||||
elif self.voice:
|
||||
file_id = self.voice.file_id
|
||||
file_ref = self.voice.file_ref
|
||||
elif self.sticker:
|
||||
file_id = self.sticker.file_id
|
||||
file_ref = self.sticker.file_ref
|
||||
elif self.video_note:
|
||||
file_id = self.video_note.file_id
|
||||
file_ref = self.video_note.file_ref
|
||||
elif self.contact:
|
||||
return self._client.send_contact(
|
||||
chat_id,
|
||||
@ -2700,9 +2708,9 @@ class Message(Object, Update):
|
||||
raise ValueError("Unknown media type")
|
||||
|
||||
if self.sticker or self.video_note: # Sticker and VideoNote should have no caption
|
||||
return send_media(file_id=file_id)
|
||||
return send_media(file_id=file_id, file_ref=file_ref)
|
||||
else:
|
||||
return send_media(file_id=file_id, caption=caption, parse_mode="html")
|
||||
return send_media(file_id=file_id, file_ref=file_ref, caption=caption, parse_mode="html")
|
||||
else:
|
||||
raise ValueError("Can't copy this message")
|
||||
else:
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class Photo(Object):
|
||||
@ -33,7 +33,7 @@ class Photo(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this photo.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
@ -57,7 +57,7 @@ class Photo(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
width: int,
|
||||
height: int,
|
||||
file_size: int,
|
||||
@ -88,7 +88,7 @@ class Photo(Object):
|
||||
big.location.local_id
|
||||
)
|
||||
),
|
||||
file_ref=photo.file_reference,
|
||||
file_ref=encode_file_ref(photo.file_reference),
|
||||
width=big.w,
|
||||
height=big.h,
|
||||
file_size=big.size,
|
||||
|
@ -25,7 +25,7 @@ from pyrogram.api import types, functions
|
||||
from pyrogram.errors import StickersetInvalid
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class Sticker(Object):
|
||||
@ -35,7 +35,7 @@ class Sticker(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
@ -76,7 +76,7 @@ class Sticker(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
width: int,
|
||||
height: int,
|
||||
is_animated: bool,
|
||||
@ -140,7 +140,7 @@ class Sticker(Object):
|
||||
sticker.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=sticker.file_reference,
|
||||
file_ref=encode_file_ref(sticker.file_reference),
|
||||
width=image_size_attributes.w if image_size_attributes else 512,
|
||||
height=image_size_attributes.h if image_size_attributes else 512,
|
||||
is_animated=sticker.mime_type == "application/x-tgsticker",
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class Video(Object):
|
||||
@ -33,7 +33,7 @@ class Video(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
@ -69,7 +69,7 @@ class Video(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
width: int,
|
||||
height: int,
|
||||
duration: int,
|
||||
@ -111,7 +111,7 @@ class Video(Object):
|
||||
video.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=video.file_reference,
|
||||
file_ref=encode_file_ref(video.file_reference),
|
||||
width=video_attributes.w,
|
||||
height=video_attributes.h,
|
||||
duration=video_attributes.duration,
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class VideoNote(Object):
|
||||
@ -33,7 +33,7 @@ class VideoNote(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
length (``int``):
|
||||
@ -60,7 +60,7 @@ class VideoNote(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
length: int,
|
||||
duration: int,
|
||||
thumbs: List[Thumbnail] = None,
|
||||
@ -91,7 +91,7 @@ class VideoNote(Object):
|
||||
video_note.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=video_note.file_reference,
|
||||
file_ref=encode_file_ref(video_note.file_reference),
|
||||
length=video_attributes.w,
|
||||
duration=video_attributes.duration,
|
||||
file_size=video_note.size,
|
||||
|
@ -21,7 +21,7 @@ from struct import pack
|
||||
import pyrogram
|
||||
from pyrogram.api import types
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
|
||||
|
||||
class Voice(Object):
|
||||
@ -31,7 +31,7 @@ class Voice(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
file_ref (``str``):
|
||||
Up to date file reference.
|
||||
|
||||
duration (``int``):
|
||||
@ -55,7 +55,7 @@ class Voice(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_ref: str,
|
||||
duration: int,
|
||||
waveform: bytes = None,
|
||||
mime_type: str = None,
|
||||
@ -84,7 +84,7 @@ class Voice(Object):
|
||||
voice.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=voice.file_reference,
|
||||
file_ref=encode_file_ref(voice.file_reference),
|
||||
duration=attributes.duration,
|
||||
mime_type=voice.mime_type,
|
||||
file_size=voice.size,
|
||||
|
Loading…
x
Reference in New Issue
Block a user