Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling InaccessibleMessage in get_media_id Function #387

Open
Latand opened this issue Apr 16, 2024 · 0 comments
Open

Handling InaccessibleMessage in get_media_id Function #387

Latand opened this issue Apr 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Latand
Copy link

Latand commented Apr 16, 2024

image

The get_media_id function is designed to extract the media ID from different types of media attachments in a message object.

Currently, it accepts a Message object and attempts to retrieve various media types (audio, animation, document, photo, video). However, the function does not account for scenarios where it might receive an InaccessibleMessage object, which lacks several attributes present in a standard Message.

To address this, the function needs to be updated to properly handle InaccessibleMessage objects by either gracefully failing or by implementing a check to ensure that only valid Message objects with accessible media attributes are processed.

The code, where this is happening:

def get_media_id(message: Message) -> Optional[MediaId]:
    media = (
        message.audio or
        message.animation or
        message.document or
        (message.photo[-1] if message.photo else None) or
        message.video
    )
    if not media:
        return None
    return MediaId(
        file_id=media.file_id,
        file_unique_id=media.file_unique_id,
    )
@Tishka17 Tishka17 added the bug Something isn't working label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants