8
n8n 中文网amn8n.com

AI社交媒体内容生成器与调度器

中级

这是一个Content Creation, Multimodal AI领域的自动化工作流,包含 14 个节点。主要使用 Set, Code, Webhook, ScheduleTrigger, OpenAi 等节点。 使用 GPT-4 和自动调度器跨平台生成社交媒体内容

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "templateId": "ai-social-media-generator-v1",
    "templateCreatedDate": "2024-01-15T00:00:00.000Z"
  },
  "name": "AI社交媒体内容生成器与调度器",
  "tags": [],
  "nodes": [
    {
      "id": "overview-note",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -900,
        -500
      ],
      "parameters": {
        "width": 400,
        "height": 420,
        "content": "## 🚀 AI社交媒体内容生成器"
      },
      "typeVersion": 1
    },
    {
      "id": "content-types",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -500
      ],
      "parameters": {
        "width": 300,
        "height": 480,
        "content": "## 📝 内容类型"
      },
      "typeVersion": 1
    },
    {
      "id": "setup-guide",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -900,
        -50
      ],
      "parameters": {
        "width": 320,
        "height": 350,
        "content": "## ⚙️ 设置指南"
      },
      "typeVersion": 1
    },
    {
      "id": "prompt-examples",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        100,
        -500
      ],
      "parameters": {
        "width": 350,
        "height": 380,
        "content": "## 💡 提示词示例"
      },
      "typeVersion": 1
    },
    {
      "id": "customization",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        -500
      ],
      "parameters": {
        "width": 300,
        "height": 380,
        "content": "## 🎨 自定义设置"
      },
      "typeVersion": 1
    },
    {
      "id": "best-practices",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        -50
      ],
      "parameters": {
        "width": 320,
        "height": 420,
        "content": "## 📈 最佳实践"
      },
      "typeVersion": 1
    },
    {
      "id": "webhook-trigger",
      "name": "内容请求Webhook",
      "type": "n8n-nodes-base.webhook",
      "notes": "Receives content generation requests with topic and parameters",
      "position": [
        -600,
        200
      ],
      "webhookId": "social-content-generator",
      "parameters": {
        "path": "generate-social-content",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
              }
            ]
          }
        },
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 1.1
    },
    {
      "id": "process-input",
      "name": "处理输入",
      "type": "n8n-nodes-base.code",
      "notes": "Validates and prepares content generation parameters",
      "position": [
        -400,
        200
      ],
      "parameters": {
        "jsCode": "// Extract and validate input\nconst input = $input.first().json;\nconst topic = input.body?.topic || input.topic || \"\";\nconst platforms = input.body?.platforms || input.platforms || [\"linkedin\", \"twitter\", \"instagram\", \"facebook\"];\nconst tone = input.body?.tone || input.tone || \"professional\";\nconst language = input.body?.language || input.language || \"en\";\nconst includeHashtags = input.body?.includeHashtags !== false;\nconst includeEmojis = input.body?.includeEmojis !== false;\nconst contentLength = input.body?.contentLength || \"medium\";\n\n// Validate input\nif (!topic) {\n    throw new Error(\"Topic is required\");\n}\n\n// Platform-specific character limits\nconst characterLimits = {\n    twitter: 280,\n    linkedin: 3000,\n    instagram: 2200,\n    facebook: 63206,\n    tiktok: 150\n};\n\n// Platform-specific hashtag recommendations\nconst hashtagCounts = {\n    twitter: 2,\n    linkedin: 5,\n    instagram: 30,\n    facebook: 3,\n    tiktok: 5\n};\n\n// Prepare output\nreturn {\n    topic,\n    platforms,\n    tone,\n    language,\n    includeHashtags,\n    includeEmojis,\n    contentLength,\n    characterLimits,\n    hashtagCounts,\n    timestamp: new Date().toISOString(),\n    requestId: Math.random().toString(36).substring(7)\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "generate-content",
      "name": "生成内容",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Uses AI to generate platform-specific content",
      "position": [
        -200,
        200
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4-mini"
        },
        "options": {
          "maxTokens": 3000,
          "temperature": 0.7
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=You are a professional social media content creator specializing in creating engaging, platform-optimized content. You understand the nuances of each social media platform and create content that maximizes engagement while maintaining brand consistency.\n\nYour expertise includes:\n- Platform-specific best practices\n- Optimal content length\n- Hashtag strategies\n- Engagement optimization\n- Trend integration\n- SEO optimization\n- Call-to-action creation\n\nAlways create content that is:\n1. Platform-appropriate\n2. Engaging and valuable\n3. Action-oriented\n4. Properly formatted\n5. Culturally sensitive\n\nTone: {{ $json.tone }}\nInclude Hashtags: {{ $json.includeHashtags }}\nInclude Emojis: {{ $json.includeEmojis }}\nContent Length: {{ $json.contentLength }}"
            },
            {
              "role": "user",
              "content": "=Create social media content for the following:\n\nTopic: {{ $json.topic }}\nPlatforms: {{ $json.platforms.join(', ') }}\nLanguage: {{ $json.language }}\n\nFor each platform, provide:\n1. Main content/caption\n2. Relevant hashtags (if requested)\n3. Suggested posting time\n4. Call-to-action\n5. Engagement tips\n\nCharacter limits:\n{{ JSON.stringify($json.characterLimits, null, 2) }}\n\nHashtag recommendations:\n{{ JSON.stringify($json.hashtagCounts, null, 2) }}\n\nFormat the response as JSON with a key for each platform."
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "{{YOUR_OPENAI_CREDENTIAL}}",
          "name": "OpenAI account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "format-response",
      "name": "格式化响应",
      "type": "n8n-nodes-base.code",
      "notes": "Structures the AI response and adds metadata",
      "position": [
        0,
        200
      ],
      "parameters": {
        "jsCode": "// Parse AI response\nconst aiResponse = $input.first().json.message.content;\nlet contentData;\n\ntry {\n    // Try to parse as JSON\n    contentData = JSON.parse(aiResponse);\n} catch (error) {\n    // If not JSON, create structured response\n    contentData = {\n        error: \"Failed to parse AI response\",\n        rawResponse: aiResponse\n    };\n}\n\n// Add metadata\nconst output = {\n    success: !contentData.error,\n    requestId: $('Process Input').first().json.requestId,\n    topic: $('Process Input').first().json.topic,\n    timestamp: new Date().toISOString(),\n    content: contentData,\n    metadata: {\n        tone: $('Process Input').first().json.tone,\n        language: $('Process Input').first().json.language,\n        platforms: $('Process Input').first().json.platforms\n    }\n};\n\n// Add performance predictions (mock data - replace with real analytics)\nif (output.success && output.content) {\n    Object.keys(output.content).forEach(platform => {\n        if (output.content[platform] && typeof output.content[platform] === 'object') {\n            output.content[platform].predictions = {\n                engagementRate: Math.floor(Math.random() * 30) + 70 + \"%\",\n                estimatedReach: Math.floor(Math.random() * 5000) + 1000,\n                bestPostingTime: getOptimalPostingTime(platform)\n            };\n        }\n    });\n}\n\nfunction getOptimalPostingTime(platform) {\n    const times = {\n        linkedin: \"Tuesday-Thursday, 8-10 AM\",\n        twitter: \"Weekdays, 9-10 AM, 7-9 PM\",\n        instagram: \"Weekdays, 11 AM-1 PM, 7-9 PM\",\n        facebook: \"Wednesday-Friday, 1-4 PM\",\n        tiktok: \"Tuesday-Thursday, 6-10 AM, 7-9 PM\"\n    };\n    return times[platform] || \"Weekdays, 10 AM-12 PM\";\n}\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "send-response",
      "name": "发送响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "notes": "Returns the generated content to the requester",
      "position": [
        200,
        200
      ],
      "parameters": {
        "options": {
          "responseCode": 200,
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        },
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json, null, 2) }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "daily-content",
      "name": "每日内容调度",
      "type": "n8n-nodes-base.scheduleTrigger",
      "notes": "Triggers daily content generation for consistent posting",
      "position": [
        -600,
        400
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "prepare-daily",
      "name": "准备每日主题",
      "type": "n8n-nodes-base.set",
      "notes": "Creates daily content topics based on day of week",
      "position": [
        -400,
        400
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "topic",
              "name": "topic",
              "type": "string",
              "value": "={{ $now.toFormat('EEEE') }} motivation - Share something inspiring for {{ $now.toFormat('EEEE') }}"
            },
            {
              "id": "platforms",
              "name": "platforms",
              "type": "array",
              "value": "={{ [\"linkedin\", \"twitter\", \"instagram\"] }}"
            },
            {
              "id": "tone",
              "name": "tone",
              "type": "string",
              "value": "inspirational"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "workflow-paths",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -150,
        -50
      ],
      "parameters": {
        "width": 350,
        "height": 300,
        "content": "## 🔄 工作流路径"
      },
      "typeVersion": 1
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "connections": {
    "Process Input": {
      "main": [
        [
          {
            "node": "Generate Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response": {
      "main": [
        [
          {
            "node": "Send Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Content": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Daily Topic": {
      "main": [
        [
          {
            "node": "Generate Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Content Schedule": {
      "main": [
        [
          {
            "node": "Prepare Daily Topic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Content Request Webhook": {
      "main": [
        [
          {
            "node": "Process Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 内容创作, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量14
分类2
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流