ForcePilot/backend/package/yuxi/channel/channels/web/translator.py

26 lines
857 B
Python
Raw Normal View History

from __future__ import annotations
from yuxi.channel.domain.model.message.peer import Peer
from yuxi.channel.domain.model.message.unified_message import UnifiedMessage
from yuxi.channel.domain.model.shared.channel_type import ChannelType
class WebTranslator:
@staticmethod
def translate_message(raw: dict) -> UnifiedMessage:
return UnifiedMessage(
message_id=raw.get("id", ""),
channel_type=ChannelType.WEB,
sender=Peer(
id=raw.get("sender_id", ""),
name=raw.get("sender_name", ""),
kind="user",
),
content=raw.get("content", ""),
metadata={
**raw.get("metadata", {}),
"account_id": raw.get("account_id", raw.get("sender_id", "")),
},
raw_payload=raw,
)