Skip to content

whatsapie/schema_generator/media_schema.py

generate_media_schema(body, message)

Generate schema for Media.

Parameters:

Name Type Description Default
body dict

Parent api schema object.

required
message Media

Media instance.

required

Returns:

Name Type Description
body

Schema body

Source code in whatsapie/schema_generator/media_schema.py
def generate_media_schema(body: dict, message: Media):
    """Generate schema for Media.

    Args:
        body: Parent api schema object.
        message: Media instance.

    Returns:
        body: Schema body
    """
    body["type"] = message.type
    body[message.type] = {"link": message.link}

    if message.type in CAPTION_ALLOWED_MEDIA_TYPES:
        body[message.type]["caption"] = message.caption

    if message.type in FILENAME_ALLOWED_MEDIA_TYPES:
        body[message.type]["filename"] = message.filename

    return body