fix(telegram+review): 修復 PPT 按鈕無反應 + Code Review 頁面空白
All checks were successful
CD Pipeline / deploy (push) Successful in 1m28s

PPT 按鈕:
- telegram_bot_service.py 新增 cmd:* handler,透過 Thread 轉發到
  OpenClaw Flask 內部 API(/bot/internal/cmd)
- openclaw_bot_routes.py 新增 /bot/internal/cmd 端點,背景執行 handle_cmd()

Code Review 頁面:
- get_history() 補回 findings / openclaw_report 欄位
- code_review.html history 項目可點擊,自動載入詳細內容
- poll() 無 active pipeline 時自動顯示最新歷史記錄

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ogt
2026-04-22 08:56:10 +08:00
parent 5761aeb1ce
commit b11789db77
4 changed files with 93 additions and 2 deletions

View File

@@ -611,6 +611,8 @@ def get_history(limit: int = 20) -> List[Dict]:
"severity_summary": sev,
"total_issues": sum(sev.values()),
"auto_fix": meta.get("auto_fix_triggered", False),
"findings": content.get("findings", []),
"openclaw_report": content.get("openclaw_report", ""),
"ea_decision": content.get("ea_decision", {}),
"created_at": r[4].isoformat() if r[4] else "",
"status": r[5] or "active",

View File

@@ -488,6 +488,34 @@ class TrendTelegramBot:
elif data.startswith("momo:ops:"):
await self._handle_ops_callback(query, data)
# ===== OpenClaw 指令按鈕cmd:<cmd>:<arg>=====
elif data.startswith("cmd:"):
parts = data[4:].split(":", 1)
cmd = parts[0]
arg = parts[1] if len(parts) > 1 else ""
chat_id = query.message.chat_id
import threading as _t
_t.Thread(
target=self._forward_cmd_to_openclaw,
args=(cmd, arg, chat_id),
daemon=True,
).start()
def _forward_cmd_to_openclaw(self, cmd: str, arg: str, chat_id: int):
"""轉發 cmd:* 指令到 OpenClaw Flask 內部 API"""
import requests as _req
try:
internal_url = os.getenv("OPENCLAW_INTERNAL_URL", "http://momo-pro-system:80")
token = os.getenv("INTERNAL_WEBHOOK_TOKEN", "")
_req.post(
f"{internal_url}/bot/internal/cmd",
json={"chat_id": chat_id, "cmd": cmd, "arg": arg},
headers={"X-Internal-Token": token},
timeout=10,
)
except Exception as e:
logger.warning(f"[TelegramBot] forward cmd failed: {e}")
async def _handle_main_menu_callback(self, query, data: str):
"""處理主選單回調 - 完整功能菜單系統"""
key = data[5:] # 移除 'menu:' 前綴