Explorar el Código

fix(auto_put_ad_mini): 飞书审批轮询增加 HTTP 兜底,修复 WebSocket 断连时无法检测回复

local_chat_history 模式依赖 WebSocket 推送写入本地文件,当 WebSocket 断连时
审批回复永远无法被检测到。改为双通道:本地每 1 秒检测 + HTTP API 每 30 秒兜底。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
刘立冬 hace 2 semanas
padre
commit
50bab4b8bd
Se han modificado 1 ficheros con 6 adiciones y 4 borrados
  1. 6 4
      examples/auto_put_ad_mini/tools/im_approval.py

+ 6 - 4
examples/auto_put_ad_mini/tools/im_approval.py

@@ -719,12 +719,12 @@ async def send_approval_request(
                 },
             )
 
-        # ═══ 等待飞书回复(优先读本地 chat_history,回退到 HTTP 轮询)═══
+        # ═══ 等待飞书回复(本地 chat_history + HTTP 轮询双通道)═══
         timeout_at = datetime.now() + timedelta(minutes=timeout_minutes)
         use_local_poll = bool(_operator_contact_name)
         logger.info(
             "等待审批回复:mode=%s,超时 %d 分钟",
-            "local_chat_history" if use_local_poll else "http_poll",
+            "local+http" if use_local_poll else "http_poll",
             timeout_minutes,
         )
 
@@ -781,9 +781,11 @@ async def send_approval_request(
                         )
                 except Exception as e:
                     logger.debug("读取 chat_history 失败(将重试): %s", e)
-                continue  # 跳过 HTTP 轮询
+                # 每 30 秒同时尝试 HTTP 轮询(兜底:WebSocket 断连时仍可检测)
+                if poll_count % 30 != 0:
+                    continue
 
-            # ─── 回退:HTTP 轮询(原有逻辑,仅在联系人未配置时使用)───
+            # ─── HTTP 轮询(主通道 / 每 30 秒兜底)───
             try:
                 for chat_id in poll_chat_ids:
                     result = _feishu.get_message_list(