{
  "name": "Gmail\u5206\u985ePoC \u30ef\u30fc\u30af\u30d5\u30ed\u30fc",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {},
        "options": {}
      },
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// HTML\u30bf\u30b0\u9664\u53bb\u3068\u30c6\u30ad\u30b9\u30c8\u6b63\u898f\u5316\nconst items = $input.all();\n\nreturn items.map(item => {\n  const data = item.json;\n  \n  // HTML\u30bf\u30b0\u9664\u53bb\n  const cleanBody = data.textPlain || data.textHtml?.replace(/<[^>]*>/g, '') || '';\n  \n  // \u57fa\u672c\u7684\u306a\u6b63\u898f\u5316\n  const normalizedBody = cleanBody\n    .replace(/\\r\\n/g, '\\n')\n    .replace(/\\n+/g, ' ')\n    .trim();\n  \n  return {\n    json: {\n      ...data,\n      subject: data.subject || '',\n      body: normalizedBody,\n      processedAt: new Date().toISOString()\n    }\n  };\n});"
      },
      "name": "Email Preprocessing",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:5000/api/enrich-context",
        "options": {
          "bodyContentType": "json",
          "headers": {
            "item": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        },
        "jsonParameters": true,
        "bodyParametersJson": "{\n  \"subject\": \"{{ $json.subject }}\",\n  \"body\": \"{{ $json.body }}\"\n}"
      },
      "name": "MCP Context Enricher",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:5000/api/classify",
        "options": {
          "bodyContentType": "json",
          "headers": {
            "item": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        },
        "jsonParameters": true,
        "bodyParametersJson": "{\n  \"subject\": \"{{ $json.subject }}\",\n  \"body\": \"{{ $json.body }}\"\n}"
      },
      "name": "AI Classification",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "{{ $json.classification }}",
              "operation": "equal",
              "value2": "\u91cd\u8981"
            }
          ]
        }
      },
      "name": "Switch\u5206\u985e",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// LINE\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8\u4f5c\u6210\nconst items = $input.all();\n\nreturn items.map(item => {\n  const classification = $('AI Classification').item.json.classification;\n  const confidence = $('AI Classification').item.json.confidence;\n  const context = $('MCP Context Enricher').item.json.enriched_context;\n  const subject = item.json.subject;\n  \n  const message = `\ud83d\udea8 \u91cd\u8981\u30e1\u30fc\u30eb\u691c\u51fa\\n` +\n    `\u5206\u985e: ${classification}\\n` +\n    `\u4fe1\u983c\u5ea6: ${(confidence * 100).toFixed(1)}%\\n` +\n    `\u4ef6\u540d: ${subject}\\n` +\n    `\u6587\u8108: ${context}`;\n  \n  return {\n    json: {\n      message: message,\n      classification: classification\n    }\n  };\n});"
      },
      "name": "LINE Message Creation",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1340,
        200
      ]
    },
    {
      "parameters": {
        "messageType": "text",
        "text": "={{ $json.message }}",
        "additionalFields": {}
      },
      "name": "LINE\u901a\u77e5",
      "type": "n8n-nodes-base.line",
      "typeVersion": 1,
      "position": [
        1560,
        200
      ]
    },
    {
      "parameters": {
        "sheetId": "YOUR_SHEET_ID",
        "range": "A:F",
        "options": {
          "valueInputMode": "USER_ENTERED"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "timestamp": "={{ new Date().toISOString() }}",
            "subject": "={{ $json.subject }}",
            "classification": "={{ $('AI Classification').item.json.classification }}",
            "confidence": "={{ $('AI Classification').item.json.confidence }}",
            "context": "={{ $('MCP Context Enricher').item.json.enriched_context }}",
            "priority": "={{ $('MCP Context Enricher').item.json.priority_level }}"
          }
        }
      },
      "name": "Google Sheets\u30ed\u30b0\u4fdd\u5b58",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1340,
        400
      ]
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Email Preprocessing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Preprocessing": {
      "main": [
        [
          {
            "node": "MCP Context Enricher",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MCP Context Enricher": {
      "main": [
        [
          {
            "node": "AI Classification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Classification": {
      "main": [
        [
          {
            "node": "Switch\u5206\u985e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch\u5206\u985e": {
      "main": [
        [
          {
            "node": "LINE Message Creation",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google Sheets\u30ed\u30b0\u4fdd\u5b58",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets\u30ed\u30b0\u4fdd\u5b58",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LINE Message Creation": {
      "main": [
        [
          {
            "node": "LINE\u901a\u77e5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "gmail-classifier-workflow"
}