{
  "name": "vivo 用户反馈监控与聚类分析",
  "nodes": [
    {
      "parameters": {
        "rule": { "interval": [{ "field": "hours", "hoursInterval": 6 }] }
      },
      "id": "trigger",
      "name": "定时触发（每6小时）",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [0, 0]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.xiaohongshu.com/explore/search",
        "sendHeaders": true,
        "headerParameters": { "parameters": [
          { "name": "Cookie", "value": "={{$env.XHS_COOKIE}}" },
          { "name": "User-Agent", "value": "Mozilla/5.0" }
        ]},
        "sendQuery": true,
        "queryParameters": { "parameters": [
          { "name": "keyword", "value": "vivo X300s 问题" },
          { "name": "sort", "value": "time" }
        ]}
      },
      "id": "xhs",
      "name": "小红书监控",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [250, -120]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://m.weibo.cn/api/container/getIndex",
        "sendHeaders": true,
        "headerParameters": { "parameters": [
          { "name": "Cookie", "value": "={{$env.WEIBO_COOKIE}}" }
        ]},
        "sendQuery": true,
        "queryParameters": { "parameters": [
          { "name": "containerid", "value": "100103type=1&q=vivo X300s 差评 问题" }
        ]}
      },
      "id": "weibo",
      "name": "微博监控",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [250, 120]
    },
    {
      "parameters": {
        "jsCode": "// 合并两个平台的帖子\nconst xhs = $input.first().json?.data?.items || [];\nconst weibo = $input.last().json?.data?.cards || [];\n\nconst posts = [];\n\nfor (const item of xhs) {\n  const note = item.note_card || {};\n  posts.push({\n    platform: '小红书',\n    title: note.display_title || '',\n    content: note.desc || '',\n    likes: parseInt(note.interact_info?.liked_count) || 0,\n    comments: parseInt(note.interact_info?.comment_count) || 0\n  });\n}\n\nfor (const card of weibo) {\n  if (!card.mblog) continue;\n  const mb = card.mblog;\n  posts.push({\n    platform: '微博',\n    title: (mb.text || '').replace(/<[^>]+>/g, '').substring(0, 60),\n    content: (mb.text || '').replace(/<[^>]+>/g, ''),\n    likes: mb.attitudes_count || 0,\n    comments: mb.comments_count || 0\n  });\n}\n\nreturn posts.map(p => ({ json: p }));"
      },
      "id": "merge",
      "name": "合并双平台",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [500, 0]
    },
    {
      "parameters": {
        "jsCode": "// 筛选负面原声\nconst negativeKW = ['糊','差','卡顿','退货','失望','翻车','bug','故障','发热','续航','问题','难用','垃圾','售后','退步','缩水','马赛克','像素方块','模糊','崩坏'];\n\nconst negative = $input.all().filter(item => {\n  const text = (item.json.title + ' ' + item.json.content);\n  return negativeKW.some(kw => text.includes(kw));\n});\n\n// 按互动量排序取前30\nnegative.sort((a, b) => (b.json.likes + b.json.comments) - (a.json.likes + a.json.comments));\nreturn negative.slice(0, 30).map(i => ({ json: i.json }));"
      },
      "id": "filter",
      "name": "筛选负面原声",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [740, 0]
    },
    {
      "parameters": {
        "jsCode": "// 拼接分析文本\nconst posts = $input.all();\nlet text = `# vivo X300s 社媒负面原声汇总\\n数据时间: ${new Date().toISOString().split('T')[0]}\\n样本量: ${posts.length} 条\\n\\n`;\n\nfor (const p of posts) {\n  text += `## [${p.json.platform}] ${p.json.title}\\n`;\n  text += `互动: 👍${p.json.likes} 💬${p.json.comments}\\n`;\n  text += `${p.json.content}\\n\\n---\\n\\n`;\n}\nreturn [{ json: { rawText: text, count: posts.length } }];"
      },
      "id": "format",
      "name": "格式化文本",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [980, 0]
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "messages": {
          "messages": [
            {
              "role": "system",
              "content": "你是手机产品的用户反馈分析专家。请对以下社媒负面原声进行多维度聚类分析。\n\n要求：\n1. 【情绪占比】负面/失望 vs 纠结/矛盾 vs 正向认可 的大致比例\n2. 【热议话题】当前舆论焦点话题 2-3 个\n3. 【问题聚类】按 维度/主要问题点/严重程度 三列表格输出\n4. 【典型声音】每个问题类别抽 2-3 条用户原话\n5. 【用户建议】用户提出的改进诉求\n6. 【舆情风险】是否需要重点关注，是否有扩大传播风险\n7. 【总结】一句话结论 + 行动建议\n\n输出格式：Markdown，使用表格和分点。"
            },
            { "role": "user", "content": "={{$json.rawText}}" }
          ]
        },
        "options": { "temperature": 0.3 }
      },
      "id": "llm",
      "name": "LLM 多维聚类分析",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.4,
      "position": [1220, 0]
    },
    {
      "parameters": {
        "jsCode": "const analysis = $input.first().json.message?.content || $input.first().json.text || '';\nconst count = $('格式化文本').first().json.count;\nconst date = new Date().toISOString().split('T')[0];\n\nconst report = `# vivo X300s 社媒舆论分析报告\\n\\n` +\n  `**日期**: ${date} | **样本**: ${count} 条 | **来源**: 小红书+微博\\n\\n---\\n\\n${analysis}\\n\\n---\\n*自动化工作流生成，每6小时更新*`;\n\nreturn [{ json: { report, date, count } }];"
      },
      "id": "report",
      "name": "生成报告",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1460, 0]
    },
    {
      "parameters": {
        "operation": "write",
        "fileName": "=vivo_X300s_反馈报告_{{$json.date}}.md",
        "fileContent": "={{$json.report}}",
        "options": {}
      },
      "id": "save",
      "name": "保存报告文件",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [1700, 0]
    }
  ],
  "connections": {
    "定时触发（每6小时）": { "main": [[{"node":"小红书监控","type":"main","index":0},{"node":"微博监控","type":"main","index":0}]] },
    "小红书监控": { "main": [[{"node":"合并双平台","type":"main","index":0}]] },
    "微博监控": { "main": [[{"node":"合并双平台","type":"main","index":0}]] },
    "合并双平台": { "main": [[{"node":"筛选负面原声","type":"main","index":0}]] },
    "筛选负面原声": { "main": [[{"node":"格式化文本","type":"main","index":0}]] },
    "格式化文本": { "main": [[{"node":"LLM 多维聚类分析","type":"main","index":0}]] },
    "LLM 多维聚类分析": { "main": [[{"node":"生成报告","type":"main","index":0}]] },
    "生成报告": { "main": [[{"node":"保存报告文件","type":"main","index":0}]] }
  },
  "settings": { "executionOrder": "v1" }
}
