Loading...
Loading...
DingTalk Address Book and Contact Query. Use this skill when the user mentions terms like "DingTalk address book", "find employee", "search user", "check user info", "get user details", "user phone number", "employee name", "employee ID", "check department", "search department", "department members", "department list", "department details", "sub-department", "parent department", "department path", "total number of employees", "address book search", "userId to unionId", "unionId to userId", "dingtalk contact", "dingtalk directory", "find user", "get user info", "department members". Supported operations: search users/departments by keyword, get complete user information (name/phone/employee ID/department/position/unionId), get department member list, get department tree structure, query user's department path, count total number of employees, and all other address book operations.
npx skill4agent add breath57/dingtalk-skills dingtalk-contactis located indt_helper.shat the same level as thisscripts/dt_helper.sh.SKILL.md
bash scripts/dt_helper.sh --get KEYbash scripts/dt_helper.sh --set KEY=VALUEbash scripts/dt_helper.shDINGTALK_APP_KEYDINGTALK_APP_SECRETDINGTALK_MY_USER_IDRule: Do not proceed to the API call step until the "task configuration validation" is passed.
Credentials are prohibited from being printed in full. Only display the first 4 characters +during confirmation.****
| Configuration Key | Required | Description | How to Obtain |
|---|---|---|---|
| ✅ | AppKey of the application | DingTalk Open Platform → Application Management → Credential Information |
| ✅ | AppSecret of the application | Same as above |
| ❌ | userId of the current operator (the person running this skill), required only when querying starting from oneself | Admin Backend → Address Book → Member Management → Click name to view |
| Identifier | Description |
|---|---|
| Internal employee ID of the enterprise, which can be viewed via Admin Backend -> Address Book -> Member Management -> Click name |
| Unique identifier across enterprises/applications, which can be obtained via |
#!/bin/bash
set -e
HELPER="./scripts/dt_helper.sh"
NEW_TOKEN=$(bash "$HELPER" --token) # api.dingtalk.com 接口用
OLD_TOKEN=$(bash "$HELPER" --old-token) # oapi.dingtalk.com 接口用
# USER_ID=$(bash "$HELPER" --get DINGTALK_MY_USER_ID) # 以当前操作用户为起点时启用
# 在此追加具体 API 调用,例如按姓名搜索用户并获取详情:
KEYWORD="张三"
SEARCH=$(curl -s -X POST https://api.dingtalk.com/v1.0/contact/users/search \
-H "x-acs-dingtalk-access-token: $NEW_TOKEN" \
-H 'Content-Type: application/json' \
-d "{\"queryWord\":\"$KEYWORD\",\"offset\":0,\"size\":20}")
echo "搜索结果: $SEARCH"
TARGET_UID=$(echo "$SEARCH" | grep -o '"list":\["[^"]*"' | grep -o '"[^"]*"$' | tr -d '"')
DETAIL=$(curl -s -X POST "https://oapi.dingtalk.com/topapi/v2/user/get?access_token=${OLD_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{\"userid\":\"$TARGET_UID\",\"language\":\"zh_CN\"}")
echo "用户详情: $DETAIL"Token Invalid Handling: dt_helper only caches by time and cannot detect if the token is revoked in advance. If the API returns/errcode 40001(token invalid/expired), use40014to skip the cache and force a re-acquisition:--nocachebashOLD_TOKEN=$(bash "$HELPER" --old-token --nocache) # 强制重新获取旧版 token NEW_TOKEN=$(bash "$HELPER" --token --nocache) # 强制重新获取新版 token
references/api.mdgrep -A 30 "^## 1. 按关键词搜索用户" references/api.md
grep -A 50 "^## 2. 获取用户完整详情" references/api.md
grep -A 20 "^## 3. unionId → userId 转换" references/api.md
grep -A 18 "^## 4. 企业员工总人数" references/api.md
grep -A 25 "^## 5. 按关键词搜索部门" references/api.md
grep -A 25 "^## 6. 获取子部门列表" references/api.md
grep -A 20 "^## 7. 获取子部门 ID 列表" references/api.md
grep -A 25 "^## 8. 获取部门详情" references/api.md
grep -A 40 "^## 9. 获取部门成员完整列表" references/api.md
grep -A 18 "^## 10. 获取部门成员 userId 列表" references/api.md
grep -A 20 "^## 11. 获取用户所在部门路径" references/api.md
grep -A 12 "^## 错误码" references/api.md
grep -A 6 "^## 所需应用权限" references/api.md