feat: 飞书知识库读写工具:增删查改节点、写入页面、创建早报、记录踩坑,基于 tenant_access_token。
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# Feishu API 端点速查
|
||||
|
||||
## 认证
|
||||
|
||||
```
|
||||
POST https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal
|
||||
Body: {app_id, app_secret}
|
||||
```
|
||||
|
||||
## Wiki 空间
|
||||
|
||||
```
|
||||
GET /wiki/v2/spaces # 列表
|
||||
GET /wiki/v2/spaces/{space_id} # 详情
|
||||
GET /wiki/v2/spaces/{space_id}/nodes # 列节点 (parent_node_token 可选)
|
||||
POST /wiki/v2/spaces/{space_id}/nodes # 创建节点
|
||||
GET /wiki/v2/spaces/get_node?token=*** # 节点详情
|
||||
POST /wiki/v2/spaces/{space_id}/nodes/{node}/move # 移动节点
|
||||
```
|
||||
|
||||
## Wiki 成员
|
||||
|
||||
```
|
||||
GET /wiki/v2/spaces/{space_id}/members # 成员列表
|
||||
POST /wiki/v2/spaces/{space_id}/members # 添加成员
|
||||
```
|
||||
|
||||
## Docx
|
||||
|
||||
```
|
||||
GET /docx/v1/documents/{doc_id}/blocks/{block_id} # 获取块
|
||||
DELETE /docx/v1/documents/{doc_id}/blocks/{block_id}/children/batch_delete # 清空子块
|
||||
POST /docx/v1/documents/{doc_id}/blocks/{block_id}/children # 写入子块
|
||||
```
|
||||
|
||||
## Drive
|
||||
|
||||
```
|
||||
DELETE /drive/v1/files/{obj_token}?type=docx # 移入回收站
|
||||
POST /drive/v1/permissions/{token}/members?type=docx # 授权
|
||||
```
|
||||
@@ -0,0 +1,40 @@
|
||||
# 飞书知识库鉴权配置
|
||||
|
||||
## 配置来源
|
||||
|
||||
所有飞书维度的配置统一从 `~/.openclaw/openclaw.json` 的 `channels.feishu` 读取:
|
||||
|
||||
| 字段 | 说明 |
|
||||
|------|------|
|
||||
| `appId` | 应用 App ID |
|
||||
| `appSecret` | 应用 App Secret(敏感) |
|
||||
| `botOpenId` | 机器人的 Open ID |
|
||||
|
||||
脚本通过 `init_token.py` 读取配置并获取 `tenant_access_token`(有效期 2 小时,自动续期)。
|
||||
|
||||
## 完整配置步骤
|
||||
|
||||
1. 在飞书开放平台为应用开通权限:
|
||||
- `wiki:wiki` — 知识库读写
|
||||
- `wiki:member:create` — 添加成员
|
||||
- `docx:document` — 文档读写
|
||||
- `docx:document:readonly` — 文档只读
|
||||
- `drive:drive` — 云盘操作
|
||||
- `space:document:delete` — 删除文档
|
||||
|
||||
2. 应用 Bot ID / Open ID
|
||||
- 从配置文件读取 `channels.feishu.appId` 和 `channels.feishu.botOpenId`
|
||||
|
||||
3. 添加机器人为知识库成员(需管理员 OAuth):
|
||||
- 走 OAuth 获取 user_access_token
|
||||
- 调 `POST /wiki/v2/spaces/{space_id}/members`
|
||||
- `member_type: openid`, `member_role: member`
|
||||
|
||||
4. 授予编辑权限(需管理员 OAuth + 用户同意):
|
||||
- 调 `POST /drive/v1/permissions/{obj_token}/members?type=docx`
|
||||
- `perm: full_access`
|
||||
|
||||
5. 日常操作:直接用 `tenant_access_token`
|
||||
- 从 `~/.openclaw/openclaw.json` 读取 app_id/app_secret
|
||||
- 调 `POST /auth/v3/tenant_access_token/internal` 获取 token
|
||||
- 有效期 2 小时,自动续期
|
||||
@@ -0,0 +1,37 @@
|
||||
# Docx Block 类型
|
||||
|
||||
## 常用块
|
||||
|
||||
| type | block_type | 说明 | key 字段 |
|
||||
|------|-----------|------|---------|
|
||||
| text | 2 | 普通文本 | `text.elements[].text_run` |
|
||||
| heading1 | 3 | 一级标题 | `heading1` |
|
||||
| heading2 | 4 | 二级标题 | `heading2` |
|
||||
| heading3 | 5 | 三级标题 | `heading3` |
|
||||
| bullet | 12 | 无序列表 | `bullet` |
|
||||
| code | 14 | 代码块 | `code` |
|
||||
| divider | 22 | 分割线 | `divider` |
|
||||
|
||||
## Text Element 属性
|
||||
|
||||
```json
|
||||
{
|
||||
"text_run": {
|
||||
"content": "文本内容",
|
||||
"text_element_style": {
|
||||
"bold": false,
|
||||
"link": {"url": "https://..."},
|
||||
"inline_code": false,
|
||||
"italic": false,
|
||||
"strikethrough": false,
|
||||
"underline": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 写入流程
|
||||
|
||||
1. `GET /docx/v1/documents/{doc_id}/blocks/{doc_id}` — 获取现有块
|
||||
2. `DELETE .../children/batch_delete` — 清空默认块
|
||||
3. `POST .../children` — 批量写入(≤25块/批)
|
||||
Reference in New Issue
Block a user