import json class ConfluenceMentions: @staticmethod def extract_mentions(raw_message: dict) -> list[dict]: body = raw_message.get("body", {}) adf_raw = body.get("atlas_doc_format", {}).get("value", "") try: doc = json.loads(adf_raw) if isinstance(adf_raw, str) else adf_raw except (json.JSONDecodeError, TypeError): return [] mentions = [] def _walk(node): if isinstance(node, dict): if node.get("type") == "mention": attrs = node.get("attrs", {}) mentions.append({ "account_id": attrs.get("id", ""), "display_name": attrs.get("text", "").lstrip("@"), }) for child in node.get("content", []): _walk(child) elif isinstance(node, list): for item in node: _walk(item) _walk(doc) return mentions @staticmethod def build_mention(account_id: str, display_name: str) -> dict: from yuxi.channel.extensions.confluence.format import ADFBuilder return ADFBuilder.mention(account_id, display_name)