ForcePilot/backend/package/yuxi/channel/extensions/workplace/mentions.py
Kris 7215418610 feat(channel): 添加企业微信、微博、WhatsApp 和 Workplace 渠道扩展
新增企业微信、微博、WhatsApp、Workplace 四个渠道扩展。

企业微信渠道扩展主要模块:config, gateway, webhook, webhook_bot, outbound, streaming, pairing, security, crypto, dedupe, persistent_dedupe, card, directory, events, externalcontact, media, mentions, menu, message, oauth, status

微博渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, passive_reply, broadcast, message, menu, media, subscription, template, status

WhatsApp 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, monitor, status

Workplace 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, challenge, groups, media, mentions, menu, monitor, persona, quick_reply, signature, subscriptions, template, threading, users, status
2026-05-21 12:01:56 +08:00

33 lines
983 B
Python

import re
import logging
logger = logging.getLogger(__name__)
MENTION_PATTERN = re.compile(r"@\[([^\]]+)\]\(mention:(\d+)\)")
class WorkplaceMentions:
@staticmethod
def extract_mentions(raw_message: dict) -> list[str]:
text = raw_message.get("message", {}).get("text", "")
if not text:
return []
matches = MENTION_PATTERN.findall(text)
mentioned_ids = [user_id for _, user_id in matches]
logger.debug("Extracted workplace mentions: %s", mentioned_ids)
return mentioned_ids
@staticmethod
def is_bot_mentioned(raw_message: dict, bot_page_id: str) -> bool:
text = raw_message.get("message", {}).get("text", "")
if not text:
return False
pattern = re.compile(rf"@\[([^\]]*)\]\(mention:({re.escape(bot_page_id)})\)")
return bool(pattern.search(text))
@staticmethod
def strip_mentions(text: str) -> str:
return MENTION_PATTERN.sub(r"@\1", text)