40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from yuxi.channels.models import ChannelIdentity
|
|||
|
|
|
|||
|
|
|
|||
|
|
def format_inbound_envelope(
|
|||
|
|
identity: ChannelIdentity,
|
|||
|
|
sender_name: str = "",
|
|||
|
|
chat_name: str = "",
|
|||
|
|
reply_context: dict | None = None,
|
|||
|
|
) -> str:
|
|||
|
|
"""生成标准入站信封格式。
|
|||
|
|
|
|||
|
|
格式示例:
|
|||
|
|
[From: Alice (alice@icloud.com)] @Family Chat
|
|||
|
|
"""
|
|||
|
|
parts: list[str] = []
|
|||
|
|
|
|||
|
|
sender_display = sender_name or identity.channel_user_id
|
|||
|
|
parts.append(f"[From: {sender_display}")
|
|||
|
|
|
|||
|
|
if identity.channel_user_id != sender_display:
|
|||
|
|
parts.append(f" ({identity.channel_user_id})")
|
|||
|
|
|
|||
|
|
parts.append("]")
|
|||
|
|
|
|||
|
|
if chat_name:
|
|||
|
|
parts.append(f" @{chat_name}")
|
|||
|
|
|
|||
|
|
if reply_context:
|
|||
|
|
reply_to_id = reply_context.get("reply_to_message_id")
|
|||
|
|
reply_to_text = reply_context.get("reply_to_text")
|
|||
|
|
if reply_to_text:
|
|||
|
|
preview = reply_to_text[:80].replace("\n", " ")
|
|||
|
|
parts.append(f"\n > Replying to: {preview}")
|
|||
|
|
elif reply_to_id:
|
|||
|
|
parts.append(f"\n > Replying to message id:{reply_to_id}")
|
|||
|
|
|
|||
|
|
return "".join(parts)
|