|
|
@@ -486,24 +486,33 @@ async def send_approval_request(
|
|
|
feishu_sent = False
|
|
|
feishu_sent_to_project_chat = False
|
|
|
sent_time_sec = str(int(time.time())) # 飞书 API start_time 单位:秒
|
|
|
+ poll_chat_ids = [] # 用于轮询的真正 chat_id(从 send_message 返回值中提取)
|
|
|
try:
|
|
|
# 消息 1a:发送到个人(FEISHU_OPERATOR_OPEN_ID)
|
|
|
if FEISHU_OPERATOR_OPEN_ID:
|
|
|
try:
|
|
|
result_personal = _feishu.send_message(to=FEISHU_OPERATOR_OPEN_ID, text=message)
|
|
|
logger.info("飞书审批消息发送成功(个人): message_id=%s", result_personal.message_id)
|
|
|
+ # ✅ 关键修复:从返回值提取 P2P chat_id(用于后续轮询)
|
|
|
+ if hasattr(result_personal, 'chat_id') and result_personal.chat_id:
|
|
|
+ poll_chat_ids.append(result_personal.chat_id)
|
|
|
+ logger.info("提取到 P2P chat_id: %s(用于轮询回复)", result_personal.chat_id)
|
|
|
+ feishu_sent = True
|
|
|
except Exception as e:
|
|
|
logger.warning("发送到个人失败: %s", e)
|
|
|
|
|
|
- # 消息 1b:发送到投放项目群聊(如果配置了)— 临时禁用
|
|
|
- # if FEISHU_AD_PROJECT_CHAT_ID:
|
|
|
- # try:
|
|
|
- # result_project = _feishu.send_message(to=FEISHU_AD_PROJECT_CHAT_ID, text=message)
|
|
|
- # feishu_sent_to_project_chat = True
|
|
|
- # feishu_sent = True
|
|
|
- # logger.info("飞书审批消息发送成功(项目群): message_id=%s", result_project.message_id)
|
|
|
- # except Exception as e:
|
|
|
- # logger.warning("发送到项目群聊失败: %s", e)
|
|
|
+ # 消息 1b:发送到投放项目群聊(如果配置了)
|
|
|
+ if FEISHU_AD_PROJECT_CHAT_ID:
|
|
|
+ try:
|
|
|
+ result_project = _feishu.send_message(to=FEISHU_AD_PROJECT_CHAT_ID, text=message)
|
|
|
+ feishu_sent_to_project_chat = True
|
|
|
+ feishu_sent = True
|
|
|
+ logger.info("飞书审批消息发送成功(项目群): message_id=%s", result_project.message_id)
|
|
|
+ # 群聊 chat_id 本身就是 oc_xxx 格式,可直接用于轮询
|
|
|
+ if FEISHU_AD_PROJECT_CHAT_ID not in poll_chat_ids:
|
|
|
+ poll_chat_ids.append(FEISHU_AD_PROJECT_CHAT_ID)
|
|
|
+ except Exception as e:
|
|
|
+ logger.warning("发送到项目群聊失败: %s", e)
|
|
|
|
|
|
# 消息 2:导入为飞书在线表格(决策详情,含hold参考)
|
|
|
try:
|
|
|
@@ -561,6 +570,15 @@ async def send_approval_request(
|
|
|
except Exception as e:
|
|
|
logger.warning("飞书发消息失败: %s", e)
|
|
|
|
|
|
+ # ✅ 兜底:如果 send_message 未返回 P2P chat_id,用 config 中的 FEISHU_OPERATOR_CHAT_ID
|
|
|
+ if not poll_chat_ids and FEISHU_OPERATOR_CHAT_ID:
|
|
|
+ poll_chat_ids.append(FEISHU_OPERATOR_CHAT_ID)
|
|
|
+ logger.info("使用配置中的 FEISHU_OPERATOR_CHAT_ID 兜底: %s", FEISHU_OPERATOR_CHAT_ID)
|
|
|
+
|
|
|
+ # 将 poll_chat_ids 存入请求状态(供 check_approval_status 使用)
|
|
|
+ _approval_requests[request_id]["poll_chat_ids"] = poll_chat_ids
|
|
|
+ logger.info("轮询目标 chat_ids: %s", poll_chat_ids)
|
|
|
+
|
|
|
# 保存审批消息到文件(备份)
|
|
|
approval_dir = _MINI_DIR / "outputs" / "approvals"
|
|
|
approval_dir.mkdir(parents=True, exist_ok=True)
|
|
|
@@ -609,15 +627,8 @@ async def send_approval_request(
|
|
|
|
|
|
# 读取个人和项目群的审批回复
|
|
|
try:
|
|
|
- # ✅ 修改:监听个人私聊和项目群聊的消息 — 临时只监听个人
|
|
|
- chat_ids_to_check = []
|
|
|
- if FEISHU_OPERATOR_OPEN_ID:
|
|
|
- chat_ids_to_check.append(FEISHU_OPERATOR_OPEN_ID)
|
|
|
- # 临时禁用项目群聊监听
|
|
|
- # if FEISHU_AD_PROJECT_CHAT_ID:
|
|
|
- # chat_ids_to_check.append(FEISHU_AD_PROJECT_CHAT_ID)
|
|
|
-
|
|
|
- for chat_id in chat_ids_to_check:
|
|
|
+ # ✅ 修复:使用 send_message 返回的真实 chat_id 轮询(非 open_id)
|
|
|
+ for chat_id in poll_chat_ids:
|
|
|
result = _feishu.get_message_list(
|
|
|
chat_id=chat_id,
|
|
|
start_time=sent_time_sec,
|
|
|
@@ -755,13 +766,10 @@ async def check_approval_status(
|
|
|
datetime.fromisoformat(request["created_at"]).timestamp()
|
|
|
))
|
|
|
|
|
|
- # ✅ 修改:监听个人私聊和项目群聊的消息 — 临时只监听个人
|
|
|
- chat_ids_to_check = []
|
|
|
- if FEISHU_OPERATOR_OPEN_ID:
|
|
|
- chat_ids_to_check.append(FEISHU_OPERATOR_OPEN_ID)
|
|
|
- # 临时禁用项目群聊监听
|
|
|
- # if FEISHU_AD_PROJECT_CHAT_ID:
|
|
|
- # chat_ids_to_check.append(FEISHU_AD_PROJECT_CHAT_ID)
|
|
|
+ # ✅ 修复:使用请求中存储的真实 chat_id(从 send_message 返回值提取)
|
|
|
+ chat_ids_to_check = request.get("poll_chat_ids", [])
|
|
|
+ if not chat_ids_to_check:
|
|
|
+ logger.warning("请求 %s 没有 poll_chat_ids,可能是旧版请求", request_id)
|
|
|
|
|
|
for chat_id in chat_ids_to_check:
|
|
|
result = _feishu.get_message_list(
|