From 665f93e83f5d05545e200d7ddc9fbcd76bf015ce Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 5 Apr 2026 13:07:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(telegram):=20=E9=A6=96=E5=B8=AD=E6=9E=B6?= =?UTF-8?q?=E6=A7=8B=E5=B8=AB=20R1=20=E4=BF=AE=E6=AD=A3=20=E2=80=94=20I-1/?= =?UTF-8?q?I-2/M-1/M-2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I-1: webhooks/sentry_webhook/signoz_webhook 三個呼叫者補 TODO 說明 無 incident_id 是已知限制(Approval 路徑未建 Incident 關聯) I-2: TestPushRequest 新增 incident_id 欄位,使 QA 可驗證按鈕渲染 M-1: 移除 _build_inline_keyboard 呼叫中多餘的 `or message.incident_id` M-2: 補充 900/1000 截斷長度差異說明 Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/api/v1/sentry_webhook.py | 1 + apps/api/src/api/v1/signoz_webhook.py | 1 + apps/api/src/api/v1/telegram.py | 3 +++ apps/api/src/api/v1/webhooks.py | 2 ++ apps/api/src/services/telegram_gateway.py | 4 ++-- 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/api/src/api/v1/sentry_webhook.py b/apps/api/src/api/v1/sentry_webhook.py index 4a3fdd00..8b2ff9f3 100644 --- a/apps/api/src/api/v1/sentry_webhook.py +++ b/apps/api/src/api/v1/sentry_webhook.py @@ -443,6 +443,7 @@ async def send_sentry_telegram_alert( level = error_context.get("level", "error") # 發送 Sentry 告警卡片 (含 Y/n 按鈕) + # TODO(2026-04-05): Sentry 路徑無 incident_id,待 Sentry→Incident 關聯後補傳 await telegram.send_approval_card( approval_id=approval_id, risk_level="high" if level in ["fatal", "error"] else "medium", diff --git a/apps/api/src/api/v1/signoz_webhook.py b/apps/api/src/api/v1/signoz_webhook.py index aec4bf01..3602c282 100644 --- a/apps/api/src/api/v1/signoz_webhook.py +++ b/apps/api/src/api/v1/signoz_webhook.py @@ -369,6 +369,7 @@ async def send_signoz_telegram( summary = annotations.get("summary", f"SignOz Alert: {alert_name}") description = annotations.get("description", "") + # TODO(2026-04-05): SignOz 路徑無 incident_id,待 SignOz→Incident 關聯後補傳 await telegram.send_approval_card( approval_id=approval_id, risk_level=analysis_result.risk_level if analysis_result else ( diff --git a/apps/api/src/api/v1/telegram.py b/apps/api/src/api/v1/telegram.py index 4a641300..e85932b2 100644 --- a/apps/api/src/api/v1/telegram.py +++ b/apps/api/src/api/v1/telegram.py @@ -60,6 +60,8 @@ class TestPushRequest(BaseModel): root_cause: str = "Test alert for development" suggested_action: str = "DELETE_POD" estimated_downtime: str = "~30s" + # 2026-04-05 Claude Code: 支援 incident_id 以測試第二排按鈕渲染 + incident_id: str = "" # ============================================================================= @@ -234,6 +236,7 @@ async def test_push( root_cause=request.root_cause, suggested_action=request.suggested_action, estimated_downtime=request.estimated_downtime, + incident_id=request.incident_id, ) return { diff --git a/apps/api/src/api/v1/webhooks.py b/apps/api/src/api/v1/webhooks.py index 1e61f493..70b53ed5 100644 --- a/apps/api/src/api/v1/webhooks.py +++ b/apps/api/src/api/v1/webhooks.py @@ -198,6 +198,8 @@ async def _push_to_telegram_background( if hit_count > 1: root_cause_with_count = f"[x{hit_count}] {root_cause}" + # TODO(2026-04-05): Alertmanager 路徑透過 Approval 建立,尚無 incident_id + # 待 Approval→Incident 關聯建立後,補傳 incident_id 以啟用 detail/reanalyze/history 按鈕 await gateway.send_approval_card( approval_id=approval_id, risk_level=risk_level, diff --git a/apps/api/src/services/telegram_gateway.py b/apps/api/src/services/telegram_gateway.py index 5916f751..50dbc5cb 100644 --- a/apps/api/src/services/telegram_gateway.py +++ b/apps/api/src/services/telegram_gateway.py @@ -293,7 +293,7 @@ class TelegramMessage: f"🔍 SignOz Trace" ) - return message[:900] + return message[:900] # 900 字元上限 (nemotron 版用 1000,因有額外 tool 區塊) def format_with_nemotron(self) -> str: """ @@ -1364,7 +1364,7 @@ class TelegramGateway: approval_id=approval_id, include_auto_tuning=bool(auto_tuning_command), auto_tuning_command=auto_tuning_command, - incident_id=incident_id or message.incident_id, + incident_id=incident_id, ) # 發送訊息