8
n8n 中文网amn8n.com

使用Google Sheets和邮件通知优化标题清晰度

中级

这是一个Content Creation, Multimodal AI领域的自动化工作流,包含 14 个节点。主要使用 If, Code, EmailSend, FormTrigger, HttpRequest 等节点。 使用Google Sheets和邮件通知优化标题清晰度

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "60c025075753afcab9f803964b4caaca9402f435deb4efafbb8e3b93b54d8752",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "1dc70980-1f3d-4352-8f39-9465eb0357ff",
      "name": "表单提交时",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -80,
        0
      ],
      "webhookId": "a3954bfd-5e79-48fe-a4a9-e6fa35122c14",
      "parameters": {
        "options": {},
        "formTitle": "YouTube Video giveaway ",
        "formFields": {
          "values": [
            {
              "fieldLabel": "url",
              "requiredField": true
            }
          ]
        },
        "formDescription": "YouTube Video giveaway "
      },
      "typeVersion": 2.2
    },
    {
      "id": "bc236f4c-6d15-447b-94a8-d1d435455e20",
      "name": "获取 YouTube 评论",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        176,
        0
      ],
      "parameters": {
        "url": "https://youtube-comments-scraper.p.rapidapi.com/comment.php",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "={{ $json.url }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-rapidapi-host",
              "value": "youtube-comments-scraper.p.rapidapi.com"
            },
            {
              "name": "x-rapidapi-key",
              "value": "your key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "155352c4-d1d6-49c3-a86f-a65176acba98",
      "name": "检查 API 响应状态",
      "type": "n8n-nodes-base.if",
      "position": [
        448,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "38976149-dd8b-452f-a2d1-cd4c88dfa791",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": "=200"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "eefb9182-3705-4c12-9e58-7ae37a3e5c88",
      "name": "随机选择评论者",
      "type": "n8n-nodes-base.code",
      "position": [
        720,
        0
      ],
      "parameters": {
        "jsCode": "// Extract the array of comment items from the API response\nconst comments = $input.first().json.body.items || [];\n\n// Extract authorDisplayName safely\nconst authors = comments\n  .map(item => {\n    // Check if snippet and topLevelComment exist before accessing authorDisplayName\n    if (item.snippet && item.snippet.topLevelComment && item.snippet.topLevelComment.snippet) {\n      return item.snippet.topLevelComment.snippet.authorDisplayName;\n    }\n    return null; // or undefined\n  })\n  .filter(name => !!name); // filter out null/undefined\n\nif (authors.length === 0) {\n  // No authors found, return empty or null\n  return [{ json: { randomAuthorDisplayName: null } }];\n}\n\n// Randomly select one authorDisplayName\nconst randomIndex = Math.floor(Math.random() * authors.length);\nconst randomAuthor = authors[randomIndex];\n\n// Return as output\nreturn [{ json: { randomAuthorDisplayName: randomAuthor } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "ac6097b0-8fd5-41d3-8733-e6d61217b822",
      "name": "通知:API 响应无效",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        704,
        320
      ],
      "webhookId": "06e6ac0e-286b-432a-b233-a61817cab593",
      "parameters": {
        "html": "Hello,\n\nThe attempt to fetch comments from the provided YouTube URL did not succeed.  \nPlease verify the URL and try again.\n\nIf the problem persists, please check the API key or contact support.\n\nBest regards,  \nYouTube Giveaway Bot\n",
        "options": {},
        "subject": "YouTube Comments Scraper: API Request Failed",
        "toEmail": "owaner@gmail.com",
        "fromEmail": "admin@gmail.com"
      },
      "credentials": {
        "smtp": {
          "id": "nPwKPPgVavimTJX4",
          "name": "SMTP account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b28e03d1-0103-4453-97bf-cdb69ecb3c49",
      "name": "通知获奖者邮件",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1312,
        -64
      ],
      "webhookId": "b8e21334-f8bb-442e-8060-e3bd170f4f6a",
      "parameters": {
        "html": "=Hello ,\n\nThe YouTube giveaway has concluded, and the winner has been selected!\n\nWinner: {{$json.randomAuthorDisplayName}}\n\nThe winner's details have been logged in the spreadsheet for your records.\n\nBest regards,  \nYour Giveaway Automation Bot\n",
        "options": {},
        "subject": "=Congratulations! {{$json.randomAuthorDisplayName}} is the Winner of the Giveaway!",
        "toEmail": "=owner@gmail.com",
        "fromEmail": "admin@gmail.com"
      },
      "credentials": {
        "smtp": {
          "id": "H0f4Gja9ECFRA34L",
          "name": "SMTP account 2"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "00ed6cc0-8f7f-44e9-bf69-cb7512c49163",
      "name": "将获奖者记录到 Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1008,
        -48
      ],
      "parameters": {
        "columns": {
          "value": {
            "Url": "={{ $('On form submission').item.json.url }}",
            "Date": "={{ $('On form submission').item.json.submittedAt }}",
            "Winner": "={{ $json.randomAuthorDisplayName }}"
          },
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Url",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Winner",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Winner",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "Rt0RWApx8PL9t0RF",
          "name": "Google Docs account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "7345d6e6-dde3-4880-85a5-e34780ad9335",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -112
      ],
      "parameters": {
        "height": 256,
        "content": "向 RapidAPI 发送 POST 请求以从给定 URL 抓取 YouTube 评论。"
      },
      "typeVersion": 1
    },
    {
      "id": "9f072800-bbac-412f-99a1-28a552ce9558",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -112
      ],
      "parameters": {
        "height": 256,
        "content": "当提交包含 YouTube URL 的表单时触发工作流。"
      },
      "typeVersion": 1
    },
    {
      "id": "26e755bc-4755-4dc7-a7d0-4f2f3cfbf0ca",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        -112
      ],
      "parameters": {
        "height": 256,
        "content": "检查 API 响应状态码是否等于 200(成功)。"
      },
      "typeVersion": 1
    },
    {
      "id": "449460b5-3b24-42a0-957f-2a47363889bc",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -112
      ],
      "parameters": {
        "height": 256,
        "content": "从获取的评论中提取作者名称。"
      },
      "typeVersion": 1
    },
    {
      "id": "023052db-e197-48ff-9567-62d2565cbf2e",
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        672,
        192
      ],
      "parameters": {
        "height": 288,
        "content": "如果 API 调用失败或返回无效响应,则发送电子邮件通知。"
      },
      "typeVersion": 1
    },
    {
      "id": "f814c860-8649-4f9b-bcb7-8f9a7a83d697",
      "name": "便签说明5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        -176
      ],
      "parameters": {
        "height": 288,
        "content": "将获奖者姓名、URL 和提交日期附加到 Google Sheet。"
      },
      "typeVersion": 1
    },
    {
      "id": "e4feec40-ba6b-4c15-b2a2-5525f4424dfd",
      "name": "便签 6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        -192
      ],
      "parameters": {
        "height": 272,
        "content": "发送祝贺邮件宣布赠品获奖者。"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "On form submission": {
      "main": [
        [
          {
            "node": "Fetch YouTube Comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch YouTube Comments": {
      "main": [
        [
          {
            "node": "Check API Response Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Random Commenter": {
      "main": [
        [
          {
            "node": "Log Winner to Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check API Response Status": {
      "main": [
        [
          {
            "node": "Select Random Commenter",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify: Invalid API Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Winner to Google Sheet": {
      "main": [
        [
          {
            "node": "Notify Winner Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流