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
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user