from __future__ import annotations def generate_dingding_chat_id(raw: dict, chat_type: str) -> str: if chat_type == "direct": sender_id = raw.get("senderId", "") return f"dm_{sender_id}" conversation_id = raw.get("conversationId", "") return f"group_{conversation_id}" def resolve_dingding_chat_type(raw: dict) -> str: is_group = raw.get("isGroupChat", False) return "group" if is_group else "direct" def generate_thread_key(channel_id: str, chat_id: str) -> str: if chat_id.startswith("dm_"): return f"{channel_id}:direct:{chat_id}" return f"{channel_id}:group:{chat_id}"