fix(api): 收斂 direct Telegram sendMessage 告警
Some checks failed
Code Review / ai-code-review (push) Successful in 14s
CD Pipeline / tests (push) Successful in 1m39s
Ansible / Reboot Recovery Contract / validate (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled

This commit is contained in:
Your Name
2026-06-18 18:45:34 +08:00
parent 5e8492256e
commit d06203cbae
5 changed files with 77 additions and 0 deletions

View File

@@ -393,6 +393,28 @@ def normalize_alert_notification_payload(text: str, parse_mode: str) -> tuple[st
return text, parse_mode
def normalize_telegram_send_message_payload(method: str, payload: dict) -> dict:
"""所有 sendMessage 出口都必須套用告警脫敏與事件卡格式。"""
if method != "sendMessage":
return payload
text = payload.get("text")
if not isinstance(text, str):
return payload
safe_text, effective_parse_mode = normalize_alert_notification_payload(
text,
str(payload.get("parse_mode") or "HTML"),
)
if safe_text == text and effective_parse_mode == payload.get("parse_mode"):
return payload
normalized_payload = dict(payload)
normalized_payload["text"] = safe_text[:4096]
normalized_payload["parse_mode"] = effective_parse_mode
return normalized_payload
def _top_gateway_bucket(
buckets: list[dict[str, object]],
field: str,
@@ -4039,6 +4061,7 @@ class TelegramGateway:
if not self._http_client:
raise TelegramGatewayError("HTTP client not initialized")
payload = normalize_telegram_send_message_payload(method, payload)
source_envelope_extra = payload.pop(_AWOOOP_SOURCE_ENVELOPE_EXTRA_KEY, None)
await self._attach_incident_thread_reply(method, payload)