重构 send_card_message 为 send_notion_card,支持接收者 ID 列表 更新 .gitignore 以忽略更多临时文件 升级项目版本至 0.1.17 删除未使用的 card.txt 模板文件
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
import types
|
|
from pathlib import Path
|
|
import requests
|
|
|
|
|
|
def main() -> None:
|
|
if not os.getenv("app_id") or not os.getenv("app_secret"):
|
|
config_path = Path(__file__).with_name("mcp-server.json")
|
|
if config_path.exists():
|
|
config_data = json.loads(config_path.read_text(encoding="utf-8"))
|
|
servers = config_data.get("mcpServers", {})
|
|
env_data = (
|
|
servers.get("lzwcai-lark-mcp", {}).get("env", {})
|
|
or servers.get("lzwcai-mcpskills-lark-mcp", {}).get("env", {})
|
|
)
|
|
if env_data.get("app_id") and env_data.get("app_secret"):
|
|
os.environ["app_id"] = env_data["app_id"]
|
|
os.environ["app_secret"] = env_data["app_secret"]
|
|
if not os.getenv("app_id") or not os.getenv("app_secret"):
|
|
raise RuntimeError("missing app_id or app_secret")
|
|
if "mcp" not in sys.modules:
|
|
mcp_module = types.ModuleType("mcp")
|
|
types_module = types.ModuleType("mcp.types")
|
|
class Tool:
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|
|
class TextContent:
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|
|
types_module.Tool = Tool
|
|
types_module.TextContent = TextContent
|
|
mcp_module.types = types_module
|
|
sys.modules["mcp"] = mcp_module
|
|
sys.modules["mcp.types"] = types_module
|
|
from lzwcai_lark_mcp.tools import send_notion_card, send_stranger_card
|
|
app_id = os.getenv("app_id", "")
|
|
app_secret = os.getenv("app_secret", "")
|
|
auth_url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
|
|
response = requests.post(
|
|
auth_url,
|
|
json={"app_id": app_id, "app_secret": app_secret},
|
|
headers={"Content-Type": "application/json"},
|
|
timeout=10
|
|
)
|
|
response.raise_for_status()
|
|
data = response.json()
|
|
if data.get("code") not in (0, None):
|
|
raise RuntimeError(f"lark auth failed: {data}")
|
|
token = data.get("tenant_access_token", "")
|
|
if not token:
|
|
raise RuntimeError(f"lark auth response missing token: {data}")
|
|
user_id = "gegg1d78"
|
|
receiver_ids = ["843ga2gb", "gegg1d78"]
|
|
person_id = "gegg1d78"
|
|
image_key = "img_v3_0210i_94bdf5de-5c89-49f0-a793-c504c7377c7g"
|
|
card_message_ids = send_notion_card(
|
|
token,
|
|
receiver_ids,
|
|
person_id,
|
|
image_key
|
|
)
|
|
print(card_message_ids)
|
|
result = send_stranger_card(
|
|
token,
|
|
user_id,
|
|
"CONF-20260301-001",
|
|
"2026-03-01 10:30:00",
|
|
[
|
|
{"华为手机": "huawei_phone"},
|
|
{"红米手机": "redmi_phone"}
|
|
],
|
|
face_cap="img_v3_02vj_b25b040f-b6c1-49f4-a29d-a02c99a13a9g",
|
|
user_ids=["347f5e71", "gegg1d78"],
|
|
remark="如有误报请点击反馈"
|
|
)
|
|
print(result)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|