37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""企业微信归档中不属于患者聊天的系统会话过滤规则。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from typing import Any
|
|
|
|
_EXCLUDED_IDS = frozenset({"APPROVAL"})
|
|
_EXCLUDED_NAMES = frozenset(
|
|
{
|
|
"审批",
|
|
"企业微信团队",
|
|
"企业码会话管理",
|
|
}
|
|
)
|
|
|
|
|
|
def should_exclude_conversation(external_id: Any, display_name: Any = "") -> bool:
|
|
"""Return whether a conversation is a built-in/system notification channel.
|
|
|
|
``Y:`` is a WeCom application session and ``O:`` is a service session. The
|
|
approval feed uses a non-prefixed stable ID, while the built-in WeCom team
|
|
contact looks like an ordinary ``S:`` session and therefore needs its name.
|
|
"""
|
|
|
|
conversation_id = str(external_id or "").strip()
|
|
normalized_id = conversation_id.upper()
|
|
if normalized_id.startswith(("Y:", "O:")):
|
|
return True
|
|
if normalized_id in _EXCLUDED_IDS:
|
|
return True
|
|
normalized_name = re.sub(r"[\s\u3000]+", "", str(display_name or "")).strip()
|
|
return normalized_name in _EXCLUDED_NAMES
|
|
|
|
|
|
__all__ = ["should_exclude_conversation"]
|