diff --git a/openclaw/yunce/n8n-content-pipeline-workflow.md b/openclaw/yunce/n8n-content-pipeline-workflow.md index f04318aa..c12c60c2 100644 --- a/openclaw/yunce/n8n-content-pipeline-workflow.md +++ b/openclaw/yunce/n8n-content-pipeline-workflow.md @@ -1,86 +1,100 @@ -# N8N 内容转化流水线工作流设计 +# N8N 内容转化流水线工作流设计(v4) > 用于:AI 英文文章 → 中文公众号/X/视频 内容转化 +> 工作流ID:`iOf32aOKvTjfTDSM` > 触发方式:OpenClaw 通过 Webhook 调用 -> 管理平台:Mac mini 上的 n8n +> 管理平台:Mac mini 上的 n8n (`https://n8n.ishenwei.online`) --- ## 📋 工作流概述 +**当前活跃版本:** v1 (`xQDabttYmLaY8qtr`) / v3 (`tOGMiC6qOJPOY89E`) +**最新开发版本:** v4 (`iOf32aOKvTjfTDSM`) — 未激活 + ``` -OpenClaw (发现文章) - ↓ (保存 Obsidian) +OpenClaw (发现文章) + ↓ (保存文件到 n8n-files 目录) ↓ (触发 Webhook) - + ┌─────────────────────────────────────────────────────────────┐ -│ N8N 工作流: content-translation-pipeline │ +│ N8N 工作流 (v4): content-translation-pipeline-v4 │ │ │ -│ [Webhook] → [Read Obsidian] → [AI 翻译改写] → [配图搜索] │ -│ ↓ │ -│ [写回 Obsidian] → [通知 OpenClaw] │ +│ [Webhook] → [Read File] → [Extract Text] → [AI Agent] │ +│ ↓ ↑ (DeepSeek) │ +│ [Convert to File] → [Write File] → [Send Telegram] │ └─────────────────────────────────────────────────────────────┘ ``` --- -## 🔌 节点详细设计 +## 🔌 节点详细设计(v4) -### 节点 1️⃣:Webhook Trigger(触发器) +### 节点 1️⃣:Webhook Trigger **类型:** Webhook -**名称:** `webhook_trigger` - -**配置:** -- Method: POST -- Path: `/content-translation` -- Authentication: None(内部网络调用) +**名称:** `Webhook Trigger` +**Path:** `/content-translation-v4` +**Method:** POST **接收数据格式:** ```json { - "note_path": "/Users/weishen/Workspace/nexus/openclaw/content-queue/2026-03-29-ai-solopreneur.md", - "source_url": "https://original-article-url", - "action": "translate", - "platforms": ["wechat", "twitter", "video"], + "note_name": "article-2026-03-29.md", "callback_url": "http://192.168.3.189:18789/webhook/yunce" } ``` -**输出:** 向下游节点传递完整 payload +**注意:** v4 使用 `note_name`(文件名)而非 `note_path`,文件需预先上传到 n8n 容器的 `/home/node/.n8n-files/` 目录。 --- -### 节点 2️⃣:Read Obsidian Note(读取原文笔记) +### 节点 2️⃣:Read Obsidian Note -**类型:** HTTP Request(调用 Obsidian Local REST API 插件) -**名称:** `read_obsidian_note` +**类型:** Read Binary File +**名称:** `Read Obsidian Note` **配置:** -- Method: GET -- URL: `http://localhost:27123/vault/{{ $json.note_path }}` -- Headers: - - `Content-Type: application/json` +- File Path: `=/home/node/.n8n-files/{{ $json.body.note_name }}` +- n8n 容器内文件路径: `/home/node/.n8n-files/` -**备选方案(如果没有 Obsidian REST API):** -使用 n8n Filesystem 节点直接读取文件路径。 +**输出:** 二进制文件数据,传递给 Extract from File 节点 + +--- + +### 节点 3️⃣:Extract from File + +**类型:** Extract from File +**名称:** `Extract from File` +**Operation:** `text` + +**功能:** 从二进制文件提取文本内容 **输出变量:** -- `original_title`(原文标题) - `original_content`(原文内容) -- `source_url`(文章来源) -- `tags`(标签) +- `note_name`(文件名) +- `callback_url`(回调地址) --- -### 节点 3️⃣:AI 翻译与本土化(核心节点) +### 节点 4️⃣:DeepSeek Chat Model -**类型:** AI Agent(n8n 内置) -**名称:** `translate_and_adapt` +**类型:** LM Chat DeepSeek +**名称:** `DeepSeek Chat Model` **配置:** -- Provider: OpenAI / Claude(通过环境变量配置) -- Model: gpt-4o 或 claude-3-5-sonnet +- Model: `deepseek-chat` +- Credentials: `DeepSeek account`(在 n8n 中配置) + +**连接:** → AI Agent(作为 languageModel 输入) + +--- + +### 节点 5️⃣:AI Agent + +**类型:** LangChain Agent +**名称:** `AI Agent` +**Version:** 3.1 **Prompt 模板:** ``` @@ -118,217 +132,101 @@ OpenClaw (发现文章) } ## 原文内容 -{{ $json.original_content }} +{{ $json.data }} ``` -**输出变量:** -- `wechat_title` -- `wechat_excerpt` -- `wechat_content` -- `twitter_copy` -- `video_title` -- `video_script` -- `cover_keywords[]` - --- -### 节点 4️⃣:搜索封面图 +### 节点 6️⃣:Convert to File -**类型:** HTTP Request -**名称:** `search_cover_image` +**类型:** Convert to File +**名称:** `Convert to File` +**Operation:** `toJson` + +**功能:** 将 AI Agent 输出转换为 JSON 格式文件 + +--- + +### 节点 7️⃣:Read/Write Files from Disk + +**类型:** Read/Write File +**名称:** `Read/Write Files from Disk` +**Operation:** `write` **配置:** -- Method: GET -- URL: `https://api.unsplash.com/search/photos` -- Query Parameters: - - `query`: 第一张封面图关键词(取 cover_keywords[0]) - - `per_page`: 1 - - `orientation`: landscape -- Headers: - - `Authorization`: `Client-ID {{ $env.UNSPLASH_API_KEY }}` - -**备选:** Pexels API(如果用 Pexels) -**备选:** 直接用搜索引擎图片 API +- File Name: `=/home/node/.n8n-files/{{ $('Webhook Trigger').item.json.body.note_name }}_output.md` **输出变量:** -- `cover_image_url` -- `cover_image_credit`(图片来源归因) +- `output_file_name` +- `output_content` --- -### 节点 5️⃣:构建 Obsidian 成品笔记 +### 节点 8️⃣:Send Telegram Message -**类型:** Code(数据转换) -**名称:** `build_output_note` - -**功能:** 将 AI 输出组装成 Obsidian 笔记的 Markdown 内容 - -**输出内容:** -```markdown ---- -source: {{ source_url }} -title: {{ wechat_title }} -excerpt: {{ wechat_excerpt }} -cover_image: {{ cover_image_url }} -date: {{ current_date }} -tags: [ai-agent, translated, ready-to-publish] -status: ready-to-publish -platforms: - - wechat - - twitter - - video ---- - -# {{ wechat_title }} - -{{ wechat_content }} - ---- - -## X/Twitter 文案 - -{{ twitter_copy }} - ---- - -## 视频信息 - -**标题:** {{ video_title }} - -**口播脚本:** - -{{ video_script }} - ---- - -*封面图来源:{{ cover_image_credit }}* -``` - -**输出变量:** -- `output_note_path`: `原笔记路径` → `output/成品笔记文件名.md` -- `output_content`: Markdown 内容 - ---- - -### 节点 6️⃣:写回 Obsidian(保存成品) - -**类型:** HTTP Request(POST 到 Obsidian REST API) -**名称:** `write_obsidian_note` +**类型:** Telegram +**名称:** `Send Telegram Message` **配置:** -- Method: PUT 或 POST -- URL: `http://localhost:27123/vault/{{ $json.output_note_path }}` -- Body: `{{ $json.output_content }}` -- Headers: - - `Content-Type: text/markdown` +- Chat ID: `5038825565` +- Text: "文章转换成功" +- Credentials: `Telegram XingJiang Bot` -**备选方案:** Filesystem Write 节点直接写文件 +**功能:** 通知星匠/用户工作流已完成 --- -### 节点 7️⃣:通知 OpenClaw(回调) - -**类型:** HTTP Request -**名称:** `notify_openclaw` - -**配置:** -- Method: POST -- URL: `{{ $json.callback_url }}` -- Body: -```json -{ - "status": "completed", - "input_note": "{{ $json.input_note_path }}", - "output_note": "{{ $json.output_note_path }}", - "wechat_title": "{{ $json.wechat_title }}", - "twitter_copy": "{{ $json.twitter_copy }}", - "video_title": "{{ $json.video_title }}", - "cover_image": "{{ $json.cover_image_url }}" -} -``` - ---- - -### 节点 8️⃣:Error Handler(错误处理) - -**类型:** Error Trigger(全局) -**名称:** `error_handler` - -**功能:** -- 捕获任意节点错误 -- 发送错误通知到 OpenClaw -- 记录错误日志 - ---- - -## 🔗 完整节点连接图 +## 🔗 完整节点连接图(v4) ``` -┌─────────────────┐ -│ Webhook │ (接收 OpenClaw 调用) -│ webhook_trigger│ -└────────┬────────┘ - │ - ▼ -┌─────────────────┐ -│ Read Obsidian │ (读取原始笔记) -│ read_obsidian │ -└────────┬────────┘ - │ - ▼ -┌─────────────────┐ -│ AI Agent │ (翻译+改写+脚本) -│ translate_ │ -│ and_adapt │ -└────────┬────────┘ - │ - ▼ -┌─────────────────┐ -│ Search Image │ (Unsplash API) -│ search_cover │ -└────────┬────────┘ - │ - ▼ -┌─────────────────┐ -│ Code │ (组装 Markdown) -│ build_output │ -└────────┬────────┘ - │ - ▼ -┌─────────────────┐ -│ Write Obsidian │ (保存成品笔记) -│ write_note │ -└────────┬────────┘ - │ - ▼ -┌─────────────────┐ -│ HTTP Request │ (回调 OpenClaw) -│ notify_openclaw│ -└─────────────────┘ -``` - ---- - -## 🔧 环境变量要求 - -```bash -# n8n 所在服务器环境变量 -export OPENAI_API_KEY="sk-..." # AI 翻译用 -export UNSPLASH_API_KEY="..." # 图片搜索用 -export OBSIDIAN_VAULT_PATH="/Users/weishen/Workspace/nexus" -``` - ---- - -## 📁 Obsidian 目录结构 - -``` -nexus/ -├── openclaw/ -│ ├── content-queue/ # 原始文章待处理 -│ │ └── 2026-03-29-ai-solopreneur.md -│ └── content-output/ # 成品输出 -│ └── 2026-03-29-ai-solopreneur-translated.md +┌─────────────────────────────────┐ +│ Webhook Trigger │ +│ POST /content-translation-v4 │ +└──────────────┬──────────────────┘ + │ + ▼ +┌─────────────────────────────────┐ +│ Read Obsidian Note │ +│ (Read Binary File) │ +│ /home/node/.n8n-files/ │ +└──────────────┬──────────────────┘ + │ + ▼ +┌─────────────────────────────────┐ +│ Extract from File │ +│ (text operation) │ +└──────────────┬──────────────────┘ + │ + ┌──────────┴──────────┐ + │ │ + │ ┌───────┴────────┐ + │ │ DeepSeek │ + │ │ Chat Model │ + │ └───────┬────────┘ + │ │ + ▼ ▼ +┌─────────────────────────────────┐ +│ AI Agent (LangChain) │ +│ - system prompt │ +│ - original content │ +└──────────────┬──────────────────┘ + │ + ▼ +┌─────────────────────────────────┐ +│ Convert to File (toJson) │ +└──────────────┬──────────────────┘ + │ + ▼ +┌─────────────────────────────────┐ +│ Read/Write Files from Disk │ +│ (write output .md) │ +└──────────────┬──────────────────┘ + │ + ▼ +┌─────────────────────────────────┐ +│ Send Telegram Message │ +│ 文章转换成功 │ +└─────────────────────────────────┘ ``` --- @@ -336,32 +234,80 @@ nexus/ ## 🔄 调用方式(OpenClaw 侧) ```bash -# 触发 n8n 工作流 -curl -X POST "http://macmini.local:5678/webhook/content-translation" \ +# 1. 将文章文件复制到 n8n-files 目录(通过 SFTP 或共享目录) +scp article.md macmini:/tmp/article.md +# 需要手动或通过 API 上传到 n8n 容器的 /home/node/.n8n-files/ + +# 2. 触发 n8n 工作流 +curl -X POST "https://n8n.ishenwei.online/webhook/content-translation-v4" \ -H "Content-Type: application/json" \ -d '{ - "note_path": "/Users/weishen/Workspace/nexus/openclaw/content-queue/2026-03-29-ai-solopreneur.md", - "source_url": "https://original-article-url", - "action": "translate", - "platforms": ["wechat", "twitter", "video"], + "note_name": "article-2026-03-29.md", "callback_url": "http://192.168.3.189:18789/webhook/yunce" }' ``` --- -## ✅ 验收标准 +## 📁 Obsidian / n8n 文件目录结构 -1. Webhook 被调用后,整个流程自动完成 -2. 成品笔记包含所有字段(标题、摘要、正文、推文、脚本、封面图) -3. OpenClaw 收到完成回调 -4. 任意节点失败时,错误被捕获并通知 +``` +# 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/ # 成品输出目录 +``` --- -## 📝 后续扩展方向(Phase 2) +## 🔧 各版本对比 -- 加入人工审核节点(审批后再发布) -- 加入多语言支持(英文 + 中文) -- 加入视频字幕生成(Whisper API) -- 加入定时调度(自动抓取 RSS → 自动翻译) +| 版本 | 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 会中断流程并记录错误 + +--- + +## 📝 待完善项(v4) + +- [ ] 成品文件需要写回 Obsidian 目录(目前只写到 n8n-files) +- [ ] 封面图搜索节点(v4 已移除 v1 的 Unsplash 配图功能) +- [ ] OpenClaw 回调通知(v4 改为 Telegram 通知,需确认是否符合预期) +- [ ] v4 激活前需完成联调测试 + +--- + +## 📝 后续扩展方向 + +- [ ] 加入封面图搜索(恢复 Unsplash 节点) +- [ ] 写回 Obsidian content-output 目录 +- [ ] 支持 X/Twitter API 自动发布 +- [ ] 支持抖音/YouTube 视频上传 API +- [ ] 加入人工审核节点(审批后再发布)