处理用户反馈 Args: user_id: 用户 ID push_id: 推送 ID(用于关联行为日志) reply: 用户回复文本 papers: 推送的论文列表 feishu_user_id: 飞书用户 ID(open_id) chat_id: 聊天 ID(优先使用,发送到原对话框) Returns: 处理结果
(
user_id: str,
push_id: str,
reply: str,
papers: List[Dict],
feishu_user_id: Optional[str] = None,
chat_id: Optional[str] = None,
send_to_feishu: bool = True,
auto_create_reports: Optional[bool] = None
)
| 615 | |
| 616 | |
| 617 | def process_feedback( |
| 618 | user_id: str, |
| 619 | push_id: str, |
| 620 | reply: str, |
| 621 | papers: List[Dict], |
| 622 | feishu_user_id: Optional[str] = None, |
| 623 | chat_id: Optional[str] = None, |
| 624 | send_to_feishu: bool = True, |
| 625 | auto_create_reports: Optional[bool] = None |
| 626 | ) -> Dict[str, Any]: |
| 627 | """ |
| 628 | 处理用户反馈 |
| 629 | |
| 630 | Args: |
| 631 | user_id: 用户 ID |
| 632 | push_id: 推送 ID(用于关联行为日志) |
| 633 | reply: 用户回复文本 |
| 634 | papers: 推送的论文列表 |
| 635 | feishu_user_id: 飞书用户 ID(open_id) |
| 636 | chat_id: 聊天 ID(优先使用,发送到原对话框) |
| 637 | |
| 638 | Returns: |
| 639 | 处理结果 |
| 640 | """ |
| 641 | print(f"Processing feedback from user: {user_id}") |
| 642 | print(f"Reply: {reply}") |
| 643 | |
| 644 | # 优先使用 chat_id,否则使用 feishu_user_id |
| 645 | target_id = chat_id or feishu_user_id |
| 646 | use_chat_id = chat_id is not None |
| 647 | |
| 648 | # 1. 解析用户回复 |
| 649 | parsed_selected = parse_user_reply(reply, papers) |
| 650 | reply_lower = reply.lower().strip() |
| 651 | is_none_command = reply_lower == "none" |
| 652 | |
| 653 | if not parsed_selected and not is_none_command: |
| 654 | # 没有有效选择,发送提示 |
| 655 | message = "未识别到有效的论文编号。请回复数字,如:1 2 4 6、1-5 8 10,或直接回复 none。" |
| 656 | if target_id and send_to_feishu: |
| 657 | send_text(target_id, message, use_chat_id=use_chat_id) |
| 658 | return {"status": "error", "message": message} |
| 659 | |
| 660 | previously_selected = get_existing_selected_numbers(user_id, push_id, papers) |
| 661 | selected = set() if is_none_command else previously_selected | parsed_selected |
| 662 | newly_selected = set() if is_none_command else parsed_selected - previously_selected |
| 663 | |
| 664 | print(f"Selected paper numbers: {sorted(selected)}") |
| 665 | if previously_selected: |
| 666 | print(f"Previously selected in this push: {sorted(previously_selected)}") |
| 667 | if newly_selected != parsed_selected: |
| 668 | print(f"Newly selected in this reply: {sorted(newly_selected)}") |
| 669 | current_timestamp = datetime.now() |
| 670 | feedback_strength_multiplier, feedback_latency_seconds = estimate_feedback_strength_multiplier(push_id, current_timestamp) |
| 671 | history_before_update = get_recent_selected_papers( |
| 672 | user_id, |
| 673 | limit=60, |
| 674 | days=60, |
no test coverage detected