Generate Graphic Wallpaper with Midjourney, GPT-4o-mini and Canvas APIs
工作流概述
这是一个包含14个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "mN7jDJoWHtJuyKpS",
"meta": {
"instanceId": "1e003a7ea4715b6b35e9947791386a7d07edf3b5bf8d4c9b7ee4fdcbec0447d7"
},
"name": "Generate Graphic Wallpaper with Midjourney, GPT-4o-mini and Canvas APIs",
"tags": [],
"nodes": [
{
"id": "11cef766-dd10-46ea-98cf-11eb8d95e157",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
280,
80
],
"parameters": {
"width": 520,
"height": 200,
"content": "## Generate Graphic Wallpaper with Midjourney, GPT-4o-mini and Canvas APIs
We design this workflow with PiAPI APIs and Canvas API with the purpose to produce a visually compelling image with resonant copy to spark emotional connection. 🙌
Wish you make a fantastic generation with our workflow! "
},
"typeVersion": 1
},
{
"id": "ba7143d7-442d-4153-9cfd-bb36448d4c91",
"name": "Midjourney Generator",
"type": "n8n-nodes-base.httpRequest",
"position": [
1200,
320
],
"parameters": {
"url": "https://api.piapi.ai/api/v1/task",
"method": "POST",
"options": {},
"jsonBody": "={
\"model\": \"midjourney\",
\"task_type\": \"imagine\",
\"input\": {
\"prompt\": \"{{ $json.prompt }}\",
\"aspect_ratio\": \"1:1\",
\"process_mode\": \"turbo\",
\"skip_prompt_check\": false
}
}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "x-api-key",
"value": "={{ $('Basic Params').item.json['x-api-key'] }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "117b5929-e98c-456a-9bfd-fe1deee77abc",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"position": [
300,
320
],
"parameters": {},
"typeVersion": 1
},
{
"id": "dfcf5c57-536c-4fb4-967b-24fd375db57c",
"name": "Get Prompt",
"type": "n8n-nodes-base.code",
"position": [
960,
320
],
"parameters": {
"jsCode": "const image_prompt=$('Basic Params').first().json.image_prompt;
const show_prompt =$input.first().json.choices[0].message.content;
const prompt = image_prompt.replace(/'xxx'/, `'${show_prompt}'`)
return {show_prompt,prompt};"
},
"typeVersion": 2
},
{
"id": "1c641437-de26-4e55-9b34-0cb13d8d1cd3",
"name": "Get Midjourney Task",
"type": "n8n-nodes-base.httpRequest",
"position": [
1140,
580
],
"parameters": {
"url": "=https://api.piapi.ai/api/v1/task/{{ $json.data.task_id }}",
"options": {},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "x-api-key",
"value": "={{ $('Basic Params').item.json['x-api-key'] }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "38fda20c-fef6-484c-ac75-c8f2fbaaca15",
"name": "Wait for Midjourney Generation",
"type": "n8n-nodes-base.wait",
"position": [
940,
580
],
"webhookId": "af79053d-1291-4dd2-889e-4593dbbb2512",
"parameters": {},
"typeVersion": 1.1
},
{
"id": "1d5eaf9a-caf8-4b08-a35c-281b400c9198",
"name": "Determine Whether the Image URL was Fetched",
"type": "n8n-nodes-base.if",
"position": [
1340,
580
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "or",
"conditions": [
{
"id": "e97a02cc-8d1d-4500-bce5-0a296c792b76",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.data.status }}",
"rightValue": "completed"
},
{
"id": "50b63a7a-52b5-4766-a859-96ac1ff949ec",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.data.status }}",
"rightValue": "failed"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "983acf91-c5ba-4335-b43e-d7a8a1a6b918",
"name": "Check Image Generation Status",
"type": "n8n-nodes-base.switch",
"position": [
1520,
320
],
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "5f61ee56-4ebe-411f-95e6-b47d9741e7a2",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.data.status }}",
"rightValue": "completed"
}
]
}
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "50455a13-5914-4f96-b977-d1c6461807bc",
"name": "Design in Canvas",
"type": "n8n-nodes-base.httpRequest",
"position": [
1920,
320
],
"parameters": {
"url": "https://api.canvas.switchboard.ai",
"method": "POST",
"options": {},
"jsonBody": "={
\"template\": \"social-3-1\",
\"sizes\": [
{
\"width\": 1000,
\"height\": 1500
}
],
\"elements\": {
\"text1\": {
\"text\": \"{{ $('Get Prompt').item.json.show_prompt.replace(/;/g, \";\\n \")}}\"
},
\"rectangle1\": {
\"fillColor\": \"#fff\"
},
\"image1\": {
\"url\": \"{{ $json.data.output.temporary_image_urls[0] }}\"
}
}
}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "X-API-Key",
"value": "45ba3916-2f10-497d-815b-7ffc9b69001f"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "0fd5d40c-aebc-4ec3-b9b5-027126b39452",
"name": "Get Image Url",
"type": "n8n-nodes-base.set",
"position": [
1720,
320
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "d52d19d1-3a37-47bb-ad23-e809323c0c54",
"name": "data.output.temporary_image_urls",
"type": "array",
"value": "={{ $json.data.output.temporary_image_urls }}"
},
{
"id": "49bed53e-675d-4ea0-947c-ffcbfae0ee97",
"name": "data.output.image_url",
"type": "string",
"value": "={{ $json.data.output.image_url }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "e36d4bd6-2d34-447c-984e-515c48f3632e",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
280,
500
],
"parameters": {
"width": 580,
"height": 280,
"content": "## Basic Params
In **Basic Params** node, you need to fill in your PiAPI key which you could check in [My Account](https://piapi.ai/workspace/my-account) on [PiAPI](https://piapi.ai). Other information you need to provide is listed as follow📝:
1. Theme. The theme refers to the topic that you want to talk about when you start your generation.
2. Scenario. The scenario text usually describe your status about your feeling.
3. Style. The style of the image.
4. Example. The text example shown to LLM to describe a style t you want to generate.
5. Image prompt. Image prompt is usually about the context of the image that you want to generate."
},
"typeVersion": 1
},
{
"id": "1e04fe5d-a1f4-4fe9-a3d2-9c6aeaf05d96",
"name": "Gpt-4o-mini API",
"type": "n8n-nodes-base.httpRequest",
"position": [
740,
320
],
"parameters": {
"url": "https://api.piapi.ai/v1/chat/completions",
"method": "POST",
"options": {},
"jsonBody": "={
\"model\": \"gpt-4o-mini\",
\"messages\": [
{
\"role\": \"system\",
\"content\": \"You are a helpful assistant.\"
},
{
\"role\": \"user\",
\"content\": \"Please {{ $json.style }}, based on the theme of {{ $json.theme }} and the scenario of {{ $json.scenario }}, according to the output case and language context. Examples are {{ $json.example }},Return a sentence directly, nothing else,Don't add a serial number, just a prompt that can be used for input,Do not add any quotation marks.\"}
]
}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "=Bearer {{ $('Basic Params').first().json['x-api-key'] }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "4eaf0f57-9458-42cb-b736-c737f134320b",
"name": "Basic Params",
"type": "n8n-nodes-base.set",
"position": [
540,
320
],
"parameters": {
"mode": "raw",
"options": {},
"jsonOutput": "{
\"x-api-key\":\"\",
\"theme\": \"Hope\",
\"scenario\": \"Don't know about the future, confused and feel lost about AI agent\",
\"style\":\"Cinematic Grandeur,Sci-Tech Aesthetic, 3D style\",
\"example\":\"1. March. Because of your faith, it will happen.2. Something in me will save me.3. To everyone carrying a heavy heart in silence. You are going to be okay.4. Tomorrow will be better.\",
\"image_prompt\":\"A cinematic sci-fi metropolis where Deep Neural Nets control a hyper-connected society. Holographic interfaces glow in the air as robotic agents move among humans, symbolizing Industry 4.0. The scene contrasts organic human emotion with cold machine precision, rendered in a hyper-realistic 3D style with futuristic lighting. Epic wide shots showcase the grandeur of this civilization’s industrial evolution.\"
}
"
},
"typeVersion": 3.4
},
{
"id": "6750b606-4222-4cda-bcaa-5d4f2b4f9ec8",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1680,
560
],
"parameters": {
"width": 380,
"height": 200,
"content": "## Design in Canvas API Node
We make a final design with Canvas API.
You could check the node code to make a template design more efficiently in Canvas.
Also you could make various artworks with template library in Canvas.
You could modify node parameters to or add more nodes to make more artworks in one role."
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "09b5a8e6-bdc8-47bb-a9e3-95b090ff3f13",
"connections": {
"Get Prompt": {
"main": [
[
{
"node": "Midjourney Generator",
"type": "main",
"index": 0
}
]
]
},
"Basic Params": {
"main": [
[
{
"node": "Gpt-4o-mini API",
"type": "main",
"index": 0
}
]
]
},
"Get Image Url": {
"main": [
[
{
"node": "Design in Canvas",
"type": "main",
"index": 0
}
]
]
},
"Gpt-4o-mini API": {
"main": [
[
{
"node": "Get Prompt",
"type": "main",
"index": 0
}
]
]
},
"Get Midjourney Task": {
"main": [
[
{
"node": "Determine Whether the Image URL was Fetched",
"type": "main",
"index": 0
}
]
]
},
"Midjourney Generator": {
"main": [
[
{
"node": "Wait for Midjourney Generation",
"type": "main",
"index": 0
}
]
]
},
"When clicking Test workflow": {
"main": [
[
{
"node": "Basic Params",
"type": "main",
"index": 0
}
]
]
},
"Check Image Generation Status": {
"main": [
[
{
"node": "Get Image Url",
"type": "main",
"index": 0
}
]
]
},
"Wait for Midjourney Generation": {
"main": [
[
{
"node": "Get Midjourney Task",
"type": "main",
"index": 0
}
]
]
},
"Determine Whether the Image URL was Fetched": {
"main": [
[
{
"node": "Check Image Generation Status",
"type": "main",
"index": 0
}
],
[
{
"node": "Wait for Midjourney Generation",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Stickynote
- Httprequest
- Manualtrigger
- Code
- Wait
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作