diff --git a/apps/api/src/services/decision_manager.py b/apps/api/src/services/decision_manager.py index 4f0c0143..970c36b6 100644 --- a/apps/api/src/services/decision_manager.py +++ b/apps/api/src/services/decision_manager.py @@ -59,6 +59,18 @@ async def _push_decision_to_telegram( get_telegram_gateway, ) + # 2026-03-26 修復: 防止重複發送 Telegram (每 incident 10 分鐘只發一次) + redis_client = get_redis() + dedup_key = f"telegram_sent:{incident.incident_id}" + already_sent = await redis_client.get(dedup_key) + if already_sent: + logger.debug( + "telegram_push_skipped_dedup", + incident_id=incident.incident_id, + reason="Already sent within 10 minutes", + ) + return + # 檢查是否有設定 Bot Token if not settings.OPENCLAW_TG_BOT_TOKEN: logger.debug( @@ -79,8 +91,8 @@ async def _push_decision_to_telegram( confidence = proposal_data.get("confidence", 0.75) source = proposal_data.get("source", "unknown") - # 建立 approval_id (使用 incident_id 作為追蹤) - approval_id = f"INC-{incident.incident_id}" + # 2026-03-26 修復: incident_id 已有 INC- 前綴,不要再加 + approval_id = incident.incident_id await gateway.send_approval_card( approval_id=approval_id, @@ -94,6 +106,9 @@ async def _push_decision_to_telegram( namespace=incident.signals[0].labels.get("namespace", "default") if incident.signals else "default", ) + # 2026-03-26 修復: 標記已發送,10 分鐘內不再發送 + await redis_client.set(dedup_key, "1", ex=600) + logger.info( "telegram_decision_pushed", incident_id=incident.incident_id,