Install
openclaw skills install feishu-send-file-directly飞书消息直接发送文件附件技能。当用户需要直接通过飞书消息发送文件附件(而不是文档链接)时使用此技能。
openclaw skills install feishu-send-file-directly本技能提供了通过飞书消息直接发送文件附件的工作流程,解决了发送文档链接而非直接文件的问题。
使用 message 工具的 path 参数直接发送本地文件,避免使用 media 参数发送文档链接。
// 步骤1:创建或确认文件存在
write({
path: "/path/to/your/file.docx",
content: "文件内容..."
});
// 步骤2:发送文件附件
message({
action: "send",
message: "文件说明",
path: "/path/to/your/file.docx", // 关键:使用path参数
filename: "自定义文件名.docx" // 可选:设置显示名称
});
// 查找所有.docx和.pdf文件
exec({
command: "find /root/.openclaw/workspace/ -name '*.docx' -o -name '*.pdf'"
});
// 逐个发送找到的文件
const files = ["file1.docx", "file2.pdf"];
files.forEach(file => {
message({
action: "send",
message: `发送文件: ${file}`,
path: `/root/.openclaw/workspace/${file}`,
filename: file
});
});
| 参数 | 类型 | 必需 | 说明 | 示例 |
|---|---|---|---|---|
action | string | 是 | 操作类型,固定为"send" | "send" |
message | string | 是 | 消息正文内容 | "这是要发送的文件" |
path | string | 是 | 本地文件绝对路径 | "/root/.openclaw/workspace/file.pdf" |
filename | string | 否 | 客户端显示的文件名 | "报告.pdf" |
channel | string | 否 | 指定channel,默认当前channel | "feishu" |
write: 创建或修改文件内容exec: 查找、列出或验证文件read: 读取文件内容(发送前预览)1. 确认文件路径 → 2. 设置发送参数 → 3. 调用message发送 → 4. 验证结果
1. 查找目标文件 → 2. 过滤文件类型 → 3. 逐个发送文件 → 4. 统计发送结果
1. 创建文件内容 → 2. 保存到本地 → 3. 发送文件 → 4. 清理临时文件(可选)
// 创建PPT内容
const pptContent = `幻灯片1: 封面
- 标题: AI MaaS述职报告
- 汇报人: [姓名]
- 日期: ${new Date().toLocaleDateString()}
幻灯片2: 目录
1. 概述
2. 市场分析
3. 技术架构
4. 未来展望`;
// 保存文件
write({
path: "/tmp/ai_maas_report.ppt",
content: pptContent
});
// 发送文件
message({
action: "send",
message: "AI MaaS述职报告PPT",
path: "/tmp/ai_maas_report.ppt",
filename: "AI_MaaS_述职报告_2026.ppt"
});
// 查找工作区所有文档
exec({
command: "ls -la /root/.openclaw/workspace/*.docx /root/.openclaw/workspace/*.pdf 2>/dev/null || true"
});
// 假设找到以下文件
const documents = [
"项目报告.docx",
"技术方案.pdf",
"会议纪要.docx",
"数据分析.pdf"
];
// 发送进度提示
message({
action: "send",
message: `开始发送 ${documents.length} 个文档文件...`
});
// 逐个发送
documents.forEach((doc, index) => {
message({
action: "send",
message: `文档 ${index + 1}/${documents.length}: ${doc}`,
path: `/root/.openclaw/workspace/${doc}`,
filename: doc
});
});
// 发送完成提示
message({
action: "send",
message: `✅ 已完成发送 ${documents.length} 个文档文件`
});
// 注意:图片文件通常是二进制,需要用其他方式创建
// 这里假设图片已存在
message({
action: "send",
message: "产品设计图",
path: "/path/to/product_design.jpg",
filename: "产品设计图.jpg"
});
文件不存在错误
// 发送前检查文件
exec({
command: `test -f "/path/to/file" && echo "EXISTS" || echo "NOT_FOUND"`
});
权限错误
// 检查文件权限
exec({
command: "ls -la /path/to/file"
});
文件大小超限
// 检查文件大小(字节)
exec({
command: "stat -c%s /path/to/file"
});
try {
const result = message({
action: "send",
message: "文件",
path: "/path/to/file"
});
if (!result.ok) {
// 记录错误,尝试其他文件
console.error(`发送失败: ${result.error}`);
}
} catch (error) {
// 异常处理
console.error(`发送异常: ${error.message}`);
}
// 发送前预览文本文件内容
const content = read({
path: "/path/to/file.txt",
limit: 1000 // 预览前1000字符
});
message({
action: "send",
message: `文件预览:\n\`\`\`\n${content}\n\`\`\`\n\n完整文件见附件`,
path: "/path/to/file.txt",
filename: "file.txt"
});
// 获取文件信息
exec({
command: "stat --format='大小: %s 字节 | 修改时间: %y' /path/to/file"
});
// 发送带统计信息的文件
message({
action: "send",
message: `文件信息: ${fileInfo}\n\n文件见附件`,
path: "/path/to/file",
filename: "file.pdf"
});
// 检查文件大小并决定是否压缩
exec({
command: "find /path/to/file -size +10M -exec echo 'LARGE_FILE' \\;"
});
// 如果文件太大,先压缩
exec({
command: "zip -q /path/to/file.zip /path/to/file"
});
// 发送压缩文件
message({
action: "send",
message: "大文件已压缩",
path: "/path/to/file.zip",
filename: "file.zip"
});
A: 检查文件读取权限,确保OpenClaw进程有权限访问该文件。
A: 确认使用了path参数而不是media参数。
A: 使用英文文件名或确保编码正确。
A: 考虑压缩文件或分卷发送。
A: 添加错误重试机制,记录失败文件。
欢迎提交改进建议、错误报告或示例代码。请通过OpenClaw社区渠道提交。
技能创建者: OpenClaw Assistant
创建日期: 2026年4月13日
最后更新: 2026年4月13日
适用场景: 飞书消息直接发送文件附件