发送周报 Args: user_id: 用户 ID days: 统计天数 feishu_chat_id: 飞书聊天 ID(优先使用) role_name: 角色名(可选,用于查找 feishu_chat_id) send_to_feishu: 是否发送 Returns: 报告结果
(
user_id: str,
days: int = 7,
feishu_chat_id: Optional[str] = None,
role_name: Optional[str] = None,
send_to_feishu: bool = True
)
| 686 | |
| 687 | def send_weekly_report( |
| 688 | user_id: str, |
| 689 | days: int = 7, |
| 690 | feishu_chat_id: Optional[str] = None, |
| 691 | role_name: Optional[str] = None, |
| 692 | send_to_feishu: bool = True |
| 693 | ) -> Dict[str, Any]: |
| 694 | """ |
| 695 | 发送周报 |
| 696 | |
| 697 | Args: |
| 698 | user_id: 用户 ID |
| 699 | days: 统计天数 |
| 700 | feishu_chat_id: 飞书聊天 ID(优先使用) |
| 701 | role_name: 角色名(可选,用于查找 feishu_chat_id) |
| 702 | send_to_feishu: 是否发送 |
| 703 | |
| 704 | Returns: |
| 705 | 报告结果 |
| 706 | """ |
| 707 | print(f"Generating weekly report for user: {user_id}") |
| 708 | |
| 709 | # 生成报告 |
| 710 | report = generate_weekly_report(user_id, days) |
| 711 | |
| 712 | if "error" in report: |
| 713 | print(f"Error: {report['error']}") |
| 714 | return report |
| 715 | |
| 716 | # 格式化 |
| 717 | report_card = format_report_card(report) |
| 718 | |
| 719 | # 发送到飞书 |
| 720 | if send_to_feishu: |
| 721 | # 优先使用传入的 chat_id,否则按 user_id / role_name 解析角色 chat_id |
| 722 | target_chat = feishu_chat_id |
| 723 | if not target_chat: |
| 724 | target_chat = resolve_chat_id_for_user(user_id, role_name) |
| 725 | |
| 726 | if target_chat: |
| 727 | try: |
| 728 | # 使用 chat_id 发送到群聊 |
| 729 | send_text_to_chat(target_chat, report_card) |
| 730 | print(f"Weekly report sent to Feishu chat: {target_chat}") |
| 731 | except Exception as e: |
| 732 | print(f"Failed to send to Feishu: {e}") |
| 733 | return {"error": str(e)} |
| 734 | else: |
| 735 | print("Warning: No Feishu chat ID provided") |
| 736 | |
| 737 | return report |
| 738 | |
| 739 | |
| 740 | if __name__ == "__main__": |
| 741 | import argparse |
no test coverage detected