def parse_incoming_chat_message(data: str | dict):
    """
    The expected format of data is
    {
      user: {
        id: string
      }
      chat: {
        id: string
      }
      message: {
        type: 'text' | 'voice' | ...
        content: string
        id: string
      }
    }
    """
    result = IncomingChatMessage()
    try:
        if isinstance(data, dict):
            obj = data
        else:
            obj = json.loads(data)
        result.user_id = obj["user"]["id"]
        result.chat_id = obj["chat"]["id"]
        result.message_type = obj["message"]["type"]
        result.message_id = obj["message"]["id"]
        result.message_content = obj["message"]["content"]
        # TODO: Check if they are str
        return result
    except Exception as e:
        logger.debug(f"An invalid message from session: {data}")
        return None

    The expected format of data is
    {
      user: {
        id: string
      }
      chat: {
        id: string
      }
      message: {
        type: 'text' | 'voice' | ...
        content: string
        id: string
      }
    }
    
PoC/agent_jarvis/jarvis/utils/incoming_chat_message_parser.py