
dingtalk-document
DingTalk knowledge base and document management operations. Use this skill when the user mentions "DingTalk Document", "Knowledge Base", "Create Document", "View Document Directory", "Read Document Content", "Write Document", "Update Document", "Document Member", "dingtalk doc", or "knowledge base". Supports all document-related operations including creating knowledge bases, querying knowledge base lists, creating documents/folders, reading/writing document content, and managing member permissions.
DingTalk knowledge base and document management operations. Use this skill when the user mentions "DingTalk Document", "Knowledge Base", "Create Document", "View Document Directory", "Read Document Content", "Write Document", "Update Document", "Document Member", "dingtalk doc", or "knowledge base". Supports all document-related operations including creating knowledge bases, querying knowledge base lists, creating documents/folders, reading/writing document content, and managing member permissions.
DingTalk Document Skill
Responsible for all operations regarding DingTalk knowledge bases and documents. This file is a policy guide that contains only decision logic and workflows. For complete API request formats, refer to the "references/api.md Lookup Index" at the end of this document.
dt_helper.shis located in thescripts/dt_helper.shdirectory relative to thisSKILL.md.
Core Concepts
- Knowledge Base (Workspace): Document container containing
workspaceIdandrootNodeId - Node: File or folder whose
typeisFILEorFOLDER - Document Identifier (used for
/v1.0/doc/suites/documents/{id}): Accepts eitherdocKeyordentryUuid- The create document response returns:
docKey,dentryUuid, andnodeId - Among these,
docKey/dentryUuidcan be used for reading and writing document content;nodeIdis used for deletion and document management APIs - The
nodeIdreturned bywiki/nodesis actuallydentryUuidand can be used directly for content read/write
- The create document response returns:
- operatorId: A required unionId parameter for all APIs, automatically converted via
bash scripts/dt_helper.sh --to-unionid
Workflow (Before Each Execution)
- Identify current task type → For example: list knowledge bases, read document, write document, create document, manage members
- Validate required configurations for current task → Read via
bash scripts/dt_helper.sh --get KEY; validate only items required for the current task - Collect missing configurations only → If any item is missing, ask the user once for all missing values and write them using
bash scripts/dt_helper.sh --set KEY=VALUE - Get Token / operatorId → Call
bash scripts/dt_helper.shdirectly; token acquisition and caching details can be ignored - Execute operation → For any commands containing variable substitution, pipes, or multiline logic, write to
/tmp/<task>.shfirst and then execute withbash /tmp/<task>.sh. Do not paste multiline commands directly into the terminal (terminal tools will truncate them), and do not use<<'EOF'syntax (heredoc will also be truncated in tools, resulting in lost variables)
Task-based Configuration Validation (Must perform first)
- Required for all tasks:
DINGTALK_APP_KEY,DINGTALK_APP_SECRET,DINGTALK_MY_USER_ID - Involves any Document/Knowledge Base API call: Must have
DINGTALK_MY_OPERATOR_ID(if missing, convert automatically viabash scripts/dt_helper.sh --to-unionidand save back first) - Create/Read/Write/Delete/Member Management: Beyond the common items above, there are no extra fixed configuration keys;
workspaceId/nodeId/docKeyare runtime task parameters retrieved from user input or API responses
Rule: Do not proceed to API call steps before passing the "Current Task Configuration Validation".
Credentials must not be printed in full in outputs; show only the first 4 characters +
****during confirmation
Required Configuration
| Config Key | Required | Description | How to Obtain |
|---|---|---|---|
DINGTALK_APP_KEY |
✅ | Application AppKey | DingTalk Open Platform → App Management → Credentials |
DINGTALK_APP_SECRET |
✅ | Application AppSecret | Same as above |
DINGTALK_MY_USER_ID |
✅ | Current user's internal employee ID (userId) | Admin Console → Contacts → Member Management → Click name to view |
DINGTALK_MY_OPERATOR_ID |
✅ | Current user's unionId (operatorId) | Automatically converted and written on first run via bash scripts/dt_helper.sh --to-unionid |
Identity Identifiers Description
| Identifier | Description |
|---|---|
userId (= staffId) |
Internal corporate employee ID, viewable via Admin Console -> Contacts -> Member Management -> Click name |
unionId |
Cross-corporate/cross-app unique identifier, obtained via bash scripts/dt_helper.sh --to-unionid <userid> |
Execution Script Template
#!/bin/bash
set -e
HELPER="./scripts/dt_helper.sh"
NEW_TOKEN=$(bash "$HELPER" --token)
OPERATOR_ID=$(bash "$HELPER" --get DINGTALK_MY_OPERATOR_ID)
# Append specific API calls here, for example querying knowledge base list:
WORKSPACES=$(curl -s -X GET "https://api.dingtalk.com/v2.0/wiki/workspaces?operatorId=${OPERATOR_ID}&maxResults=20" \
-H "x-acs-dingtalk-access-token: $NEW_TOKEN")
echo "Workspace List: $WORKSPACES"
Token Invalidation Handling: dt_helper caches only by time and cannot detect if a token is revoked prematurely. If the API returns 401 (invalid/expired token), use
--nocacheto bypass cache and force re-fetching:NEW_TOKEN=$(bash "$HELPER" --token --nocache)
references/api.md Lookup Index
Once you have determined the action to perform, use the following commands to extract full API details (request format, parameter descriptions, return value examples) for the corresponding section from references/api.md:
grep -A 30 "^## 1. 查询知识库列表" references/api.md
grep -A 10 "^## 2. 查询知识库信息" references/api.md
grep -A 35 "^## 3. 查询节点列表" references/api.md
grep -A 10 "^## 4. 查询单个节点" references/api.md
grep -A 15 "^## 5. 通过 URL 查询节点" references/api.md
grep -A 28 "^## 6. 创建文档" references/api.md
grep -A 10 "^## 7. 删除文档" references/api.md
grep -A 30 "^## 8. 读取文档内容" references/api.md
grep -A 15 "^## 9. 覆盖写入文档内容" references/api.md
grep -A 12 "^## 10. 追加文本到段落" references/api.md
grep -A 18 "^## 11. 添加文档成员" references/api.md
grep -A 12 "^## 12. 更新文档成员权限" references/api.md
grep -A 10 "^## 13. 移除文档成员" references/api.md
grep -A 10 "^## 错误码" references/api.md
grep -A 10 "^## 所需应用权限" references/api.md





