8
n8n 中文网amn8n.com

使用 OpenAI 为 WooCommerce 生成真实产品评论

中级

这是一个Content Creation, Multimodal AI领域的自动化工作流,包含 7 个节点。主要使用 Set, HttpRequest, ManualTrigger, OpenAi 等节点。 使用 OpenAI 为 WooCommerce 生成真实产品评论

前置要求
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "8e39b7468c6828f4a107b01649bad86d436b5b7484be7eb792fe15ba099d5821"
  },
  "nodes": [
    {
      "id": "37f90234-8233-495a-b9e5-394de7c76852",
      "name": "当点击\"执行工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        0,
        -624
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f91ce677-4b08-43f7-b742-a54f9c48e07c",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -768
      ],
      "parameters": {
        "color": 2,
        "width": 1696,
        "height": 336,
        "content": "## 产品 AI 评论生成器"
      },
      "typeVersion": 1
    },
    {
      "id": "512931cd-db6a-4056-b8bc-4705ea1f7877",
      "name": "从 WooCommerce 获取产品",
      "type": "n8n-nodes-base.httpRequest",
      "maxTries": 5,
      "position": [
        224,
        -624
      ],
      "parameters": {
        "url": "https://example.com/wp-json/wc/v3/products?per_page=100",
        "options": {
          "timeout": 600000,
          "batching": {
            "batch": {
              "batchSize": 100
            }
          }
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth"
      },
      "credentials": {
        "httpBasicAuth": {
          "id": "a390F9PA3LRvL5DR",
          "name": "YOUR_API_KEY"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "waitBetweenTries": 2000
    },
    {
      "id": "aef7c79c-96aa-4252-bd69-d2f83b773661",
      "name": "构建产品评论提示",
      "type": "n8n-nodes-base.set",
      "position": [
        464,
        -624
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3af62c72-bd9b-433a-943c-4caafe23bdd5",
              "name": "prompt",
              "type": "string",
              "value": "=={{ `For the product “${$json.name}”, write a natural comment (one sentence). \nDescription: ${($json.short_description || $json.description || '').replace(/<[^>]*>/g,' ').slice(0,300)}` }}\nComment characteristics:\n- Some neutral, some positive, some negative, some questioning\n- Conversational tone, not formal\n- Occasionally include the brand name in the comment\n- Preferably short\n"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "849160e7-9df1-4337-a111-65fc9bd8d5e5",
      "name": "生成产品评论 (AI)",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        752,
        -624
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "={{$json.prompt}}\n"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "oETjE0hiLJ8SZxWX",
          "name": "YOUR_API_KEY"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1.8,
      "waitBetweenTries": 2000
    },
    {
      "id": "fb93ada6-17e2-46c8-8ca3-b24efcd67c97",
      "name": "提取 AI 输出",
      "type": "n8n-nodes-base.set",
      "position": [
        1104,
        -624
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "18fe84dc-59b3-440b-830d-da161cd5e3da",
              "name": "review",
              "type": "string",
              "value": "={{$json.message?.content || $json.choices?.[0]?.message?.content || $json.content}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3402a419-227b-446d-96dd-7e7bbc6eedd2",
      "name": "将评论发布到产品",
      "type": "n8n-nodes-base.httpRequest",
      "maxTries": 5,
      "position": [
        1360,
        -624
      ],
      "parameters": {
        "url": "https://example.com/wp-json/wc/v3/products/reviews",
        "method": "POST",
        "options": {
          "timeout": 900000
        },
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "product_id",
              "value": "={{ $('Fetch Products from WooCommerce').item.json.id }}"
            },
            {
              "name": "review",
              "value": "={{ $('Generate Product Comment (AI)').item.json.message.content }}"
            },
            {
              "name": "reviewer_email",
              "value": "={{ `guest+${$('Fetch Products from WooCommerce').item.json.id}-${Math.floor(Date.now()%100000)}@example.com`.toLowerCase() }}\n"
            },
            {
              "name": "reviewer",
              "value": "={{ (() => {\n  const first = ['John','Emily','Michael','Sophia','David','Olivia','Daniel','Ava','James','Isabella','Ethan','Mia','William','Charlotte','Benjamin','Amelia','Alexander','Harper','Lucas','Ella'];\n  const last  = ['Smith','Johnson','Williams','Brown','Jones','Garcia','Miller','Davis','Rodriguez','Martinez','Hernandez','Lopez','Gonzalez','Wilson','Anderson','Thomas','Taylor','Moore','Jackson','Martin'];\n  return `${first[Math.floor(Math.random()*first.length)]} ${last[Math.floor(Math.random()*last.length)]}`;\n})() }}\n"
            }
          ]
        },
        "genericAuthType": "httpBasicAuth"
      },
      "credentials": {
        "httpBasicAuth": {
          "id": "a390F9PA3LRvL5DR",
          "name": "YOUR_API_KEY"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "waitBetweenTries": 5000
    }
  ],
  "pinData": {},
  "connections": {
    "Extract AI Output": {
      "main": [
        [
          {
            "node": "Post Review to Product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Product Comment Prompt": {
      "main": [
        [
          {
            "node": "Generate Product Comment (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Product Comment (AI)": {
      "main": [
        [
          {
            "node": "Extract AI Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Products from WooCommerce": {
      "main": [
        [
          {
            "node": "Build Product Comment Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Fetch Products from WooCommerce",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
Ali Khosravani

Ali Khosravani

@alikhosro

Automation & SEO Specialist with years of experience building smart workflows, AI-powered content solutions, and marketing automations. Skilled in n8n, WordPress, and API integrations to help businesses save time and grow faster.

外部链接
在 n8n.io 查看

分享此工作流