Files
ai-proj-helper/plugins/feishu-docx-plugin/skills/SKILL.md

127 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: feishu-docx
description: 飞书云文档操作。用于创建、编辑云文档,插入内容块,会议纪要生成。当需要操作飞书云文档时使用。
---
# 飞书云文档 (Docx)
## URL 结构
```
https://xxx.feishu.cn/docx/DoxcXXXXXX
└── document_id
```
## 创建文档
```python
def create_document(title, folder_token=None):
url = "https://open.feishu.cn/open-apis/docx/v1/documents"
payload = {"title": title}
if folder_token:
payload["folder_token"] = folder_token
response = requests.post(url, headers=headers, json=payload)
doc = response.json()["data"]["document"]
return {"document_id": doc["document_id"], "url": f"https://feishu.cn/docx/{doc['document_id']}"}
```
## 设置权限
```python
def set_permission(document_id, editable=True):
"""设置文档为组织内可编辑/只读"""
url = f"https://open.feishu.cn/open-apis/drive/v1/permissions/{document_id}/public"
payload = {
"external_access_entity": "open",
"link_share_entity": "tenant_editable" if editable else "tenant_readable"
}
requests.patch(url, headers=headers, params={"type": "docx"}, json=payload)
```
## 内容块类型
| 类型 | block_type | 示例 |
|------|------------|------|
| 段落 | 2 | 普通文本 |
| 一级标题 | 3 | # 标题 |
| 二级标题 | 4 | ## 标题 |
| 三级标题 | 5 | ### 标题 |
| 无序列表 | 13 | - 列表项 |
| 有序列表 | 14 | 1. 列表项 |
| 代码块 | 16 | ```code``` |
| 引用 | 18 | > 引用 |
| 分割线 | 22 | --- |
| 图片 | 27 | 需先上传 |
## 创建内容块
```python
def create_block(document_id, block_id, block_type, content):
url = f"https://open.feishu.cn/open-apis/docx/v1/documents/{document_id}/blocks/{block_id}/children"
if block_type in [3, 4, 5]: # 标题
block = {"block_type": block_type, "heading": {"elements": [{"text_run": {"content": content}}]}}
elif block_type == 2: # 段落
block = {"block_type": 2, "text": {"elements": [{"text_run": {"content": content}}]}}
elif block_type in [13, 14]: # 列表
block = {"block_type": block_type, "bullet/ordered": {"elements": [{"text_run": {"content": content}}]}}
requests.post(url, headers=headers, json={"children": [block], "index": -1})
```
## 图片上传
```python
# 1. 上传图片到素材库
def upload_image(file_path, parent_node):
url = "https://open.feishu.cn/open-apis/drive/v1/medias/upload_all"
with open(file_path, 'rb') as f:
files = {'file': f}
data = {'file_name': os.path.basename(file_path), 'parent_type': 'docx_image', 'parent_node': parent_node}
response = requests.post(url, headers={"Authorization": f"Bearer {token}"}, files=files, data=data)
return response.json()["data"]["file_token"]
# 2. 插入图片块
def insert_image(document_id, block_id, file_token):
block = {"block_type": 27, "image": {"token": file_token}}
# ... 同 create_block
```
## 会议纪要模板
```python
def create_meeting_notes(title, date, attendees, agenda, decisions, action_items):
doc = create_document(f"{title} - {date}")
doc_id = doc["document_id"]
# 获取根块
root = requests.get(f".../documents/{doc_id}/blocks/{doc_id}").json()
root_id = root["data"]["block"]["block_id"]
# 添加内容
create_block(doc_id, root_id, 3, f"会议纪要:{title}")
create_block(doc_id, root_id, 2, f"日期:{date}")
create_block(doc_id, root_id, 2, f"参会人:{', '.join(attendees)}")
create_block(doc_id, root_id, 4, "议程")
for item in agenda:
create_block(doc_id, root_id, 13, item)
create_block(doc_id, root_id, 4, "决议")
for item in decisions:
create_block(doc_id, root_id, 13, item)
create_block(doc_id, root_id, 4, "待办事项")
for item in action_items:
create_block(doc_id, root_id, 14, item)
return doc
```
## 完整工具类
见 `~/.claude/skills/feishu/feishu_docx.py`
## 注意事项
- 创建文档必须指定 `folder_token`,否则会出现在「与我共享」
- 默认存储到 `C80gfkRnzlonQ5d4AhOcOACDnNg`01运营文件夹
- 图片必须先上传到素材库,再插入文档