{
  "name": "客户反馈分析工作流",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "feedback-collect",
        "responseMode": "onReceived",
        "options": {}
      },
      "name": "Webhook收反馈",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [0, 0],
      "webhookId": "customer-feedback-analysis"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const raw = $input.first().json;\nconst text = (raw.body || raw.text || raw.content || '').toString();\n// 简易 hash 去重键\nlet h = 0;\nfor (let i = 0; i < text.length; i++) h = ((h << 5) - h + text.charCodeAt(i)) | 0;\nconst hash = 'fb_' + Math.abs(h).toString(36);\n// PII 脱敏：手机号 / 邮箱 / 身份证号\nconst masked = text\n  .replace(/1[3-9]\\d{9}/g, '[PHONE]')\n  .replace(/[\\w.+-]+@[\\w-]+\\.[\\w.-]+/g, '[EMAIL]')\n  .replace(/\\d{15,18}/g, '[ID]');\nreturn { json: { ...raw, feedback: masked, hash, source: raw.source || 'webhook' } };"
      },
      "name": "去重+脱敏",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [220, 0]
    },
    {
      "parameters": {
        "url": "https://api.moonshot.cn/v1/chat/completions",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer YOUR_LLM_API_KEY" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"model\":\"moonshot-v1-8k\",\"messages\":[{\"role\":\"system\",\"content\":\"你是客户反馈分析师。读反馈文本输出JSON：type(投诉/建议/bug/夸赞四选一,不得自创类目)、sentiment(正面/中性/负面)、urgency(P0崩溃或数据丢失/P1核心功能受阻/P2体验问题/P3锦上添花)、module(产品模块名,未知标unknown)、confidence(0-1)、summary(20字内)。置信度<0.7时summary前置[需复核]。不编造文本中没有的事实,仅基于原文判断。\"},{\"role\":\"user\",\"content\":\"={{$json.feedback}}\"}]}",
        "options": {}
      },
      "name": "LLM分类",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [440, 0]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            { "value1": "={{JSON.parse($json.choices[0].message.content).urgency}}", "value2": "P0" }
          ]
        }
      },
      "name": "IF紧急",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [660, -120]
    },
    {
      "parameters": {
        "url": "YOUR_WECOM_WORK_BOT_WEBHOOK",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"msgtype\":\"text\",\"text\":{\"content\":\"[P0反馈] {{JSON.parse($json.choices[0].message.content).summary}}\\n模块:{{JSON.parse($json.choices[0].message.content).module}}\\n来源:{{$node[\\\"去重+脱敏\\\"].json.source}}\"}}",
        "options": {}
      },
      "name": "推企微",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [880, -240]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            { "value1": "={{JSON.parse($json.choices[0].message.content).type}}", "value2": "bug" }
          ]
        }
      },
      "name": "IF是Bug",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [880, -20]
    },
    {
      "parameters": {
        "url": "=https://api.github.com/repos/YOUR_ORG/YOUR_REPO/issues",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer YOUR_GITHUB_TOKEN" },
            { "name": "Accept", "value": "application/vnd.github+json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"title\":\"[反馈] {{JSON.parse($json.choices[0].message.content).summary}}\",\"labels\":[\"from-feedback\",\"{{JSON.parse($json.choices[0].message.content).module}}\"],\"body\":\"来源:{{$node[\\\"去重+脱敏\\\"].json.source}}\\n紧急度:{{JSON.parse($json.choices[0].message.content).urgency}}\\n情感:{{JSON.parse($json.choices[0].message.content).sentiment}}\\n原文:{{$node[\\\"去重+脱敏\\\"].json.feedback}}\"}",
        "options": {}
      },
      "name": "建GitHubIssue",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [1100, -120]
    },
    {
      "parameters": {
        "url": "YOUR_FEISHU_BITABLE_API_URL",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{$json.choices[0].message.content}}",
        "options": {}
      },
      "name": "入汇总表",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [1320, -20]
    }
  ],
  "connections": {
    "Webhook收反馈": { "main": [ [{ "node": "去重+脱敏", "type": "main", "index": 0 }] ] },
    "去重+脱敏": { "main": [ [{ "node": "LLM分类", "type": "main", "index": 0 }] ] },
    "LLM分类": { "main": [ [{ "node": "IF紧急", "type": "main", "index": 0 }] ] },
    "IF紧急": { "main": [ [{ "node": "推企微", "type": "main", "index": 0 }], [{ "node": "IF是Bug", "type": "main", "index": 0 }] ] },
    "推企微": { "main": [ [{ "node": "IF是Bug", "type": "main", "index": 0 }] ] },
    "IF是Bug": { "main": [ [{ "node": "建GitHubIssue", "type": "main", "index": 0 }], [{ "node": "入汇总表", "type": "main", "index": 0 }] ] },
    "建GitHubIssue": { "main": [ [{ "node": "入汇总表", "type": "main", "index": 0 }] ] }
  }
}
