8
n8n 中文网amn8n.com

情感分析器

中级

这是一个AI领域的自动化工作流,包含 14 个节点。主要使用 Code, Gmail, QuickChart, GoogleSheets, ManualTrigger 等节点,结合人工智能技术实现智能自动化。 情感分析可视化工具

前置要求
  • Google 账号和 Gmail API 凭证
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "4BOP29RhumejWZ6r",
  "meta": {
    "instanceId": "9cff38efa9e14e046ee88ad0878735c9b841d16e934d6ad95ba7fd58bb5558de"
  },
  "name": "情感分析器",
  "tags": [],
  "nodes": [
    {
      "id": "cb616bea-a6ad-4864-8169-9b0c24868761",
      "name": "📋 设置说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -300,
        40
      ],
      "parameters": {
        "width": 400,
        "height": 460,
        "content": "## 📋 需要设置"
      },
      "typeVersion": 1
    },
    {
      "id": "da05ebb8-6027-43d9-8c56-42d33d6d5f78",
      "name": "🔧 配置 Google Sheets",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -160
      ],
      "parameters": {
        "width": 300,
        "height": 340,
        "content": "## 🔧 自定义此节点"
      },
      "typeVersion": 1
    },
    {
      "id": "a07f32b5-1f38-4f61-b2c4-1e91b0df9512",
      "name": "🤖 配置 OpenAI",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        740
      ],
      "parameters": {
        "width": 420,
        "height": 200,
        "content": "## 🤖 自定义此节点"
      },
      "typeVersion": 1
    },
    {
      "id": "370277f5-8a80-4dc8-aff8-f025d6123356",
      "name": "📧 配置 Gmail",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        -60
      ],
      "parameters": {
        "width": 340,
        "height": 220,
        "content": "## 📧 自定义此节点"
      },
      "typeVersion": 1
    },
    {
      "id": "bccef3f8-801b-421a-8865-00064fc313f2",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        620,
        200
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "76118dc2-c52d-4a1a-aba2-981a62d4a28a",
      "name": "情感分析",
      "type": "@n8n/n8n-nodes-langchain.sentimentAnalysis",
      "position": [
        820,
        360
      ],
      "parameters": {
        "options": {
          "categories": "Positive, Neutral, Negative",
          "enableAutoFixing": true,
          "systemPromptTemplate": "You are highly intelligent and accurate sentiment analyzer. Analyze the sentiment of the provided text. Categorize it into one of the following: {categories}. Use the provided formatting instructions. Only output the JSON.",
          "includeDetailedResults": false
        },
        "inputText": "=Title: {{ $json['Review title'] }}\nText: {{ $json['Review text'] }}"
      },
      "retryOnFail": false,
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "c34c8c45-fd8e-4cef-8156-6a5658c48c46",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        820,
        540
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "7bd27f43-9207-40f4-9c6a-bea0be03a6fc",
      "name": "点击\"测试工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        180,
        200
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c2c21691-fd21-4afe-a60d-08c6399372e5",
      "name": "选择 Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        400,
        200
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEETS_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit",
          "cachedResultName": "Your Customer Reviews Sheet"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "4a4b2f78-d043-4853-980d-f24c3f5139dd",
      "name": "更新 Google 表格",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1180,
        520
      ],
      "parameters": {
        "columns": {
          "value": {
            "Sentiment": "={{ $json.sentimentAnalysis.category }}"
          },
          "schema": [
            {
              "id": "Review title",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Review title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Review text",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Review text",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sentiment",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sentiment",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sentimentAnalysis",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "sentimentAnalysis",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "USER_ENTERED"
        },
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEETS_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit",
          "cachedResultName": "Your Customer Reviews Sheet"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "e8af1018-02ea-4961-be63-4ac7e0b2db4a",
      "name": "从 Google Sheet 读取数据",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        980,
        180
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEETS_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit",
          "cachedResultName": "Your Customer Reviews Sheet"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.5
    },
    {
      "id": "58cfddb4-cc28-451a-a4ec-f8d391c7b198",
      "name": "提取每种情感的回答数量",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        180
      ],
      "parameters": {
        "jsCode": "const comments = $input.all();\nlet sentimentCount = { Positive: 0, Negative: 0, Neutral: 0 };\n\ncomments.forEach((comment) => {\n  const sentiment = comment?.json?.sentimentAnalysis;\n  if (sentiment.includes(\"Positive\")) {\n    sentimentCount.Positive++;\n  } else if (sentiment.includes(\"Negative\")) {\n    sentimentCount.Negative++;\n  } else if (sentiment.includes(\"Neutral\")) {\n    sentimentCount.Neutral++;\n  }\n});\n\nreturn {\n  labels: [\"Positive\", \"Neutral\", \"Negative\"],\n  values: [\n    sentimentCount.Positive,\n    sentimentCount.Neutral,\n    sentimentCount.Negative,\n  ],\n};\n"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "fa766ee4-8dff-44cd-b2a5-9c2f079ab160",
      "name": "生成 QuickChart",
      "type": "n8n-nodes-base.quickChart",
      "position": [
        1380,
        180
      ],
      "parameters": {
        "data": "={{ $json.values }}",
        "output": "=data",
        "labelsMode": "array",
        "labelsArray": "={{ $json.labels }}",
        "chartOptions": {},
        "datasetOptions": {}
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "952e3afc-c5a3-4faf-92e1-a467399bc7c8",
      "name": "发送带有情感图表的 Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1600,
        180
      ],
      "webhookId": "WEBHOOK_ID_WILL_BE_GENERATED",
      "parameters": {
        "sendTo": "YOUR_EMAIL@example.com",
        "message": "=Dear Team,\n\nPlease find attached the sentiment analysis summary of recent customer reviews.\n\nBest regards,\nAutomated Sentiment Analysis System",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          }
        },
        "subject": "Sentiment Analysis Summary",
        "emailType": "text"
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "894d1878-53b7-4efd-a542-b2851424e27c",
  "connections": {
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Read Data from Google Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sentiment Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Sentiment Analysis",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Sentiment Analysis": {
      "main": [
        [
          {
            "node": "Update Google Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Google Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate QuickChart": {
      "main": [
        [
          {
            "node": "Send Gmail with Sentiment Chart",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Google Sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Google Sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Data from Google Sheet": {
      "main": [
        [
          {
            "node": "Extract Number of Answers per Sentiment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Test workflow'": {
      "main": [
        [
          {
            "node": "Select Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Number of Answers per Sentiment": {
      "main": [
        [
          {
            "node": "Generate QuickChart",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 人工智能

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流