DingTalk File Send Skill
Upload files to DingTalk media server and send them to specified users.
Automatically detects DingTalk account from current session binding.
When to Use
✅ USE this skill when:
- - "Send this PDF to [user]"
- "Forward this document via DingTalk"
- "Share this file with my boss"
- "Upload and send [filename]"
Configuration (Automatic)
This skill automatically detects the DingTalk account from your current session:
How it works:
- 1. Reads current agent ID from OpenClaw runtime context
- Looks up the binding in INLINECODE0
- Matches
agentId → accountId → DingTalk credentials
Binding example:
CODEBLOCK0
Note: In DingTalk's API, clientId is used as appKey for authentication.
Workflow
CODEBLOCK1
Commands
Step 1: Detect Account from Current Session
CODEBLOCK2
Step 2: Get Access Token
CODEBLOCK3
Step 3: Upload File
CODEBLOCK4
Step 4: Send File Message
CODEBLOCK5
Complete Script
CODEBLOCK6
Supported File Types
| Type | Extensions | Max Size |
|---|
| PDF | INLINECODE5 | 20 MB |
| Document |
.doc,
.docx,
.xls,
.xlsx,
.ppt,
.pptx | 20 MB |
| Image |
.jpg,
.jpeg,
.png,
.gif,
.bmp | 10 MB |
| Other |
.txt,
.zip,
.rar | 20 MB |
Environment Variables
| Variable | Description | Required |
|---|
| INLINECODE20 | Current agent ID (auto-set by OpenClaw runtime) | Auto |
Response Handling
Success response:
CODEBLOCK7
Check delivery status:
CODEBLOCK8
Notes
- - Fully automatic — detects account from current session, no configuration needed
- Media files expire after 30 days on DingTalk server
- Max file size: 20 MB for files, 10 MB for images
- Access token expires after 2 hours
- Rate limit: ~100 requests/second per app
- Works with any DingTalk account bound in OpenClaw config
Common Issues
"Account not found in OpenClaw config"
→ Check bindings: jq '.bindings[] | select(.agentId == "current-agent-id")' ~/.openclaw/openclaw.json
→ Verify account exists: INLINECODE22
"Failed to get access token"
→ Verify clientId/clientSecret in OpenClaw config are correct and not expired.
"Invalid media_id"
→ File upload failed or expired. Re-upload and get new media_id.
"Invalid userId"
→ Check the recipient's DingTalk user ID format.
File shows but can't open
→ Ensure file is valid (not HTML renamed to .pdf, etc.)
Security Notes
- - No hardcoded credentials — reads from OpenClaw config only
- Session-based account detection — uses current agent's bound account
- Access token is generated on-demand and not stored
- Credentials never leave your machine except for DingTalk API calls
钉钉文件发送技能
将文件上传至钉钉媒体服务器,并发送给指定用户。
自动从当前会话绑定中检测钉钉账号。
使用场景
✅ 使用此技能的场景:
- - 将此PDF发送给[用户]
- 通过钉钉转发此文档
- 与我的老板共享此文件
- 上传并发送[文件名]
配置(自动)
此技能自动检测当前会话中的钉钉账号:
工作原理:
- 1. 从OpenClaw运行时上下文读取当前代理ID
- 在~/.openclaw/openclaw.json中查找绑定关系
- 匹配agentId → accountId → 钉钉凭证
绑定示例:
json
{
bindings: [
{
agentId: dingtalk-office,
match: {
channel: dingtalk,
accountId: office
}
}
],
channels: {
dingtalk: {
accounts: {
office: {
clientId: yourclientid,
clientSecret: xxx,
robotCode: yourrobotcode
}
}
}
}
}
注意: 在钉钉API中,clientId用作appKey进行身份认证。
工作流程
- 1. 从会话上下文检测当前agentId
- 查找绑定关系:agentId → accountId
- 根据accountId从OpenClaw配置读取凭证
- 获取访问令牌
- 将文件上传至钉钉媒体服务器
- 向接收者发送文件消息
命令
步骤1:从当前会话检测账号
bash
OPENCLAW_CONFIG=~/.openclaw/openclaw.json
从环境获取当前代理ID(由OpenClaw运行时设置)
AGENT
ID=${OPENCLAWAGENT_ID:-dingtalk-office}
从绑定关系中查找accountId
ACCOUNT
ID=$(jq -r .bindings[] | select(.agentId == \$AGENTID\) | .match.accountId $OPENCLAW_CONFIG)
回退:如果未找到绑定关系,使用代理ID后缀
if [ -z $ACCOUNT
ID ] || [ $ACCOUNTID = null ]; then
# 从代理ID中提取账号(例如:dingtalk-office → office)
ACCOUNT
ID=$(echo $AGENTID | sed s/dingtalk-//)
fi
读取凭证(clientId用作appKey)
APP
KEY=$(jq -r .channels.dingtalk.accounts[\$ACCOUNTID\].clientId $OPENCLAW_CONFIG)
APP
SECRET=$(jq -r .channels.dingtalk.accounts[\$ACCOUNTID\].clientSecret $OPENCLAW_CONFIG)
ROBOT
CODE=$(jq -r .channels.dingtalk.accounts[\$ACCOUNTID\].robotCode $OPENCLAW_CONFIG)
验证
if [ $APP
KEY = null ] || [ $APPSECRET = null ] || [ $ROBOT_CODE = null ]; then
echo ❌ 在OpenClaw配置中未找到账号$ACCOUNT_ID。
echo 当前代理:$AGENT_ID
echo 可用账号:$(jq -r .channels.dingtalk.accounts | keys | join(, ) $OPENCLAW_CONFIG)
exit 1
fi
步骤2:获取访问令牌
bash
ACCESS_TOKEN=$(curl -s -X POST https://api.dingtalk.com/v1.0/oauth2/accessToken \
-H Content-Type: application/json \
-d {\appKey\:\$APPKEY\,\appSecret\:\$APPSECRET\} | jq -r .accessToken)
if [ -z $ACCESSTOKEN ] || [ $ACCESSTOKEN = null ]; then
echo ❌ 获取访问令牌失败。
exit 1
fi
步骤3:上传文件
bash
FILE_PATH=$1
FILENAME=$(basename $FILEPATH)
UPLOADRESULT=$(curl -s -X POST https://oapi.dingtalk.com/media/upload?accesstoken=$ACCESSTOKEN&type=file&robotCode=$ROBOTCODE \
-F media=@$FILEPATH;filename=$FILENAME \
-H Expect:)
MEDIAID=$(echo $UPLOADRESULT | jq -r .media_id)
if [ -z $MEDIAID ] || [ $MEDIAID = null ]; then
echo ❌ 上传失败:$UPLOAD_RESULT
exit 1
fi
步骤4:发送文件消息
bash
USER_ID=$2
FILEEXT=${FILENAME##*.}
PAYLOAD=$(jq -n \
--arg robotCode $ROBOT_CODE \
--arg msgKey sampleFile \
--arg mediaId $MEDIA_ID \
--arg fileName $FILE_NAME \
--arg fileType $FILE_EXT \
--arg userId $USER_ID \
{
robotCode: $robotCode,
msgKey: $msgKey,
msgParam: ({
mediaId: $mediaId,
fileName: $fileName,
fileType: $fileType
} | tojson),
userIds: [$userId]
})
SEND_RESULT=$(curl -s -X POST https://api.dingtalk.com/v1.0/robot/oToMessages/batchSend \
-H Content-Type: application/json \
-H x-acs-dingtalk-access-token: $ACCESS_TOKEN \
-d $PAYLOAD)
PROCESSKEY=$(echo $SENDRESULT | jq -r .processQueryKey // empty)
if [ -n $PROCESS_KEY ]; then
echo ✅ 文件发送成功!
echo ProcessQueryKey:$PROCESS_KEY
else
echo ❌ 发送失败:$SEND_RESULT
exit 1
fi
完整脚本
bash
#!/bin/bash
用法:senddingtalkfile.sh <文件路径> <用户ID>
自动从当前会话检测钉钉账号
set -e
OPENCLAW_CONFIG=~/.openclaw/openclaw.json
检查配置文件
if [ ! -f $OPENCLAW_CONFIG ]; then
echo ❌ 未找到OpenClaw配置:$OPENCLAW_CONFIG
exit 1
fi
检查文件参数
FILE_PATH=$1
USER_ID=$2
if [ -z $FILEPATH ] || [ -z $USERID ]; then
echo 用法:$0 <文件路径> <用户ID>
exit 1
fi
if [ ! -f $FILE_PATH ]; then
echo ❌ 未找到文件:$FILE_PATH
exit 1
fi
从环境获取当前代理ID(由OpenClaw运行时设置)
AGENT
ID=${OPENCLAWAGENT_ID:-dingtalk-office}
从绑定关系中查找accountId
ACCOUNT
ID=$(jq -r .bindings[] | select(.agentId == \$AGENTID\) | .match.accountId $OPENCLAW_CONFIG)
回退:如果未找到绑定关系,使用代理ID后缀
if [ -z $ACCOUNT
ID ] || [ $ACCOUNTID = null ]; then
ACCOUNT
ID=$(echo $AGENTID | sed s/dingtalk-//)
fi
从OpenClaw配置读取凭证
APP
KEY=$(jq -r .channels.dingtalk.accounts[\$ACCOUNTID\].clientId $OPENCLAW_CONFIG)
APP
SECRET=$(jq -r .channels.dingtalk.accounts[\$ACCOUNTID\].clientSecret $OPENCLAW_CONFIG)
ROBOT
CODE=$(jq -r .channels.dingtalk.accounts[\$ACCOUNTID\].robotCode $OPENCLAW_CONFIG)
验证凭证
if [ $APP
KEY = null ] || [ $APPSECRET = null ] || [ $ROBOT_CODE = null ]; then
echo ❌ 在OpenClaw配置中未找到账号$ACCOUNT_ID。
echo 当前代理:$AGENT_ID
echo 可用账号:$(jq -r .channels.dingtalk.accounts | keys | join(, ) $OPENCLAW_CONFIG)
exit 1
fi
FILENAME=$(basename $FILEPATH)
FILEEXT=${FILENAME##*.}
获取访问令牌
ACCESS_TOKEN=$(curl -s