diff --git a/sdk/scripts/send_to_feishu.py b/sdk/scripts/send_to_feishu.py new file mode 100644 index 0000000000..7f4dbf306c --- /dev/null +++ b/sdk/scripts/send_to_feishu.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +""" +工作手机SDK · 开发进度复盘 → 飞书工作手机开发群 + +注意:这个脚本专门发到【工作手机开发进度群】,不是卡若AI日志群。 +两个群的 webhook 不同: + - 工作手机开发进度群: d0f607da-ae26-43a0-9dbe-2c2c0b90743d ← 本脚本用这个 + - 卡若AI复盘群: 8b7f996e-2892-4075-989f-aa5593ea4fbc ← 卡若AI那边的 + +用法: + python3 send_to_feishu.py "复盘文本内容" + python3 send_to_feishu.py --rich "标题" "正文内容" +""" +import argparse +import json +import sys + +import requests + +WEBHOOK_URL = ( + "https://open.feishu.cn/open-apis/bot/v2/hook/" + "d0f607da-ae26-43a0-9dbe-2c2c0b90743d" +) + + +def send_text(text: str) -> bool: + payload = {"msg_type": "text", "content": {"text": text[:4000]}} + return _post(payload) + + +def send_rich(title: str, body: str) -> bool: + lines = body.strip().split("\n") + content = [[{"tag": "text", "text": line + "\n"}] for line in lines] + payload = { + "msg_type": "post", + "content": { + "post": { + "zh_cn": { + "title": title, + "content": content, + } + } + }, + } + return _post(payload) + + +def _post(payload: dict) -> bool: + try: + r = requests.post(WEBHOOK_URL, json=payload, timeout=10) + body = r.json() + if body.get("code") != 0: + print(f"飞书返回错误: {body}", file=sys.stderr) + return False + print("✅ 已发送到工作手机开发进度群") + return True + except Exception as e: + print(f"发送失败: {e}", file=sys.stderr) + return False + + +def main(): + ap = argparse.ArgumentParser(description="工作手机SDK 复盘发飞书") + ap.add_argument("text", nargs="?", default="", help="纯文本内容") + ap.add_argument("--rich", nargs=2, metavar=("TITLE", "BODY"), + help="富文本模式: --rich '标题' '正文'") + args = ap.parse_args() + + if args.rich: + ok = send_rich(args.rich[0], args.rich[1]) + elif args.text: + ok = send_text(args.text) + else: + text = sys.stdin.read().strip() + ok = send_text(text) if text else False + + if not ok: + sys.exit(1) + + +if __name__ == "__main__": + main()