lark-drive
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedrive (v1)
drive (v1)
CRITICAL — 开始前 MUST 先用 Read 工具读取 ,其中包含认证、权限处理
../lark-shared/SKILL.mdCRITICAL — You MUST use the Read tool to access first, which contains authentication and permission handling
../lark-shared/SKILL.md核心概念
Core Concepts
文档类型与 Token
Document Types and Tokens
飞书开放平台中,不同类型的文档有不同的 URL 格式和 Token 处理方式。在进行文档操作(如添加评论、下载文件等)时,必须先获取正确的 。
file_tokenIn the Feishu Open Platform, different types of documents have different URL formats and token handling methods. When performing document operations (such as adding comments, downloading files, etc.), you must first obtain the correct .
file_token文档 URL 格式与 Token 处理
Document URL Formats and Token Handling
| URL 格式 | 示例 | Token 类型 | 处理方式 |
|---|---|---|---|
| | | URL 路径中的 token 直接作为 |
| | | URL 路径中的 token 直接作为 |
| | | ⚠️ 不能直接使用,需要先查询获取真实的 |
| | | URL 路径中的 token 直接作为 |
| | | URL 路径中的 token 作为文件夹 token 使用 |
| URL Format | Example | Token Type | Handling Method |
|---|---|---|---|
| | | Use the token in the URL path directly as |
| | | Use the token in the URL path directly as |
| | | ⚠️ Cannot be used directly, you need to query to get the real |
| | | Use the token in the URL path directly as |
| | | Use the token in the URL path as the folder token |
Wiki 链接特殊处理(关键!)
Special Handling for Wiki Links (Critical!)
知识库链接()背后可能是云文档、电子表格、多维表格等不同类型的文档。不能直接假设 URL 中的 token 就是 file_token,必须先查询实际类型和真实 token。
/wiki/TOKENA knowledge base link () may correspond to different types of documents such as cloud documents, spreadsheets, base tables, etc. Do not assume that the token in the URL is the file_token; you must first query the actual type and real token.
/wiki/TOKEN处理流程
Processing Flow
-
使用查询节点信息
wiki.spaces.get_nodebashlark-cli wiki spaces get_node --params '{"token":"wiki_token"}' -
从返回结果中提取关键信息
- :文档类型(docx/doc/sheet/bitable/slides/file/mindnote)
node.obj_type - :真实的文档 token(用于后续操作)
node.obj_token - :文档标题
node.title
-
根据使用对应的 API
obj_typeobj_type 说明 使用的 API docx新版云文档 、drive file.comments.*docx.*doc旧版云文档 drive file.comments.*sheet电子表格 sheets.*bitable多维表格 bitable.*slides幻灯片 drive.*file文件 drive.*mindnote思维导图 drive.*
-
Query node information using
wiki.spaces.get_nodebashlark-cli wiki spaces get_node --params '{"token":"wiki_token"}' -
Extract key information from the returned result
- : Document type (docx/doc/sheet/bitable/slides/file/mindnote)
node.obj_type - : Real document token (used for subsequent operations)
node.obj_token - : Document title
node.title
-
Use the corresponding API based on
obj_typeobj_type Description API to Use docxNew version cloud document 、drive file.comments.*docx.*docOld version cloud document drive file.comments.*sheetSpreadsheet sheets.*bitableBase table bitable.*slidesSlides drive.*fileFile drive.*mindnoteMind map drive.*
查询示例
Query Example
bash
undefinedbash
undefined查询 wiki 节点
Query wiki node
lark-cli wiki spaces get_node --params '{"token":"wiki_token"}'
返回结果示例:
```json
{
"node": {
"obj_type": "docx",
"obj_token": "xxxx",
"title": "标题",
"node_type": "origin",
"space_id": "12345678910"
}
}lark-cli wiki spaces get_node --params '{"token":"wiki_token"}'
Sample return result:
```json
{
"node": {
"obj_type": "docx",
"obj_token": "xxxx",
"title": "Title",
"node_type": "origin",
"space_id": "12345678910"
}
}资源关系
Resource Relationships
Wiki Space (知识空间)
└── Wiki Node (知识库节点)
├── obj_type: docx (新版文档)
│ └── obj_token (真实文档 token)
├── obj_type: doc (旧版文档)
│ └── obj_token (真实文档 token)
├── obj_type: sheet (电子表格)
│ └── obj_token (真实文档 token)
├── obj_type: bitable (多维表格)
│ └── obj_token (真实文档 token)
└── obj_type: file/slides/mindnote
└── obj_token (真实文档 token)
Drive Folder (云空间文件夹)
└── File (文件/文档)
└── file_token (直接使用)Wiki Space
└── Wiki Node
├── obj_type: docx (New version document)
│ └── obj_token (Real document token)
├── obj_type: doc (Old version document)
│ └── obj_token (Real document token)
├── obj_type: sheet (Spreadsheet)
│ └── obj_token (Real document token)
├── obj_type: bitable (Base table)
│ └── obj_token (Real document token)
└── obj_type: file/slides/mindnote
└── obj_token (Real document token)
Drive Folder
└── File (File/Document)
└── file_token (Use directly)常见操作 Token 需求
Token Requirements for Common Operations
| 操作 | 需要的 Token | 说明 |
|---|---|---|
| 读取文档内容 | | |
| 添加局部评论(划词评论) | | 传 |
| 添加全文评论 | | 不传 |
| 下载文件 | | 从文件 URL 中直接提取 |
| 上传文件 | | 目标位置的 token |
| 列出文档评论 | | 同添加评论 |
| Operation | Required Token | Description |
|---|---|---|
| Read document content | | |
| Add local comment (selected text comment) | | When passing |
| Add full-document comment | | When not passing |
| Download file | | Extract directly from the file URL |
| Upload file | | Token of the target location |
| List document comments | | Same as adding comments |
评论能力边界(关键!)
Comment Capability Boundaries (Critical!)
- 支持两种模式。
drive +add-comment - 全文评论:未传 /
--selection-with-ellipsis时默认启用,也可显式传--block-id;支持--full-comment、旧版docxURL,以及最终解析为doc/doc的 wiki URL。docx - 局部评论:传 或
--selection-with-ellipsis时启用;仅支持--block-id,以及最终解析为docx的 wiki URL。docx - 的
drive +add-comment需要传--contentJSON 数组字符串,例如reply_elements。--content '[{"type":"text","text":"正文"}]' - 如果 wiki 解析后不是 /
doc,不要用docx。+add-comment - 如果需要更底层地直接调用评论 V2 协议,再走原生 API:先执行 ,再执行
lark-cli schema drive.file.comments.create_v2。全文评论省略lark-cli drive file.comments create_v2 ...,局部评论传anchor。anchor.block_id
- supports two modes.
drive +add-comment - Full-document comment: Enabled by default when /
--selection-with-ellipsisis not passed, or can be explicitly enabled by passing--block-id; supports--full-comment, old versiondocxURLs, and wiki URLs that resolve todoc/doc.docx - Local comment: Enabled when or
--selection-with-ellipsisis passed; only supports--block-idand wiki URLs that resolve todocx.docx - The parameter of
--contentrequires a JSON array string ofdrive +add-comment, e.g.,reply_elements.--content '[{"type":"text","text":"Content"}]' - Do not use if the wiki resolves to a type other than
+add-comment/doc.docx - If you need to directly call the comment V2 protocol at a lower level, use the native API: first run , then run
lark-cli schema drive.file.comments.create_v2. Omitlark-cli drive file.comments create_v2 ...for full-document comments, and passanchorfor local comments.anchor.block_id
评论查询与统计口径(关键!)
Comment Query and Statistical Caliber (Critical!)
- 查询文档评论时,使用 。
drive file.comments list - 返回的
drive file.comments list应理解为"评论卡片"列表,每个items对应用户界面里看到的一张评论卡片,而不是平铺的互动消息列表。item - 服务端语义上,创建第一条评论时会同时创建该卡片里的第一条 reply;因此真正承载正文的是每个 ,其中第一条 reply 在用户视角下就是这张卡片里的"评论本身"。
item.reply_list.replies - 当用户要统计"评论数"或"评论卡片数"时,统计 的长度即可;如果是全量统计,则对所有评论分页返回的
items长度累加。items - 当用户要统计"回复数"时,按用户视角应排除每张评论卡片里的首条评论,统计口径是所有 的长度之和减去
item.reply_list.replies的长度。items - 当用户要统计"总互动数"时,统计所有 的长度之和即可;这个口径包含每张评论卡片里的首条评论。
item.reply_list.replies - 如果某个 ,说明该评论卡片下还有更多回复未包含在当前返回中;此时需要继续调用
item.has_more=true拉全后,再做全量回复数 / 总互动数统计。drive file.comment.replys list
- Use to query document comments.
drive file.comments list - The returned by
itemsshould be understood as a list of "comment cards", where eachdrive file.comments listcorresponds to a comment card seen in the user interface, not a flat list of interactive messages.item - In server-side semantics, when the first comment is created, the first reply in the card is also created; therefore, the actual content is carried in , where the first reply is the "comment itself" in the user's view.
item.reply_list.replies - When users want to count the "number of comments" or "number of comment cards", count the length of ; for full statistics, sum the lengths of
itemsreturned from all comment pages.items - When users want to count the "number of replies", exclude the first comment in each comment card from the user's perspective; the statistical caliber is the total length of all minus the length of
item.reply_list.replies.items - When users want to count the "total number of interactions", count the total length of all ; this caliber includes the first comment in each comment card.
item.reply_list.replies - If for a certain item, it means there are more replies under this comment card not included in the current return; in this case, you need to continue calling
item.has_more=trueto pull all data before conducting full reply count / total interaction count statistics.drive file.comment.replys list
评论业务特性与引导(关键!)
Comment Business Features and Guidance (Critical!)
评论排序引导
Comment Sorting Guidance
- 一个文档通常有多个评论,评论按 (创建时间)排序。
create_time - 重要:只有当用户明确提到"最新评论"、"最后评论"、"最早评论"时,才需要根据 进行排序:
create_time- 必须先获取所有评论(处理分页拉完所有数据),不能只获取一页就排序
- "最新评论" / "最后评论":按 降序排列,取第一条
create_time - "最早评论":按 升序排列,取第一条
create_time
- 如果用户只说"第一条评论",直接使用 返回的第一条即可,不需要额外排序。
drive file.comments list
- A document usually has multiple comments, sorted by (creation time).
create_time - Important: Only when the user explicitly mentions "latest comment", "last comment", or "earliest comment" should you sort by :
create_time- Must first obtain all comments (handle pagination to pull all data), do not sort after only getting one page
- "Latest comment" / "Last comment": Sort in descending order by , take the first one
create_time - "Earliest comment": Sort in ascending order by , take the first one
create_time
- If the user only says "first comment", directly use the first one returned by , no additional sorting is needed.
drive file.comments list
评论回复限制
Comment Reply Restrictions
- 添加评论回复前先检查是否存在以下限制
- 全文评论不支持回复:的评论(全文评论)无法添加回复,遇到此类评论应提示用户"全文评论不支持回复"。
is_whole=true - 已解决评论不支持回复:的评论无法添加回复,遇到此类评论应提示用户"该评论已被解决,无法回复"。
is_solved=true - 注意:当用户要回复某条评论但该评论因上述限制不能回复时,只提示不能回复即可,不要自动帮用户找其他可以回复的评论,避免不符合用户预期。
- Check for the following restrictions before adding a comment reply
- Full-document comments do not support replies: Comments with (full-document comments) cannot have replies added. Prompt the user with "Full-document comments do not support replies" when encountering such comments.
is_whole=true - Resolved comments do not support replies: Comments with cannot have replies added. Prompt the user with "This comment has been resolved and cannot be replied to" when encountering such comments.
is_solved=true - Note: When the user wants to reply to a comment but it cannot be replied to due to the above restrictions, only prompt that it cannot be replied to, do not automatically find other commentable comments for the user to avoid inconsistent expectations.
批量查询与列表查询的选择
Selection Between Batch Query and List Query
- 使用 是已知评论 ID 后的批量查询,需要传入具体的评论 ID 列表。
drive file.comments batch_query - 使用 用于分页获取评论列表,适合统计评论总数、遍历所有评论,或获取"最新/最后 N 条评论"等场景。
drive file.comments list
- is for batch query after knowing the comment IDs, requiring a specific list of comment IDs to be passed.
drive file.comments batch_query - is used to obtain comment lists in pages, suitable for scenarios such as counting the total number of comments, traversing all comments, or obtaining "latest/last N comments".
drive file.comments list
典型错误与解决方案
Typical Errors and Solutions
| 错误信息 | 原因 | 解决方案 |
|---|---|---|
| 使用了错误的 token | 检查 token 类型,wiki 链接必须先查询获取 |
| 没有相关操作权限 | 引导用户检查当前身份对文档/文件是否有相应操作权限;如果需要,可以授予相应权限 |
| file_type 参数错误 | 根据 |
| Error Message | Cause | Solution |
|---|---|---|
| Used an incorrect token | Check the token type; wiki links must first be queried to obtain |
| No relevant operation permissions | Guide the user to check if the current identity has the corresponding operation permissions for the document/file; if needed, grant the corresponding permissions |
| Incorrect file_type parameter | Pass the correct file_type according to |
Shortcuts(推荐优先使用)
Shortcuts (Recommended for Priority Use)
Shortcut 是对常用操作的高级封装()。有 Shortcut 的操作优先使用。
lark-cli drive +<verb> [flags]| Shortcut | 说明 |
|---|---|
| Upload a local file to Drive |
| Download a file from Drive to local |
| Add a full-document comment, or a local comment to selected docx text (also supports wiki URL resolving to doc/docx) |
Shortcuts are advanced encapsulations of common operations (). Use shortcuts first for operations that have them.
lark-cli drive +<verb> [flags]| Shortcut | Description |
|---|---|
| Upload a local file to Drive |
| Download a file from Drive to local |
| Add a full-document comment, or a local comment to selected docx text (also supports wiki URL resolving to doc/docx) |
API Resources
API Resources
bash
lark-cli schema drive.<resource>.<method> # 调用 API 前必须先查看参数结构
lark-cli drive <resource> <method> [flags] # 调用 API重要:使用原生 API 时,必须先运行查看schema/--data参数结构,不要猜测字段格式。--params
bash
lark-cli schema drive.<resource>.<method> # Must check the parameter structure before calling the API
lark-cli drive <resource> <method> [flags] # Call the APIImportant: When using the native API, you must first runto check theschema/--dataparameter structure, do not guess the field format.--params
files
files
- — 复制文件
copy
- — Copy file
copy
file.comments
file.comments
- — 批量获取评论
batch_query- — 添加全文/局部(划词)评论
create_v2 - — 分页获取文档评论
list - — 解决/恢复 评论
patch
- — Batch get comments
batch_query- — Add full-document/local (selected text) comment
create_v2 - — Paginate to get document comments
list - — Resolve/restore comment
patch
file.comment.replys
file.comment.replys
- —
create- — 删除回复
delete - — 获取回复
list - — 更新回复
update
- — Create reply
create- — Delete reply
delete - — Get replies
list - — Update reply
update
permission.members
permission.members
- —
auth- — 增加协作者权限
create - —
transfer_owner
- — Authenticate permission member
auth- — Add collaborator permission
create - — Transfer owner
transfer_owner
metas
metas
- — 获取文档元数据
batch_query
- — Get document metadata
batch_query
user
user
- — 取消订阅用户、应用维度事件
remove_subscription- — 订阅用户、应用维度事件(本次开放评论添加事件)
subscription - — 查询用户、应用对指定事件的订阅状态
subscription_status
- — Unsubscribe from user or application-level events
remove_subscription- — Subscribe to user or application-level events (comment addition event is open this time)
subscription - — Query the subscription status of user or application to specified events
subscription_status
权限表
Permission Table
| 方法 | 所需 scope |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Method | Required scope |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |