diff --git a/apps/api/src/services/telegram_gateway.py b/apps/api/src/services/telegram_gateway.py index 036f1a59..abc531a2 100644 --- a/apps/api/src/services/telegram_gateway.py +++ b/apps/api/src/services/telegram_gateway.py @@ -3066,7 +3066,8 @@ class TelegramGateway: is_sre_group = str(chat_id) == str(settings.SRE_GROUP_CHAT_ID) if is_group and is_sre_group: - await self._handle_group_message(text, user_id, username, chat_id, message_id) + reply_to_message = message.get("reply_to_message") + await self._handle_group_message(text, user_id, username, chat_id, message_id, reply_to_message) return # 2. 個人 chat 安全檢查 (ADR-012) @@ -3109,14 +3110,17 @@ class TelegramGateway: username: str, chat_id: int, # noqa: ARG002 message_id: int | None, + reply_to_message: dict | None = None, ) -> None: """ 處理 SRE 群組訊息 (2026-04-03 ogt: Phase 22.6 Triumvirate) 路由規則: - @OpenClawAwoooI_Bot → 只有 OpenClaw 回應 - @NemoTronAwoooI_Bot → 只有 NemoClaw 回應 - 其他訊息 → 兩個 AI 並行回應,互相看到後可評論 + Reply OpenClaw 訊息 → 只有 OpenClaw 回應 + Reply NemoClaw 訊息 → 只有 NemoClaw 回應 + @OpenClawAwoooI_Bot → 只有 OpenClaw 回應 + @NemoTronAwoooI_Bot → 只有 NemoClaw 回應 + 其他訊息 → 兩個 AI 並行回應 """ from src.services.chat_manager import get_chat_manager as _get_cm chat_mgr = _get_cm() @@ -3124,9 +3128,26 @@ class TelegramGateway: # 全形/半形統一化後比較 import unicodedata text_normalized = unicodedata.normalize("NFKC", text).lower() - # 別名: 小O / 小o (含全形O) → OpenClaw; 小賀 / 小贺 → NemoClaw - mention_openclaw = "@openclawawoooi_bot" in text_normalized or "小o" in text_normalized - mention_nemo = "@nemotronawoooi_bot" in text_normalized or "小賀" in text_normalized or "小贺" in text_normalized + + # Reply 路由: 若 Reply 的是 Bot 訊息,直接認定目標 AI (2026-04-03 ogt) + if reply_to_message: + replied_from = reply_to_message.get("from", {}) + if replied_from.get("is_bot"): + replied_username = (replied_from.get("username") or "").lower() + if "openclawawoooi" in replied_username: + mention_openclaw, mention_nemo = True, False + elif "nemotronawoooi" in replied_username: + mention_openclaw, mention_nemo = False, True + else: + mention_openclaw = "@openclawawoooi_bot" in text_normalized or "小o" in text_normalized + mention_nemo = "@nemotronawoooi_bot" in text_normalized or "小賀" in text_normalized or "小贺" in text_normalized + else: + mention_openclaw = "@openclawawoooi_bot" in text_normalized or "小o" in text_normalized + mention_nemo = "@nemotronawoooi_bot" in text_normalized or "小賀" in text_normalized or "小贺" in text_normalized + else: + # 別名: 小O / 小o (含全形O) → OpenClaw; 小賀 / 小贺 → NemoClaw + mention_openclaw = "@openclawawoooi_bot" in text_normalized or "小o" in text_normalized + mention_nemo = "@nemotronawoooi_bot" in text_normalized or "小賀" in text_normalized or "小贺" in text_normalized # 去掉 @ mention 與別名,取出純訊息 clean_text = unicodedata.normalize("NFKC", text)