fix(phase22): 修復 Telegram 對話三個 Bug (ADR-044)
All checks were successful
E2E Health Check / e2e-health (push) Successful in 18s

P0: security_interceptor.py 新增 intercept_telegram() 方法
- 修復 _handle_chat_message 的 AttributeError (致命 Bug)
- 白名單驗證,不需要 Nonce (對話訊息 vs 按鈕回調)

P1: nvidia_provider.py chat() 新增 use_json_mode 參數
- 對話場景預設 False (自然語言回應)
- RCA/分析場景傳入 True (結構化 JSON 輸出)
- openclaw.py RCA 呼叫加上 use_json_mode=True

P2: K8s ConfigMap 啟用 TELEGRAM_ENABLE_POLLING=true
- K8s AWOOOI API 接管 @tsenyangbot Long Polling
- OpenClaw (188) 停止 Telegram,改為純 REST 服務

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-31 21:53:09 +08:00
parent 589f2fc4c7
commit cc6b18e3bc
4 changed files with 29 additions and 5 deletions

View File

@@ -660,12 +660,15 @@ class NvidiaProvider:
model: str | None = None,
temperature: float = 0.1,
max_tokens: int = 2048,
use_json_mode: bool = False,
) -> tuple[str, bool, int, float]:
"""
一般對話 (非 Tool Calling) - 用於 RCA 分析
一般對話 (非 Tool Calling) - 用於 RCA 分析或自由對話
2026-03-29 ogt: 新增,符合模組化規範
從 openclaw.py 遷移,統一由 NvidiaProvider 處理所有 NVIDIA API 呼叫
2026-03-31 ogt: 新增 use_json_mode 參數 (Phase 22 修復)
- RCA/分析場景: use_json_mode=True (結構化輸出)
- 對話場景: use_json_mode=False (預設,自然語言回應)
Args:
prompt: 對話內容
@@ -726,7 +729,7 @@ class NvidiaProvider:
"messages": [{"role": "user", "content": prompt}],
"temperature": temperature,
"max_tokens": max_tokens,
"response_format": {"type": "json_object"},
**({"response_format": {"type": "json_object"}} if use_json_mode else {}),
},
)
response.raise_for_status()

View File

@@ -884,7 +884,7 @@ class OpenClawService:
# 2026-03-29 ogt: 使用 NvidiaProvider.chat() (模組化規範)
from src.services.nvidia_provider import get_nvidia_provider
nvidia_provider = get_nvidia_provider()
response, success, total_tokens, cost_usd = await nvidia_provider.chat(prompt)
response, success, total_tokens, cost_usd = await nvidia_provider.chat(prompt, use_json_mode=True)
elif provider == "claude":
response, success = await self._call_claude(prompt)
else:

View File

@@ -270,6 +270,25 @@ class TelegramSecurityInterceptor:
return is_allowed
async def intercept_telegram(self, user_id: int) -> None:
"""
攔截 Telegram 文字訊息 (ADR-044 Phase 22)
用於 _handle_chat_message 的白名單驗證。
與 verify_callback 不同,純文字訊息不需要 Nonce 防重放。
Args:
user_id: Telegram user ID
Raises:
UserNotWhitelistedError: user_id 不在白名單內
"""
# 2026-03-31 ogt: Phase 22 修復 - 補齊對話訊息的安全攔截方法
if not self.is_whitelisted(user_id):
raise UserNotWhitelistedError(
f"User {user_id} is not in the chat whitelist"
)
async def verify_callback(
self,
user_id: int,

View File

@@ -43,11 +43,13 @@ data:
# ============================================================================
# Phase 22: OpenClaw + Nemotron 協作 (ADR-044)
# 2026-03-31 ogt: 統帥需求 - @tsenyangbot 同時顯示 OpenClaw 仲裁 + Nemotron 執行
# 2026-03-31 ogt: 統帥需求 - @tsenyangbot 對話 + Incident 雙軌
# ============================================================================
ENABLE_NEMOTRON_COLLABORATION: "true"
NEMOTRON_TIMEOUT_SECONDS: "45"
NEMOTRON_ASYNC_UPDATE: "true"
# K8s 接管 @tsenyangbot Long Polling (停用 OpenClaw 188 Telegram)
TELEGRAM_ENABLE_POLLING: "true"
# 快取 TTL (秒)
CACHE_TTL_DASHBOARD: "300"