Files
nexus/openclaw/yunce/n8n-content-pipeline-workflow.md
2026-03-30 14:13:23 +08:00

548 lines
19 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# N8N 内容转化流水线工作流设计v6
> 用于AI 英文文章 → 中文公众号/X/视频 内容转化
> 工作流 ID`iOf32aOKvTjfTDSM`v5 基础)
> 触发方式OpenClaw 通过 Webhook 调用
> 管理平台Mac mini 上的 n8n (`https://n8n.ishenwei.online`)
>
> **v6 变更(相比 v5**
> - ✅ 移除 Node 7Build HTML、Node 8Write HTML
> - ✅ n8n 仅输出 Markdown 文件HTML 转换不再需要
> - ✅ 最终输出纯 Markdown便于在 Obsidian 中编辑后再发布到公众号
> - ⚠️ Telegram 通知中的 HTML 相关字段已移除
> - ⚠️ 验收标准调整为仅检查 Markdown 文件
---
## 核心需求更新v6
### 输出要求
**单一输出:中文 Markdown 文件**
| 输出文件 | 路径 | 格式 | 用途 |
|---------|------|------|------|
| **Markdown 源文件** | `content-output/{原文件名}.md` | 中文 Markdown | Obsidian 留存、编辑、发布 |
> 不再生成公众号 HTML。公众号排版在 Obsidian 中手动完成,或通过其他工具转换。
### Obsidian 目录结构
```
~/Workspace/nexus/openclaw/
├── content-queue/ # 原始英文文章(输入)
│ └── 2026-03-29-ai-solopreneur.md
└── content-output/ # 成品输出v6 仅 Markdown
└── 2026-03-29-ai-solopreneur.md # 翻译后 Markdown ✅
```
---
## 工作流概述
```
OpenClaw (发现文章)
↓ (保存文件到 n8n-files 目录)
↓ (触发 Webhook)
┌─────────────────────────────────────────────────────────────┐
│ N8N 工作流 (v6): content-translation-pipeline-v6 │
│ │
│ [Webhook] → [Read File] → [Extract Text] → [AI Agent] │
│ ↓ ↑ (DeepSeek) │
│ [Build Markdown] → [Write .md] │
│ ↓ │
│ [Send Telegram] │
└─────────────────────────────────────────────────────────────┘
```
---
## 节点详细设计v6
### 节点 1Webhook Trigger
**类型:** Webhook
**名称:** `Webhook Trigger`
**Path** `/content-translation-v6`(新建 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",
"output_name": "2026-03-29-ai-solopreneur",
"callback_url": "http://192.168.3.189:18789/webhook/yunce"
}
```
---
### 节点 2Read Obsidian Note
**类型:** Read Binary File
**名称:** `Read Obsidian Note`
**配置:**
- File Path: `=/home/node/.n8n-files/{{ $json.body.note_name }}`
---
### 节点 3Extract from File
**类型:** Extract from File
**名称:** `Extract from File`
**Operation** `text`
---
### 节点 4AI 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 }}
```
---
### 节点 5Build Markdownv6 精简版)
**类型:** Code
**名称:** `Build Markdown`
**功能:** 将 AI 输出的 JSON 组装成结构清晰的 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;
const outputName = noteName.replace('.md', '');
const markdown = `# ${data.wechat_title}
> ${data.wechat_excerpt}
${data.wechat_content}
---
## X/Twitter 文案
${data.twitter_copy}
---
## 视频信息
**标题:** ${data.video_title}
**口播脚本:**
${data.video_script}
---
*封面图关键词:${data.cover_keywords?.join(', ')}*
`;
return {
json: {
output_name: outputName,
output_content: markdown,
source_path: $('Webhook Trigger').first().json.body.source_path
}
};
```
---
### 节点 6Write .md File
**类型:** Write Binary File / ReadWriteFile
**名称:** `Write Markdown Note`
**配置:**
- Operation: `write`
- File Path: `=/home/node/.n8n-files/{{ $json.output_name }}_output.md`
- Content: `={{ $json.output_content }}`
**注意:** 输出到 n8n-files/ 目录,由 OpenClaw 负责复制回 Obsidian。
---
### 节点 7Send Telegram Message
**类型:** Telegram
**名称:** `Send Telegram Message`
**配置:**
- Chat ID: `5038825565`
- Text:
```
✅ 文章转换完成!
📝 标题:${$json.wechat_title}
📁 Markdown/home/node/.n8n-files/${$json.output_name}_output.md
🐦 Twitter 文案:${$json.twitter_copy}
🎬 视频标题:${$json.video_title}
```
- Credentials: `Telegram XingJiang Bot`
**注意:** OpenClaw 收到通知后负责将 Markdown 文件复制回 Obsidian。
---
## 节点连接图v6
```
┌─────────────────────────────────┐
│ Webhook Trigger │
│ POST /content-translation-v6 │
└──────────────┬──────────────────┘
┌─────────────────────────────────┐
│ Read Obsidian Note │
│ (Read Binary File) │
└──────────────┬──────────────────┘
┌─────────────────────────────────┐
│ Extract from File │
│ (text operation) │
└──────────────┬──────────────────┘
┌──────────┴──────────┐
│ │
│ ┌───────┴────────┐
│ │ DeepSeek │
│ │ Chat Model │
│ └───────┬────────┘
│ │
▼ ▼
┌─────────────────────────────────┐
│ AI Agent (LangChain) │
│ 输出 JSON 格式结果 │
└──────────────┬──────────────────┘
┌─────────────────────────────────┐
│ Build Markdown │
│ 组装中文 Markdown 文件 │
└──────────────┬──────────────────┘
┌─────────────────────────────────┐
│ Write Markdown Note │
│ → content-output/*.md │
└──────────────┬──────────────────┘
┌─────────────────────────────────┐
│ Send Telegram Message │
│ Markdown 文件路径通知 │
└─────────────────────────────────┘
```
---
## 调用方式OpenClaw 侧)
**核心约束n8n 只能读写 `/home/node/.n8n-files/` 目录OpenClaw 负责文件搬运。**
### OpenClaw 完整流程v6
```bash
# =============================================
# 步骤 1OpenClaw 复制原文到 n8n-files 目录
# =============================================
scp /Users/weishen/Workspace/nexus/openclaw/content-queue/article-2026-03-29.md \
macmini:/home/node/.n8n-files/article-2026-03-29.md
# =============================================
# 步骤 2OpenClaw 触发 n8n Webhook
# =============================================
curl -X POST "https://n8n.ishenwei.online/webhook/content-translation-v6" \
-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"
}'
# =============================================
# 步骤 3n8n 流程执行中...
# =============================================
# n8n 读取 /home/node/.n8n-files/article-2026-03-29.md
# 处理(翻译、改写)
# 输出到 /home/node/.n8n-files/article-2026-03-29_output.md
# 发送 Telegram 通知
# =============================================
# 步骤 4OpenClaw 复制输出文件回 Obsidian工作流完成后
# =============================================
scp macmini:/home/node/.n8n-files/article-2026-03-29_output.md \
/Users/weishen/Workspace/nexus/openclaw/content-output/article-2026-03-29.md
# =============================================
# 步骤 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"
```
### OpenClaw Python 脚本模板v6
```python
import subprocess
import sys
# ========== 配置区 ==========
N8N_BASE_URL = "https://n8n.ishenwei.online"
WEBHOOK_PATH = "content-translation-v6" # <-- 实际 webhook path
SOURCE_FILE = "/path/to/source/file.md" # <-- 实际源文件路径
N8N_FILES = "/home/node/.n8n-files"
NOTE_NAME = "source-file.md" # <-- 实际文件名
OUTPUT_NAME = "source-file" # <-- 输出文件名(无扩展名)
OUTPUT_DIR = "/Users/weishen/Workspace/nexus/openclaw/content-output"
# ===================================
n8n_input_path = f"{N8N_FILES}/{NOTE_NAME}"
print(f"[Step 1/5] 复制输入文件到 N8N 容器: {NOTE_NAME}")
result = subprocess.run(
['scp', SOURCE_FILE, f'macmini:{n8n_input_path}'],
capture_output=True, text=True
)
if result.returncode != 0:
print(f"X 文件复制失败: {result.stderr}")
sys.exit(1)
print(f"V 已复制到 {n8n_input_path}")
print(f"[Step 2/5] 触发 N8N Webhook: {WEBHOOK_PATH}")
webhook_url = f"{N8N_BASE_URL}/webhook/{WEBHOOK_PATH}"
payload = ("{"
"\"note_name\": \"" + NOTE_NAME + "\", "
"\"source_path\": \"" + SOURCE_FILE + "\", "
"\"output_name\": \"" + OUTPUT_NAME + "\""
"}")
result = subprocess.run(
['curl', '-X', 'POST', webhook_url,
'-H', 'Content-Type: application/json',
'-d', payload],
capture_output=True, text=True
)
print(f"Webhook 触发响应: {result.stdout[:200]}")
print("[Step 3/5] 等待 N8N 执行完成Telegram 通知将发送到本会话)...")
print("请等待 Telegram 通知,收到后继续执行步骤 4。")
sys.exit(0) # <-- 退出等待通知
# ---- 以下为步骤 4 和 5需在收到 Telegram 通知后执行 ----
print(f"[Step 4/5] 复制输出文件回 Obsidian...")
output_file = f"{OUTPUT_NAME}_output.md"
src = f"macmini:{N8N_FILES}/{output_file}"
dst = f"{OUTPUT_DIR}/{output_file}"
result = subprocess.run(['scp', src, dst], capture_output=True, text=True)
if result.returncode == 0:
print(f" V {output_file}")
else:
print(f" X {result.stderr}")
print("[Step 5/5] 清理 N8N 容器临时文件...")
files_to_clean = [NOTE_NAME, output_file]
result = subprocess.run(
['ssh', 'macmini', 'rm'] + [f"{N8N_FILES}/{f}" for f in files_to_clean],
capture_output=True, text=True
)
if result.returncode == 0:
print(" V 清理完成")
else:
print(f" ! 清理失败(不影响结果): {result.stderr}")
print("🎉 工作流执行完毕!")
```
---
## Obsidian 最终目录结构v6
```
~/Workspace/nexus/openclaw/
├── content-queue/ # 原始英文输入OpenClaw 放置)
│ └── article-2026-03-29.md
└── content-output/ # 成品v6 仅 Markdown
└── article-2026-03-29.md # 中文 Markdown ✅
```
---
## 验收标准v6
1. 触发后自动完成整个流程,无需人工干预
2. `content-output/` 目录生成 `.md` 文件v6 无 HTML
3. Markdown 文件内容完整,包含:公众号正文 + Twitter 文案 + 视频脚本
4. Telegram 收到完成通知(含标题和文件路径)
5. 错误时 n8n 记录错误节点并停止流程
---
## 备注v6
- **Markdown 源文件**:保留中文原文,便于在 Obsidian 中编辑、排版后再发布
- **公众号排版**:在 Obsidian 中手动完成,或通过 Markdown→公众号工具转换
- **文件路径**:写入 Obsidian vault 的 `content-output/` 子目录,需确保 n8n 容器有对应目录的写权限
- **API Key**DeepSeek API 通过 n8n credential 配置,无需在代码中硬编码
---
---
# 📖 附录OpenClaw ↔ N8N 通用工作流调用规范v1.0
> 本规范旨在为 OpenClaw 与 N8N 之间的每次交互建立统一标准使星辉XingHui或其他 Agent 能够通过标准化步骤执行任意 N8N 工作流。
>
> **适用范围**:任何由 OpenClaw 触发、N8N 执行的工作流(不仅限于内容转化流水线)
>
> **核心约束**N8N 容器只读写 `/home/node/.n8n-files/` 目录,无法直接访问 Obsidian 或其他宿主机路径。OpenClaw 负责所有文件搬运。
---
## 架构总览
```
OpenClaw N8N 容器 其他存储
Agent (/home/node/.n8n-files/) 位置
│ │ │
│ ── ① 复制输入文件 ─────────────────→│ │
│ │ │
│ ── ② POST webhook ─────────────────→│ │
│ │ │
│ [N8N 执行工作流] │
│ │ │
│ ←── ③ Telegram / callback 通知 ───│ │
│ │ │
│ ←── ④ 复制输出文件 ─────────────────│──→ Obsidian 目录 │
│ │ │
│ ── ⑤ 清理 n8n-files ───────────────→│ │
```
---
## 标准化执行步骤(星辉操作指南)
### 步骤 ①:准备输入文件
**规则**:所有传递给 N8N 的文件,必须先复制到 N8N 容器可访问的路径。
**通用格式**`scp <源路径> macmini:/home/node/.n8n-files/<文件名>`
### 步骤 ②:触发 Webhook
**通用格式**
```bash
curl -X POST "<N8N_BASE_URL>/webhook/<webhook-path>" \
-H "Content-Type: application/json" \
-d '{
"note_name": "<文件名>",
"source_path": "<原始文件路径>"
}'
```
**Webhook Path 查询方式**
1. 在 n8n 管理界面https://n8n.ishenwei.online打开对应工作流
2. 点击 Webhook 节点,查看右侧 Path 字段
### 步骤 ③:等待执行完成
**规则**N8N 工作流完成后会发送通知OpenClaw 需等待此信号后再执行后续复制操作。
**通知方式优先级**Telegram Bot > Callback URL > 轮询 n8n API
### 步骤 ④:复制输出文件
**通用格式**`scp macmini:/home/node/.n8n-files/<输出文件名> <目标完整路径>`
### 步骤 ⑤:清理临时文件
**通用格式**`ssh macmini "rm /home/node/.n8n-files/<输入文件> /home/node/.n8n-files/<输出文件>"`
---
## 速查表:常见工作流配置
| 工作流 | Webhook Path | 输入文件规则 | 输出文件规则 | 通知方式 |
| ------- | ------------------------ | -------------------- | ---------------------------- | -------- |
| 内容转化 v6 | `content-translation-v6` | `content-queue/*.md` | `content-output/*_output.md` | Telegram |
| (待补充) | | | | |
> **添加新工作流时**:在此表新增一行,注明 Webhook Path 和文件路径规则,星辉即可照此执行。
---
## 异常处理规范
| 异常情况 | 处理方式 |
|---------|---------|
| `scp` 文件复制失败 | 检查源文件是否存在、检查目标目录权限 |
| `curl` Webhook 请求超时 | 重试 1 次(间隔 5 秒),仍失败则中止并通知用户 |
| Telegram 未收到完成通知 | 登录 n8n 管理界面 → 查看对应工作流执行记录 |
| 输出文件复制失败 | 检查 n8n-files 中是否已生成文件,确认文件名是否匹配 |
| N8N 工作流报错 | 登录 n8n 管理界面 → 打开对应工作流 → 查看错误节点日志 |
---
## 关键约束汇总
1. **N8N 容器路径**`/home/node/.n8n-files/`(只读/写此目录)
2. **文件传输方式**`scp` via `macmini` 主机名
3. **Webhook 触发**:统一使用 `curl -X POST`Content-Type 为 `application/json`
4. **通知等待**:必须等待 Telegram/callback 通知后再复制输出文件,不得跳过
5. **清理时机**:步骤 4 成功后再执行清理,步骤 4 失败时不清理(保留现场)
6. **配置文件**`~/.openclaw/.env` 中的 `N8N_API_KEY``N8N_BASE_URL` 供脚本读取