LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.8k stars 1.39k forks source link

Issue in pack_bot_file_id method #4458

Closed chandan22140 closed 3 weeks ago

chandan22140 commented 3 weeks ago

Code that causes the issue

This is the code of the method having the issue.

def pack_bot_file_id(file):
    """
    Inverse operation for `resolve_bot_file_id`.

    The only parameters this method will accept are :tl:`Document` and
    :tl:`Photo`, and it will return a variable-length ``file_id`` string.

    If an invalid parameter is given, it will ``return None``.
    """
    if isinstance(file, types.MessageMediaDocument):
        file = file.document
    elif isinstance(file, types.MessageMediaPhoto):
        file = file.photo

    if isinstance(file, types.Document):
        file_type = 5
        for attribute in file.attributes:
            if isinstance(attribute, types.DocumentAttributeAudio):
                file_type = 3 if attribute.voice else 9
            elif isinstance(attribute, types.DocumentAttributeVideo):
                file_type = 13 if attribute.round_message else 4
            elif isinstance(attribute, types.DocumentAttributeSticker):
                file_type = 8
            elif isinstance(attribute, types.DocumentAttributeAnimated):
                file_type = 10
            else:
                continue
            break
        ret = _encode_telegram_base64(_rle_encode(struct.pack('<iiqqb', file_type, file.dc_id, file.id, file.access_hash, 2)))
        print("_encode_telegram_base64", ret)
        return ret

Expected behavior

On using this method, an year ago, I used to get a string of 71 characters as file_id as output of the method , which is expected "BQACAgUAAxkBAAIkeWbcpPid1R5UHBbQxaYFD5Siu8zOAAJlEgAC1xHoVq0YxoxvBTCiNgQ"

Actual behavior

On using this method right now, I get a string of 31 characters as file_id as the output of the method, which is not expected

"BQADBQADXRIAAtcR6Fass92SitfR7QI"

Traceback

No response

Telethon version

v1

Python version

3.12.5

Operating system (including distribution name and version)

Windows 11 64 bit

Other details

No response

Checklist

Lonami commented 3 weeks ago

This method is unfortunately broken and no longer maintained. It will be gone entirely from v2.

chandan22140 commented 3 weeks ago

Can you suggest any Alternative to this method which can provide the file-id given that telethon message.media is provided

On Mon, 9 Sept, 2024, 00:41 Lonami, @.***> wrote:

This method is unfortunately broken and no longer maintained. It will be gone entirely from v2.

— Reply to this email directly, view it on GitHub https://github.com/LonamiWebs/Telethon/issues/4458#issuecomment-2336793056, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4HXEGYUVKR4PNFXMYB53ULZVSOPVAVCNFSM6AAAAABN25WE6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZWG44TGMBVGY . You are receiving this because you authored the thread.Message ID: @.***>