yunce: v5工作流设计 - 新增Markdown+HTML双输出、Write节点、公众号HTML模板
This commit is contained in:
@@ -1,16 +1,38 @@
|
||||
# N8N 内容转化流水线工作流设计(v4)
|
||||
# N8N 内容转化流水线工作流设计(v4 → v5 升级)
|
||||
|
||||
> 用于:AI 英文文章 → 中文公众号/X/视频 内容转化
|
||||
> 工作流ID:`iOf32aOKvTjfTDSM`
|
||||
> 工作流ID:`iOf32aOKvTjfTDSM`(v4基础)
|
||||
> 触发方式:OpenClaw 通过 Webhook 调用
|
||||
> 管理平台:Mac mini 上的 n8n (`https://n8n.ishenwei.online`)
|
||||
|
||||
---
|
||||
|
||||
## 📋 工作流概述
|
||||
## 📋 核心需求更新(v5)
|
||||
|
||||
**当前活跃版本:** v1 (`xQDabttYmLaY8qtr`) / v3 (`tOGMiC6qOJPOY89E`)
|
||||
**最新开发版本:** v4 (`iOf32aOKvTjfTDSM`) — 未激活
|
||||
### 输出要求(重要!)
|
||||
|
||||
**必须同时输出两个版本:**
|
||||
|
||||
| 输出文件 | 路径 | 格式 | 用途 |
|
||||
|---------|------|------|------|
|
||||
| **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 (发现文章)
|
||||
@@ -18,35 +40,36 @@ OpenClaw (发现文章)
|
||||
↓ (触发 Webhook)
|
||||
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ N8N 工作流 (v4): content-translation-pipeline-v4 │
|
||||
│ N8N 工作流 (v5): content-translation-pipeline-v5 │
|
||||
│ │
|
||||
│ [Webhook] → [Read File] → [Extract Text] → [AI Agent] │
|
||||
│ ↓ ↑ (DeepSeek) │
|
||||
│ [Convert to File] → [Write File] → [Send Telegram] │
|
||||
│ ↓ ↑ (DeepSeek) │
|
||||
│ [Build Markdown] → [Write .md] → [Build HTML] → [Write .html] │
|
||||
│ ↓ │
|
||||
│ [Send Telegram] │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔌 节点详细设计(v4)
|
||||
## 🔌 节点详细设计(v5)
|
||||
|
||||
### 节点 1️⃣:Webhook Trigger
|
||||
|
||||
**类型:** Webhook
|
||||
**名称:** `Webhook Trigger`
|
||||
**Path:** `/content-translation-v4`
|
||||
**Path:** `/content-translation-v5`(新建 path)
|
||||
**Method:** POST
|
||||
|
||||
**接收数据格式:**
|
||||
```json
|
||||
{
|
||||
"note_name": "article-2026-03-29.md",
|
||||
"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"
|
||||
}
|
||||
```
|
||||
|
||||
**注意:** v4 使用 `note_name`(文件名)而非 `note_path`,文件需预先上传到 n8n 容器的 `/home/node/.n8n-files/` 目录。
|
||||
|
||||
---
|
||||
|
||||
### 节点 2️⃣:Read Obsidian Note
|
||||
@@ -56,9 +79,6 @@ OpenClaw (发现文章)
|
||||
|
||||
**配置:**
|
||||
- File Path: `=/home/node/.n8n-files/{{ $json.body.note_name }}`
|
||||
- n8n 容器内文件路径: `/home/node/.n8n-files/`
|
||||
|
||||
**输出:** 二进制文件数据,传递给 Extract from File 节点
|
||||
|
||||
---
|
||||
|
||||
@@ -68,33 +88,23 @@ OpenClaw (发现文章)
|
||||
**名称:** `Extract from File`
|
||||
**Operation:** `text`
|
||||
|
||||
**功能:** 从二进制文件提取文本内容
|
||||
|
||||
**输出变量:**
|
||||
- `original_content`(原文内容)
|
||||
- `note_name`(文件名)
|
||||
- `callback_url`(回调地址)
|
||||
**输出:**
|
||||
```json
|
||||
{
|
||||
"original_content": "...",
|
||||
"note_name": "2026-03-29-ai-solopreneur.md",
|
||||
"source_path": "/Users/weishen/Workspace/nexus/openclaw/content-queue/..."
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 节点 4️⃣:DeepSeek Chat Model
|
||||
|
||||
**类型:** LM Chat DeepSeek
|
||||
**名称:** `DeepSeek Chat Model`
|
||||
|
||||
**配置:**
|
||||
- Model: `deepseek-chat`
|
||||
- Credentials: `DeepSeek account`(在 n8n 中配置)
|
||||
|
||||
**连接:** → AI Agent(作为 languageModel 输入)
|
||||
|
||||
---
|
||||
|
||||
### 节点 5️⃣:AI Agent
|
||||
### 节点 4️⃣:AI Agent(翻译+改写)
|
||||
|
||||
**类型:** LangChain Agent
|
||||
**名称:** `AI Agent`
|
||||
**Version:** 3.1
|
||||
**Model:** DeepSeek Chat Model
|
||||
|
||||
**Prompt 模板:**
|
||||
```
|
||||
@@ -137,58 +147,242 @@ OpenClaw (发现文章)
|
||||
|
||||
---
|
||||
|
||||
### 节点 6️⃣:Convert to File
|
||||
### 节点 5️⃣:Build Markdown(新增)
|
||||
|
||||
**类型:** Convert to File
|
||||
**名称:** `Convert to File`
|
||||
**Operation:** `toJson`
|
||||
**类型:** Code
|
||||
**名称:** `Build Markdown`
|
||||
|
||||
**功能:** 将 AI Agent 输出转换为 JSON 格式文件
|
||||
**功能:** 将 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}
|
||||
|
||||
---
|
||||
|
||||
### 节点 7️⃣:Read/Write Files from Disk
|
||||
## X/Twitter 文案
|
||||
|
||||
**类型:** Read/Write File
|
||||
**名称:** `Read/Write Files from Disk`
|
||||
**Operation:** `write`
|
||||
${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`
|
||||
|
||||
**配置:**
|
||||
- File Name: `=/home/node/.n8n-files/{{ $('Webhook Trigger').item.json.body.note_name }}_output.md`
|
||||
|
||||
**输出变量:**
|
||||
- `output_file_name`
|
||||
- `output_content`
|
||||
- Operation: `write`
|
||||
- File Path: `={{ $json.output_path }}`
|
||||
- Content: `={{ $json.output_content }}`
|
||||
|
||||
---
|
||||
|
||||
### 节点 8️⃣:Send Telegram Message
|
||||
### 节点 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 noteName = $('Webhook Trigger').first().json.body.note_name;
|
||||
const htmlPath = '/Users/weishen/Workspace/nexus/openclaw/content-output/' + noteName.replace('.md', '.html');
|
||||
|
||||
// 公众号 HTML 模板
|
||||
const html = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 1.8;
|
||||
color: #333;
|
||||
max-width: 100%;
|
||||
padding: 20px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
color: #1a1a1a;
|
||||
margin-bottom: 30px;
|
||||
font-weight: 600;
|
||||
}
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
color: #1a1a1a;
|
||||
margin-top: 30px;
|
||||
margin-bottom: 15px;
|
||||
font-weight: 600;
|
||||
border-left: 4px solid #007aff;
|
||||
padding-left: 12px;
|
||||
}
|
||||
p {
|
||||
text-align: justify;
|
||||
margin-bottom: 16px;
|
||||
text-indent: 2em;
|
||||
}
|
||||
.twitter-copy {
|
||||
background: #f5f5f5;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 15px;
|
||||
}
|
||||
.video-info {
|
||||
background: #f0f7ff;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.video-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #007aff;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.script {
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
color: #555;
|
||||
}
|
||||
.cover-keywords {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>${data.wechat_title}</h1>
|
||||
|
||||
${data.wechat_content.split('\n').map(line => {
|
||||
if (line.startsWith('# ')) return `<h1 style="text-align:center;font-size:24px;margin:30px 0;">${line.slice(2)}</h1>`;
|
||||
if (line.startsWith('## ')) return `<h2>${line.slice(3)}</h2>`;
|
||||
if (line.startsWith('### ')) return `<h3 style="font-size:17px;color:#333;margin:20px 0 10px;">${line.slice(4)}</h3>`;
|
||||
if (line.trim() === '---') return '<hr style="border:none;border-top:1px solid #eee;margin:30px 0;">';
|
||||
if (line.startsWith('- ') || line.startsWith('* ')) return `<li style="margin:8px 0;">${line.slice(2)}</li>`;
|
||||
if (line.trim() === '') return '';
|
||||
return `<p>${line}</p>`;
|
||||
}).join('\n')}
|
||||
|
||||
<div class="twitter-copy">
|
||||
<strong>📱 X/Twitter 文案:</strong><br>
|
||||
${data.twitter_copy.replace(/\n/g, '<br>')}
|
||||
</div>
|
||||
|
||||
<div class="video-info">
|
||||
<div class="video-title">🎬 视频标题:${data.video_title}</div>
|
||||
<div class="script">
|
||||
<strong>口播脚本:</strong><br>
|
||||
${data.video_script.replace(/\n/g, '<br>')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cover-keywords">
|
||||
封面图关键词:${data.cover_keywords?.join(' | ')}<br>
|
||||
原文路径:${$('Webhook Trigger').first().json.body.source_path}
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
return {
|
||||
json: {
|
||||
html_path: htmlPath,
|
||||
html_content: html
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 节点 8️⃣:Write .html File(新增)
|
||||
|
||||
**类型:** Write Binary File / ReadWriteFile
|
||||
**名称:** `Write WeChat HTML`
|
||||
|
||||
**配置:**
|
||||
- Operation: `write`
|
||||
- File Path: `={{ $json.html_path }}`
|
||||
- Content: `={{ $json.html_content }}`
|
||||
|
||||
---
|
||||
|
||||
### 节点 9️⃣:Send Telegram Message
|
||||
|
||||
**类型:** Telegram
|
||||
**名称:** `Send Telegram Message`
|
||||
|
||||
**配置:**
|
||||
- Chat ID: `5038825565`
|
||||
- Text: "文章转换成功"
|
||||
- Credentials: `Telegram XingJiang Bot`
|
||||
- Text:
|
||||
```
|
||||
✅ 文章转换完成!
|
||||
|
||||
**功能:** 通知星匠/用户工作流已完成
|
||||
📝 标题:{{ $json.wechat_title }}
|
||||
📁 Markdown:{{ $json.output_path }}
|
||||
🌐 HTML:{{ $json.html_path }}
|
||||
🐦 Twitter 文案:{{ $json.twitter_copy }}
|
||||
```
|
||||
- Credentials: `Telegram XingJiang Bot`
|
||||
|
||||
---
|
||||
|
||||
## 🔗 完整节点连接图(v4)
|
||||
## 🔗 完整节点连接图(v5)
|
||||
|
||||
```
|
||||
┌─────────────────────────────────┐
|
||||
│ Webhook Trigger │
|
||||
│ POST /content-translation-v4 │
|
||||
│ POST /content-translation-v5 │
|
||||
└──────────────┬──────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────┐
|
||||
│ Read Obsidian Note │
|
||||
│ (Read Binary File) │
|
||||
│ /home/node/.n8n-files/ │
|
||||
└──────────────┬──────────────────┘
|
||||
│
|
||||
▼
|
||||
@@ -213,19 +407,32 @@ OpenClaw (发现文章)
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────┐
|
||||
│ Convert to File (toJson) │
|
||||
│ Build Markdown (NEW) │
|
||||
│ 组装中文 Markdown 文件 │
|
||||
└──────────────┬──────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────┐
|
||||
│ Read/Write Files from Disk │
|
||||
│ (write output .md) │
|
||||
│ Write Markdown Note (NEW) │
|
||||
│ → content-output/*.md │
|
||||
└──────────────┬──────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────┐
|
||||
│ Build WeChat HTML (NEW) │
|
||||
│ Markdown → 带样式 HTML │
|
||||
└──────────────┬──────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────┐
|
||||
│ Write WeChat HTML (NEW) │
|
||||
│ → content-output/*.html │
|
||||
└──────────────┬──────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────┐
|
||||
│ Send Telegram Message │
|
||||
│ 文章转换成功 │
|
||||
│ 文章转换完成通知 │
|
||||
└─────────────────────────────────┘
|
||||
```
|
||||
|
||||
@@ -234,80 +441,48 @@ OpenClaw (发现文章)
|
||||
## 🔄 调用方式(OpenClaw 侧)
|
||||
|
||||
```bash
|
||||
# 1. 将文章文件复制到 n8n-files 目录(通过 SFTP 或共享目录)
|
||||
scp article.md macmini:/tmp/article.md
|
||||
# 需要手动或通过 API 上传到 n8n 容器的 /home/node/.n8n-files/
|
||||
# 1. 将文章文件复制到 n8n-files 目录
|
||||
scp /path/to/article.md macmini:/tmp/article.md
|
||||
|
||||
# 2. 触发 n8n 工作流
|
||||
curl -X POST "https://n8n.ishenwei.online/webhook/content-translation-v4" \
|
||||
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",
|
||||
"callback_url": "http://192.168.3.189:18789/webhook/yunce"
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📁 Obsidian / n8n 文件目录结构
|
||||
## 📁 最终 Obsidian 目录结构
|
||||
|
||||
```
|
||||
# n8n 容器内
|
||||
/home/node/.n8n-files/
|
||||
├── article-2026-03-29.md # 原始文章(待处理)
|
||||
└── article-2026-03-29.md_output.md # 成品笔记(转换后)
|
||||
|
||||
# MacMini Obsidian(OpenClaw 读取目录)
|
||||
~/Workspace/nexus/openclaw/
|
||||
├── content-queue/ # 待处理文章队列
|
||||
└── content-output/ # 成品输出目录
|
||||
├── content-queue/ # 输入
|
||||
│ └── article-2026-03-29.md # 原始英文
|
||||
│
|
||||
└── content-output/ # 输出(v5 新增)
|
||||
├── article-2026-03-29.md # 中文 Markdown
|
||||
└── article-2026-03-29.html # 公众号 HTML ✅
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔧 各版本对比
|
||||
|
||||
| 版本 | ID | 状态 | AI Provider | 特点 |
|
||||
|------|-----|------|-------------|------|
|
||||
| **v1** | `xQDabttYmLaY8qtr` | ✅ 活跃 | DeepSeek (LangChain Agent) | 读 Obsidian 路径,写入 content-output |
|
||||
| **v2** | `r0v9WAmed2THfN81` | ❌ 未激活 | OpenAI (n8n-nodes-langchain) | 基于 GPT-4o |
|
||||
| **v3** | `tOGMiC6qOJPOY89E` | ✅ 活跃 | DeepSeek (直接 API) | 直接调用 DeepSeek API,稳定性更好 |
|
||||
| **v4** | `iOf32aOKvTjfTDSM` | ❌ 未激活 | DeepSeek (LangChain Agent) | 最新版本,用 n8n-files 路径 |
|
||||
|
||||
---
|
||||
|
||||
## 🔧 环境变量 / Credentials
|
||||
|
||||
| 配置项 | 值 |
|
||||
|--------|-----|
|
||||
| DeepSeek API | 通过 n8n credential `DeepSeek account` (ID: `T7yJumbH684ClWfI`) |
|
||||
| Telegram Bot | `Telegram XingJiang Bot` (ID: `y1NdRSaJwl0LoY37`) |
|
||||
| Unsplash API | 在 v1/v2 中使用,v3/v4 未使用 |
|
||||
|
||||
---
|
||||
|
||||
## ✅ 验收标准
|
||||
|
||||
1. Webhook 被调用后,整个流程自动完成
|
||||
2. 成品文件写入 `/home/node/.n8n-files/{note_name}_output.md`
|
||||
3. Telegram 收到完成通知
|
||||
4. 任意节点失败时,n8n 会中断流程并记录错误
|
||||
1. 触发后自动完成整个流程,无需人工干预
|
||||
2. `content-output/` 目录同时生成 `.md` 和 `.html` 两个文件
|
||||
3. HTML 文件可直接复制粘贴到微信公众号编辑器,格式基本正确
|
||||
4. Telegram 收到完成通知(含标题和文件路径)
|
||||
5. 错误时 n8n 记录错误节点并停止流程
|
||||
|
||||
---
|
||||
|
||||
## 📝 待完善项(v4)
|
||||
## 📝 备注
|
||||
|
||||
- [ ] 成品文件需要写回 Obsidian 目录(目前只写到 n8n-files)
|
||||
- [ ] 封面图搜索节点(v4 已移除 v1 的 Unsplash 配图功能)
|
||||
- [ ] OpenClaw 回调通知(v4 改为 Telegram 通知,需确认是否符合预期)
|
||||
- [ ] v4 激活前需完成联调测试
|
||||
|
||||
---
|
||||
|
||||
## 📝 后续扩展方向
|
||||
|
||||
- [ ] 加入封面图搜索(恢复 Unsplash 节点)
|
||||
- [ ] 写回 Obsidian content-output 目录
|
||||
- [ ] 支持 X/Twitter API 自动发布
|
||||
- [ ] 支持抖音/YouTube 视频上传 API
|
||||
- [ ] 加入人工审核节点(审批后再发布)
|
||||
- **Markdown 源文件**:保留中文原文,方便后续修改和溯源
|
||||
- **HTML 文件**:带内联样式,兼容微信公众号编辑器,复制后格式不走形
|
||||
- **文件路径**:写入 Obsidian vault 的 `content-output/` 子目录,需确保 n8n 容器有对应目录的写权限
|
||||
- **API Key**:DeepSeek API 通过 n8n credential 配置,无需在代码中硬编码
|
||||
|
||||
Reference in New Issue
Block a user