# N8N 内容转化流水线工作流设计(v4 → v5 升级)
> 用于:AI 英文文章 → 中文公众号/X/视频 内容转化
> 工作流ID:`iOf32aOKvTjfTDSM`(v4基础)
> 触发方式:OpenClaw 通过 Webhook 调用
> 管理平台:Mac mini 上的 n8n (`https://n8n.ishenwei.online`)
---
## 📋 核心需求更新(v5)
### 输出要求(重要!)
**必须同时输出两个版本:**
| 输出文件 | 路径 | 格式 | 用途 |
|---------|------|------|------|
| **Markdown 源文件** | `content-output/{原文件名}.md` | 中文 Markdown | Obsidian 留存、溯源 |
| **公众号 HTML** | `content-output/{原文件名}.html` | 带样式的 HTML | 直接复制到公众号编辑器 |
### Obsidian 目录结构
```
~/Workspace/nexus/openclaw/
├── content-queue/ # 原始英文文章(输入)
│ └── 2026-03-29-ai-solopreneur.md
│
└── content-output/ # 成品(输出)
├── 2026-03-29-ai-solopreneur.md # 翻译后 Markdown
└── 2026-03-29-ai-solopreneur.html # 公众号 HTML(新增)
```
---
## 📋 工作流概述
```
OpenClaw (发现文章)
↓ (保存文件到 n8n-files 目录)
↓ (触发 Webhook)
┌─────────────────────────────────────────────────────────────┐
│ N8N 工作流 (v5): content-translation-pipeline-v5 │
│ │
│ [Webhook] → [Read File] → [Extract Text] → [AI Agent] │
│ ↓ ↑ (DeepSeek) │
│ [Build Markdown] → [Write .md] → [Build HTML] → [Write .html] │
│ ↓ │
│ [Send Telegram] │
└─────────────────────────────────────────────────────────────┘
```
---
## 🔌 节点详细设计(v5)
### 节点 1️⃣:Webhook Trigger
**类型:** Webhook
**名称:** `Webhook Trigger`
**Path:** `/content-translation-v5`(新建 path)
**Method:** POST
**接收数据格式:**
```json
{
"note_name": "2026-03-29-ai-solopreneur.md",
"source_path": "/Users/weishen/Workspace/nexus/openclaw/content-queue/2026-03-29-ai-solopreneur.md",
"callback_url": "http://192.168.3.189:18789/webhook/yunce"
}
```
---
### 节点 2️⃣:Read Obsidian Note
**类型:** Read Binary File
**名称:** `Read Obsidian Note`
**配置:**
- File Path: `=/home/node/.n8n-files/{{ $json.body.note_name }}`
---
### 节点 3️⃣:Extract from File
**类型:** Extract from File
**名称:** `Extract from File`
**Operation:** `text`
**输出:**
```json
{
"original_content": "...",
"note_name": "2026-03-29-ai-solopreneur.md",
"source_path": "/Users/weishen/Workspace/nexus/openclaw/content-queue/..."
}
```
---
### 节点 4️⃣:AI Agent(翻译+改写)
**类型:** LangChain Agent
**名称:** `AI Agent`
**Version:** 3.1
**Model:** DeepSeek Chat Model
**Prompt 模板:**
```
你是一个专业的中文内容编辑,擅长将英文文章转化为适合中国读者的高质量内容。
## 你的任务
将以下英文原文转化为:
1. 公众号风格的深度文章(2000-3000字)
2. X/Twitter 风格的短文案(280字内,带钩子)
3. 视频口播脚本(3-5分钟,适合抖音/YouTube)
## 内容要求
- 语言:地道中文,无翻译腔
- 风格:专业、有干货、适合中国读者
- 调性:公众号大V风格,有观点有案例
- 商业化:可自然植入 AI Agent / 知识管理相关内容(软性,不硬广)
## 文章主题方向(供校准时参考)
- AI Agent 落地实践与工具推荐
- AI 赋能商业的最佳实践
- AI 时代的网络安全与运维
## 输出格式(严格按此 JSON 返回)
{
"wechat_title": "中文标题",
"wechat_excerpt": "公众号摘要(100字内)",
"wechat_content": "完整公众号文章(Markdown格式)",
"twitter_copy": "X/Twitter文案(280字内,带emoji)",
"video_title": "视频标题",
"video_script": "口播脚本(含时间戳和字幕)",
"cover_keywords": ["关键词1", "关键词2", "关键词3"]
}
## 原文内容
{{ $json.data }}
```
---
### 节点 5️⃣:Build Markdown(新增)
**类型:** Code
**名称:** `Build Markdown`
**功能:** 将 AI 输出组装成 Markdown 文件
```javascript
const aiResult = $input.first().json.message;
const data = typeof aiResult === 'string' ? JSON.parse(aiResult) : aiResult;
const noteName = $('Webhook Trigger').first().json.body.note_name;
// 去掉 .md 后缀,输出到 content-output
const outputName = noteName.replace('.md', '.md');
const outputPath = '/Users/weishen/Workspace/nexus/openclaw/content-output/' + outputName;
const markdown = `# ${data.wechat_title}
${data.wechat_content}
---
## X/Twitter 文案
${data.twitter_copy}
---
## 视频信息
**标题:** ${data.video_title}
**口播脚本:**
${data.video_script}
---
*封面图关键词:${data.cover_keywords?.join(', ')}*
`;
return {
json: {
output_path: outputPath,
output_content: markdown,
source_path: $('Webhook Trigger').first().json.body.source_path
}
};
```
---
### 节点 6️⃣:Write .md File(新增)
**类型:** Write Binary File / ReadWriteFile
**名称:** `Write Markdown Note`
**配置:**
- Operation: `write`
- File Path: `=/home/node/.n8n-files/{{ $json.body.output_name }}_output.md`
- Content: `={{ $json.output_content }}`
**注意:** 输出到 n8n-files/ 目录,由 OpenClaw 负责复制回 Obsidian。
---
### 节点 7️⃣:Build HTML(新增,核心)
**类型:** Code
**名称:** `Build WeChat HTML`
**功能:** 将 Markdown 转为带样式的公众号 HTML
```javascript
const aiResult = $input.first().json.message;
const data = typeof aiResult === 'string' ? JSON.parse(aiResult) : aiResult;
const outputName = $('Webhook Trigger').first().json.body.output_name;
const htmlPath = '/home/node/.n8n-files/' + outputName + '_output.html';
// 公众号 HTML 模板
const html = `
${data.wechat_title}
${data.wechat_content.split('\n').map(line => {
if (line.startsWith('# ')) return `${line.slice(2)}
`;
if (line.startsWith('## ')) return `${line.slice(3)}
`;
if (line.startsWith('### ')) return `${line.slice(4)}
`;
if (line.trim() === '---') return '
';
if (line.startsWith('- ') || line.startsWith('* ')) return `${line.slice(2)}`;
if (line.trim() === '') return '';
return `${line}
`;
}).join('\n')}
🎬 视频标题:${data.video_title}
口播脚本:
${data.video_script.replace(/\n/g, '
')}
封面图关键词:${data.cover_keywords?.join(' | ')}
原文路径:${$('Webhook Trigger').first().json.body.source_path}
`;
return {
json: {
html_path: htmlPath,
html_content: html
}
};
```
---
### 节点 8️⃣:Write .html File(新增)
**类型:** Write Binary File / ReadWriteFile
**名称:** `Write WeChat HTML`
**配置:**
- Operation: `write`
- File Path: `=/home/node/.n8n-files/{{ $json.body.output_name }}_output.html`
- Content: `={{ $json.html_content }}`
**注意:** 输出到 n8n-files/ 目录,由 OpenClaw 负责复制回 Obsidian。
---
### 节点 9️⃣:Send Telegram Message
**类型:** Telegram
**名称:** `Send Telegram Message`
**配置:**
- Chat ID: `5038825565`
- Text:
```
✅ 文章转换完成!
📝 标题:{{ $json.wechat_title }}
📁 Markdown:/home/node/.n8n-files/{{ $json.body.output_name }}_output.md
🌐 HTML:/home/node/.n8n-files/{{ $json.body.output_name }}_output.html
🐦 Twitter 文案:{{ $json.twitter_copy }}
```
- Credentials: `Telegram XingJiang Bot`
**注意:** Telegram 只通知完成,OpenClaw 收到通知后负责将文件复制回 Obsidian。
---
## 🔗 完整节点连接图(v5)
```
┌─────────────────────────────────┐
│ Webhook Trigger │
│ POST /content-translation-v5 │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────┐
│ Read Obsidian Note │
│ (Read Binary File) │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────┐
│ Extract from File │
│ (text operation) │
└──────────────┬──────────────────┘
│
┌──────────┴──────────┐
│ │
│ ┌───────┴────────┐
│ │ DeepSeek │
│ │ Chat Model │
│ └───────┬────────┘
│ │
▼ ▼
┌─────────────────────────────────┐
│ AI Agent (LangChain) │
│ - system prompt │
│ - original content │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────┐
│ Build Markdown (NEW) │
│ 组装中文 Markdown 文件 │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────┐
│ Write Markdown Note (NEW) │
│ → content-output/*.md │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────┐
│ Build WeChat HTML (NEW) │
│ Markdown → 带样式 HTML │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────┐
│ Write WeChat HTML (NEW) │
│ → content-output/*.html │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────┐
│ Send Telegram Message │
│ 文章转换完成通知 │
└─────────────────────────────────┘
```
---
## 🔄 调用方式(OpenClaw 侧)
**重要说明:n8n 只能读写 `/home/node/.n8n-files/` 目录,无法直接访问 Obsidian 目录。因此 OpenClaw 负责文件搬运,n8n 专注处理。**
### OpenClaw 完整流程:
```bash
# =============================================
# 步骤 1:OpenClaw 复制原文到 n8n-files 目录
# =============================================
# SSH 到 MacMini,将源文件复制到 n8n 容器可访问的目录
scp /Users/weishen/Workspace/nexus/openclaw/content-queue/article-2026-03-29.md \
macmini:/home/node/.n8n-files/article-2026-03-29.md
# =============================================
# 步骤 2:OpenClaw 触发 n8n Webhook
# =============================================
curl -X POST "https://n8n.ishenwei.online/webhook/content-translation-v5" \
-H "Content-Type: application/json" \
-d '{
"note_name": "article-2026-03-29.md",
"source_path": "/Users/weishen/Workspace/nexus/openclaw/content-queue/article-2026-03-29.md",
"output_name": "article-2026-03-29",
"callback_url": "http://192.168.3.189:18789/webhook/yunce"
}'
# =============================================
# 步骤 3:n8n 流程执行中...
# =============================================
# n8n 读取 /home/node/.n8n-files/article-2026-03-29.md
# 处理(翻译、改写)
# 输出到 /home/node/.n8n-files/article-2026-03-29_output.md
# 输出到 /home/node/.n8n-files/article-2026-03-29_output.html
# 发送 Telegram 通知
# =============================================
# 步骤 4:OpenClaw 复制输出文件回 Obsidian(工作流完成后)
# =============================================
# 复制 Markdown 成品
scp macmini:/home/node/.n8n-files/article-2026-03-29_output.md \
/Users/weishen/Workspace/nexus/openclaw/content-output/article-2026-03-29.md
# 复制 HTML 成品
scp macmini:/home/node/.n8n-files/article-2026-03-29_output.html \
/Users/weishen/Workspace/nexus/openclaw/content-output/article-2026-03-29.html
# =============================================
# 步骤 5:清理 n8n-files 临时文件(可选)
# =============================================
ssh macmini "rm /home/node/.n8n-files/article-2026-03-29.md \
/home/node/.n8n-files/article-2026-03-29_output.md \
/home/node/.n8n-files/article-2026-03-29_output.html"
```
### 简化版 OpenClaw 代码流程:
```python
import subprocess
note_name = "article-2026-03-29.md"
source_path = "/Users/weishen/Workspace/nexus/openclaw/content-queue/" + note_name
output_name = note_name.replace('.md', '')
n8n_files = "/home/node/.n8n-files"
# 1. 复制原文到 n8n-files
subprocess.run(['scp', source_path, f'macmini:{n8n_files}/{note_name}'])
# 2. 触发 Webhook
subprocess.run(['curl', '-X', 'POST',
'https://n8n.ishenwei.online/webhook/content-translation-v5',
'-H', 'Content-Type: application/json',
'-d', f'{{"note_name": "{note_name}", "output_name": "{output_name}", ...}}'
])
# 3. 等待 Telegram 通知(工作流完成)
# 4. 复制输出回 Obsidian
subprocess.run(['scp',
f'macmini:{n8n_files}/{output_name}_output.md',
f'/Users/weishen/Workspace/nexus/openclaw/content-output/{output_name}.md'])
subprocess.run(['scp',
f'macmini:{n8n_files}/{output_name}_output.html',
f'/Users/weishen/Workspace/nexus/openclaw/content-output/{output_name}.html'])
```
---
## 📁 最终 Obsidian 目录结构
```
~/Workspace/nexus/openclaw/
├── content-queue/ # 原始英文(输入,OpenClaw 放置)
│ └── article-2026-03-29.md
│
└── content-output/ # 成品(OpenClaw 从 n8n-files/ 复制回来)
├── article-2026-03-29.md # 中文 Markdown ✅
└── article-2026-03-29.html # 公众号 HTML ✅
```
**文件来源说明:**
- n8n 工作流只读写 `/home/node/.n8n-files/` 目录
- OpenClaw 在工作流完成后负责将输出文件复制到 Obsidian 目录
---
## ✅ 验收标准
1. 触发后自动完成整个流程,无需人工干预
2. `content-output/` 目录同时生成 `.md` 和 `.html` 两个文件
3. HTML 文件可直接复制粘贴到微信公众号编辑器,格式基本正确
4. Telegram 收到完成通知(含标题和文件路径)
5. 错误时 n8n 记录错误节点并停止流程
---
## 📝 备注
- **Markdown 源文件**:保留中文原文,方便后续修改和溯源
- **HTML 文件**:带内联样式,兼容微信公众号编辑器,复制后格式不走形
- **文件路径**:写入 Obsidian vault 的 `content-output/` 子目录,需确保 n8n 容器有对应目录的写权限
- **API Key**:DeepSeek API 通过 n8n credential 配置,无需在代码中硬编码