from typing import Dict
from datetime import datetime


def message_timestamp(data: Dict) -> datetime:
    """
    Extract the timestamp from a Signal message and convert it to
    a proper datetime object.
    """
    try:
        timestamp_milliseconds = data["timestamp"]
    except KeyError as err:
        raise KeyError(f"Timestamp field is not present in data: {data}") from err

    dt = datetime.fromtimestamp(timestamp_milliseconds / 1000.0)
    return dt