8
n8n 中文网amn8n.com

Lighthouse报告

中级

这是一个DevOps, AI Summarization领域的自动化工作流,包含 13 个节点。主要使用 If, Code, Telegram, HttpRequest, GoogleSheets 等节点。 使用Lighthouse、Gemini AI、Telegram警报和Google Sheets监控核心网页指标

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "5yT7sA01kGAY5Teu",
  "meta": {
    "instanceId": "d02289ff41436fdfe97f97a509483d64007d2a482e6a216298112e027bb59fbf",
    "templateCredsSetupCompleted": true
  },
  "name": "Lighthouse 报告",
  "tags": [],
  "nodes": [
    {
      "id": "9d96468e-d03c-4180-8e2b-71e60ab7c3f5",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -192,
        96
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "be628d83-99c4-4f70-ac3c-a0fc3c008f3a",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        656,
        272
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "LqsDVdm5OmSBk8zP",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6e16b71b-65d0-40cd-91ca-469935fe9dbf",
      "name": "如果",
      "type": "n8n-nodes-base.if",
      "position": [
        512,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "0ac8b99f-03f3-4ce5-bee3-0bdb85764dad",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['first-contentful-paint'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "f230a71d-c8ee-47e8-970e-1ebb2c0d5324",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['speed-index'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "b49040c6-eea1-4df8-b8ec-bccbff9dcbc8",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['largest-contentful-paint'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "015ac9bd-2dd4-4cac-a3ea-e8999efd4f68",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['cumulative-layout-shift'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "843fe25a-a1a4-474f-a5b7-53501f7dfe65",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['total-blocking-time'].score }}",
              "rightValue": 0.95
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "640a72fd-312b-4c67-b78a-4ff90eb25df9",
      "name": "发送通知",
      "type": "n8n-nodes-base.telegram",
      "position": [
        720,
        -128
      ],
      "webhookId": "b16fb70f-eeea-4696-b235-0f4fd493761d",
      "parameters": {
        "text": "=Reminder: One of the Core Web Vitals has a score below 0.95!\n\nPage: Home\n\nFCP: {{ $json.cwv['first-contentful-paint'].value }}, Score: {{ $json.cwv['first-contentful-paint'].score }}\n\nSpeed Index: {{ $json.cwv['speed-index'].value }}, Score: {{ $json.cwv['largest-contentful-paint'].score }}\n\nTBT: {{ $json.cwv['total-blocking-time'].value }}, Score: {{ $json.cwv['total-blocking-time'].score }}\n\nInteractive: {{ $json.cwv.interactive.value }}, Score: {{ $json.cwv.interactive.score }}\n\nCLS: {{ $json.cwv['cumulative-layout-shift'].value }}, Score: {{ $json.cwv['cumulative-layout-shift'].score }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "BDQbUISqJJFVGPsF",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7ebc6e84-0192-45df-a2e3-4d5a01aa3bdc",
      "name": "调用页面速度洞察",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        32,
        96
      ],
      "parameters": {
        "url": "https://www.googleapis.com/pagespeedonline/v5/runPagespeed",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "url"
            },
            {
              "name": "key"
            },
            {
              "name": "strategy",
              "value": "mobile"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "242c0cb4-c313-4653-8c33-447968e5753c",
      "name": "处理 CWV 和审计数据",
      "type": "n8n-nodes-base.code",
      "position": [
        352,
        96
      ],
      "parameters": {
        "jsCode": "const cwv = [\n'first-contentful-paint',\n'speed-index',\n'largest-contentful-paint',\n'total-blocking-time',\n'interactive',\n  'cumulative-layout-shift'\n]\n\nconst map = new Map();\n\ncwv.map((item) => {\n  map.set(item, {\n    value: $input.first().json.lighthouseResult.audits[item].displayValue,\n    score: $input.first().json.lighthouseResult.audits[item].score\n  })\n})\n\nconst obj = Object.fromEntries(map);\n\nconst audits = Object.keys($input.first().json.lighthouseResult.audits).filter((key) => !key.includes(cwv))\n\nlet auditsDesc = \"\"\n\naudits.forEach((key) => {\n  auditsDesc += $input.first().json.lighthouseResult.audits[key].title + $input.first().json.lighthouseResult.audits[key].description.replace(/\\[[^\\]]*\\]\\([^)]+\\)/g, '').replace(/\\s{2,}/g, ' ').trim()\n})\n\nreturn [\n  {\n    json: {\n      cwv: obj,\n      audits: auditsDesc\n    }\n  }\n]"
      },
      "typeVersion": 2
    },
    {
      "id": "60380b8b-ec37-44b4-9314-89c82c46a0e6",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -512,
        -208
      ],
      "parameters": {
        "width": 640,
        "height": 208,
        "content": "## 将 Lighthouse 报告生成自动化发送至 Telegram 或其他通讯工具及 Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "6687d507-bb75-4129-830c-a98fd936841a",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        288
      ],
      "parameters": {
        "color": 7,
        "content": "使用 PageSpeed Insights API"
      },
      "typeVersion": 1
    },
    {
      "id": "e8799b32-2704-486c-bfc2-b331758b75c3",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        256,
        288
      ],
      "parameters": {
        "color": 7,
        "content": "## Javascript 代码"
      },
      "typeVersion": 1
    },
    {
      "id": "2e62b919-da7c-4e62-83ae-81dacb6bad16",
      "name": "汇总审计描述",
      "type": "@n8n/n8n-nodes-langchain.chainSummarization",
      "position": [
        656,
        96
      ],
      "parameters": {
        "options": {
          "batching": {},
          "summarizationMethodAndPrompts": {
            "values": {
              "prompt": "Acting as a staff web engineer and core web vitals expert, you must create a insightful report to give use the action items for improving the web. Don't mention the role in output.\n\nWrite a concise summary of the following in the list of action items in bullets form without any introduction:\n\n\n\"{text}\"\n"
            }
          }
        },
        "chunkingMode": "advanced"
      },
      "typeVersion": 2.1
    },
    {
      "id": "71e7be4c-ac64-4dd5-a8c9-e70e46c38e8e",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        288,
        -224
      ],
      "parameters": {
        "color": 7,
        "content": "### 仅当至少一项 CWV 分数低于预期阈值时发送消息"
      },
      "typeVersion": 1
    },
    {
      "id": "4eedeb48-cfb0-43aa-b1b0-c842f810c526",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -320
      ],
      "parameters": {
        "color": 7,
        "content": "### 您可根据偏好更换通讯工具"
      },
      "typeVersion": 1
    },
    {
      "id": "675e51d4-bdec-4753-8dcb-202b786dd8f0",
      "name": "在指定工作表中追加行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1040,
        96
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "hhkaTilBRdo87XG7",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.6
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6d4d54d3-e5a3-471a-9732-a0660efd44d7",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Send Notification",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "call page speed insights",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "summarize audit description",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "call page speed insights": {
      "main": [
        [
          {
            "node": "processing data cwv and audits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "summarize audit description": {
      "main": [
        [
          {
            "node": "Append row in specific sheet ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "processing data cwv and audits": {
      "main": [
        [
          {
            "node": "summarize audit description",
            "type": "main",
            "index": 0
          },
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 开发运维, AI 摘要总结

需要付费吗?

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

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

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

作者
Rully Saputra

Rully Saputra

@rullysaputra15

Specializing in software engineering with over 5 years of hands-on experience. In addition to my expertise in web development, I also have experience in creating Hybrid mobile apps.

外部链接
在 n8n.io 查看

分享此工作流