fix(telegram): mirror remaining gateway sends
This commit is contained in:
@@ -3645,10 +3645,7 @@ class TelegramGateway:
|
||||
}
|
||||
if _orig_msg:
|
||||
_payload["reply_to_message_id"] = _orig_msg
|
||||
await self._http_client.post(
|
||||
f"https://api.telegram.org/bot{settings.OPENCLAW_TG_BOT_TOKEN}/sendMessage",
|
||||
json=_payload,
|
||||
)
|
||||
await self._send_request("sendMessage", _payload)
|
||||
except Exception as _re:
|
||||
logger.warning("category_action_reply_send_failed", error=str(_re))
|
||||
|
||||
@@ -4762,10 +4759,7 @@ class TelegramGateway:
|
||||
}
|
||||
if orig_msg_id:
|
||||
payload["reply_to_message_id"] = orig_msg_id
|
||||
await self._http_client.post(
|
||||
f"https://api.telegram.org/bot{settings.OPENCLAW_TG_BOT_TOKEN}/sendMessage",
|
||||
json=payload,
|
||||
)
|
||||
await self._send_request("sendMessage", payload)
|
||||
logger.info(
|
||||
"category_action_reply_sent",
|
||||
action=action,
|
||||
@@ -5267,7 +5261,7 @@ class TelegramGateway:
|
||||
parse_mode: str = "HTML",
|
||||
) -> dict:
|
||||
"""
|
||||
用指定 Bot Token 發訊息(不走 self._http_client,獨立建立請求)
|
||||
用指定 Bot Token 發訊息。
|
||||
|
||||
Args:
|
||||
token: Bot Token
|
||||
@@ -5298,7 +5292,15 @@ class TelegramGateway:
|
||||
|
||||
response = await self._http_client.post(url, json=payload)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
result = response.json()
|
||||
result_val = result.get("result") if isinstance(result, dict) else None
|
||||
if isinstance(result_val, dict) and "message_id" in result_val:
|
||||
await self._mirror_outbound_message(
|
||||
method="sendMessage",
|
||||
payload=payload,
|
||||
provider_message_id=str(result_val["message_id"]),
|
||||
)
|
||||
return result
|
||||
|
||||
async def send_as_openclaw(
|
||||
self,
|
||||
@@ -6179,9 +6181,9 @@ class TelegramGateway:
|
||||
{"text": "📋 詳情", "callback_data": f"detail:{incident_id}"},
|
||||
{"text": "📊 歷史", "callback_data": f"history:{incident_id}"},
|
||||
]]
|
||||
await self._http_client.post(
|
||||
f"https://api.telegram.org/bot{settings.OPENCLAW_TG_BOT_TOKEN}/editMessageReplyMarkup",
|
||||
json={
|
||||
await self._send_request(
|
||||
"editMessageReplyMarkup",
|
||||
{
|
||||
"chat_id": chat_id,
|
||||
"message_id": orig_msg_id,
|
||||
"reply_markup": {"inline_keyboard": info_buttons},
|
||||
@@ -6193,9 +6195,9 @@ class TelegramGateway:
|
||||
|
||||
try:
|
||||
# 2. 在原訊息下回覆狀態
|
||||
await self._http_client.post(
|
||||
f"https://api.telegram.org/bot{settings.OPENCLAW_TG_BOT_TOKEN}/sendMessage",
|
||||
json={
|
||||
await self._send_request(
|
||||
"sendMessage",
|
||||
{
|
||||
"chat_id": chat_id,
|
||||
"text": status_line,
|
||||
"parse_mode": "HTML",
|
||||
|
||||
@@ -4474,3 +4474,30 @@ outbound_message_recorded -> observed 2 rows, project_id=awoooi, send_status=sen
|
||||
```
|
||||
|
||||
判讀:成本告警、審批執行結果、自愈 rollback 提案三條原本 direct Bot API 路徑,已跟隨正式 API image 收斂到 `TelegramGateway._send_request()`。這些訊息接下來會被 outbound mirror 捕捉,讓 AwoooP 可以逐步成為 Telegram 訊息治理的資料來源。
|
||||
|
||||
### 00:48 Telegram Gateway 內部直送收斂
|
||||
|
||||
**改動**:
|
||||
|
||||
- `telegram_gateway.py` 內部 category action reply 與 approval status reply 改走 `TelegramGateway._send_request()`。
|
||||
- 多 Bot `_send_as_bot()` 因需指定 bot token,保留 direct Telegram HTTP,但成功送出後同樣呼叫 `_mirror_outbound_message()`。
|
||||
|
||||
**驗證**:
|
||||
|
||||
```text
|
||||
/Users/ogt/awoooi/apps/api/.venv/bin/python -m py_compile \
|
||||
apps/api/src/services/telegram_gateway.py
|
||||
# passed
|
||||
|
||||
DATABASE_URL='postgresql+asyncpg://test:test@localhost:5432/test' \
|
||||
/Users/ogt/awoooi/apps/api/.venv/bin/python -m pytest \
|
||||
apps/api/tests/test_telegram_message_templates.py -q
|
||||
# 22 passed
|
||||
|
||||
rg direct sendMessage:
|
||||
剩餘 2 條:
|
||||
- channel_hub.py progressive feedback:已由 record_outbound_message 先落庫
|
||||
- telegram_gateway.py _send_as_bot:custom token direct HTTP,但成功後 mirror
|
||||
```
|
||||
|
||||
判讀:Telegram 出站治理目前已達到「可觀測優先」狀態。下一步不應再硬改發送器,而是做 firing alert fingerprint 聚合與 AwoooP Timeline UI,避免同一事件在群組內形成訊息洪水。
|
||||
|
||||
@@ -40,6 +40,7 @@ Telegram 不應是完整執行日誌,也不應承載所有 AI 推理細節。T
|
||||
- `append_incident_update()` 對相同的「AI 自動修復失敗 / AI 診斷工具失敗」摘要增加 10 分鐘跨 incident 去重;每個 incident 仍會移除原卡危險按鈕,但 Telegram 不再重複 reply 同一個失敗摘要。
|
||||
- `TelegramGateway._send_request()` 對成功送出的 legacy `sendMessage` 增加 AwoooP `awooop_outbound_message` 鏡像。鏡像失敗只記錄 `telegram_outbound_mirror_failed`,不能影響 Telegram 正常送達。
|
||||
- 成本告警、審批執行結果、自愈 rollback 提案已由 direct Bot API 改走 `TelegramGateway._send_request()`,避免繞過 outbound mirror。
|
||||
- `telegram_gateway.py` 內部歷史直打 `sendMessage` 路徑已收斂;多 Bot `_send_as_bot()` 因需指定 token 保留 direct HTTP,但成功後同樣鏡像到 `awooop_outbound_message`。
|
||||
- 既有 `詳情 / 重診 / 歷史` 按鈕保留,讓 Telegram 保持輕量,細節回到控制台。
|
||||
|
||||
## 後續建議
|
||||
|
||||
Reference in New Issue
Block a user