{
  "id": "qS9W7d2IVCxZZKaN",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "\u9009\u9898\u6355\u624b\u6a21\u677f",
  "tags": [
    {
      "id": "yz1g2PbPKQgVLlgc",
      "name": "\u9009\u9898\u6355\u624b",
      "createdAt": "2025-06-25T01:29:38.391Z",
      "updatedAt": "2025-06-25T01:29:38.391Z"
    }
  ],
  "nodes": [
    {
      "id": "9fed71e8-52e3-4c6e-9e95-22c387915f81",
      "name": "Apify\u6293\u53d6x\u63a8\u6587",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2780,
        1120
      ],
      "parameters": {
        "url": "https://api.apify.com/v2/acts/nfp1fpt5gUlBwPcor/run-sync-get-dataset-items",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "input",
              "value": "=={{ JSON.stringify({\n    \"queries\": [$(\"Analysis Parameters\").item.json.keyword],\n    \"tweets_desired\": 20,\n    \"proxyConfiguration\": {\n        \"useApifyProxy\": true\n    }\n}) }}"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "858cf619-ed1b-4b9d-aa7d-6c99872641d5",
      "name": "ScrapingBee\u6293\u53d6x\u63a8\u6587",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2980,
        1120
      ],
      "parameters": {
        "url": "https://api.scrapingbee.com/api/v1",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "={{ \"https://x.com/search?q=\" + encodeURIComponent($json.keyword) }}"
            },
            {
              "name": "render_js",
              "value": "true"
            },
            {
              "name": "wait",
              "value": "3000"
            }
          ]
        }
      },
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "68a4588f-9086-4974-ac6e-57c5269b801f",
      "name": "twitterapi\u6293\u53d6x\u63a8\u6587",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2580,
        1120
      ],
      "parameters": {
        "url": "https://api.twitterapi.io/twitter/user/last_tweets",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "userName",
              "value": "={{ $('\u5206\u6210\u591a\u6761').item.json.users }}"
            },
            {
              "name": "cursor",
              "value": "={{ $json.cursor }}"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "632ab262-c571-46b7-a2af-37b7e430522b",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -2200,
        360
      ],
      "parameters": {
        "options": {},
        "batchSize": 10
      },
      "typeVersion": 3
    },
    {
      "id": "9fb2d5ce-5f69-4c22-8f3a-6b4a681ab11e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2980,
        840
      ],
      "parameters": {
        "color": 6,
        "width": 260,
        "height": 240,
        "content": "## X Third-party scraping tools\nX API is relatively easy to configure and suitable for quick start-up, but they offer limited free quotas. Here are three third-party scraping tools. Please refer to the official documentation for configuration instructions."
      },
      "typeVersion": 1
    },
    {
      "id": "40f49eac-3232-40d1-b6ad-c093d862cbbc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2040,
        700
      ],
      "parameters": {
        "color": 6,
        "width": 220,
        "height": 140,
        "content": "## llm node\nJust change it to your usual one."
      },
      "typeVersion": 1
    },
    {
      "id": "7a0fbe60-d027-4be0-9a64-c2f652db85ed",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        220
      ],
      "parameters": {
        "color": 6,
        "content": "## URL configuration settings\n\nFeishu Group Chat - Settings - Create a new robot to obtain the webhook, then fill it in."
      },
      "typeVersion": 1
    },
    {
      "id": "12041c3c-5e45-4ae3-aeec-7769e9599f36",
      "name": "Form Trigger",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -3340,
        300
      ],
      "parameters": {
        "options": {},
        "formTitle": "\u9009\u9898\u6355\u624b",
        "formFields": {
          "values": [
            {
              "fieldLabel": "keyword",
              "placeholder": "e.g.AI",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Please enter the core keywords you want to analyze, then click Submit."
      },
      "typeVersion": 2.2
    },
    {
      "id": "b6164739-04d2-48f3-a22b-d4e4e3a57c9e",
      "name": "Analysis Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        -3160,
        300
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "keyword-assignment",
              "name": "keyword",
              "type": "string",
              "value": "={{ $json.body.keyword || $json.query.keyword || 'AI' }}"
            },
            {
              "id": "date-assignment",
              "name": "search_date",
              "type": "string",
              "value": "={{ $now.toFormat('yyyy-MM-dd') }}"
            },
            {
              "id": "analysis-id",
              "name": "analysis_id",
              "type": "string",
              "value": "={{ $now.toFormat('yyyyMMddHHmmss') }}_{{ ($json.body.keyword || $json.query.keyword || 'default').replace(' ', '_') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "70bfecff-afa0-4423-810e-d570d86512fb",
      "name": "Reddit: Search Posts",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -2940,
        160
      ],
      "parameters": {
        "keyword": "={{ $('Analysis Parameters').item.json.keyword }}",
        "location": "allReddit",
        "operation": "search",
        "additionalFields": {}
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "77808c17-0b0b-4c52-a0e7-095d79de44b5",
      "name": "Format Reddit Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -2760,
        160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "reddit-weight",
              "name": "source_weight",
              "type": "number",
              "value": 0.7
            },
            {
              "id": "reddit-source",
              "name": "source_type",
              "type": "string",
              "value": "reddit"
            },
            {
              "id": "reddit-content",
              "name": "content",
              "type": "string",
              "value": "={{ $json.title + ' ' + ($json.selftext || '') }}"
            },
            {
              "id": "reddit-url",
              "name": "url",
              "type": "string",
              "value": "={{ $json.url }}"
            },
            {
              "id": "reddit-score",
              "name": "engagement_score",
              "type": "number",
              "value": "={{ $json.ups }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "fa853181-835f-4f89-98c6-63dd093c8ac7",
      "name": "YouTube: Search Videos",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2940,
        340
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/search",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "part",
              "value": "snippet"
            },
            {
              "name": "q",
              "value": "={{ $('Analysis Parameters').item.json.keyword }}"
            },
            {
              "name": "type",
              "value": "video"
            },
            {
              "name": "order",
              "value": "relevance"
            },
            {
              "name": "maxResults",
              "value": "15"
            },
            {
              "name": "publishedAfter",
              "value": "={{ $now.minus({days: 7}).toISO() }}"
            }
          ]
        }
      },
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "82c25f04-f65f-4c7e-bbf7-661ba36a9a6b",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -2760,
        340
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "items"
      },
      "typeVersion": 1
    },
    {
      "id": "224a28a8-42f0-441a-b5ba-744d327c62c0",
      "name": "X: Search Tweets",
      "type": "n8n-nodes-base.twitter",
      "position": [
        -2940,
        520
      ],
      "parameters": {
        "operation": "search",
        "searchText": "={{ $json.keyword }}",
        "additionalFields": {}
      },
      "credentials": {
        "twitterOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "af9dbdce-c8dc-432d-8f06-a86f6110032f",
      "name": "Parse Twitter Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -2760,
        520
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// \u65b0\u4ee3\u7801\uff1a\u8f93\u51fa\u4e0e\u5176\u4ed6\u5e73\u53f0\u5b8c\u5168\u4e00\u81f4\u7684\u683c\u5f0f\uff0c\u5e76\u589e\u52a0 engagement_score\ntry {\n  const tweetObject = $input.item.json;\n\n  // \u4ece\u63a8\u6587\u7684\u516c\u5f00\u6307\u6807(public_metrics)\u4e2d\u8ba1\u7b97\u4e00\u4e2a\u7efc\u5408\u7684\u4e92\u52a8\u5206\u6570\n  // \u540c\u65f6\u589e\u52a0\u5b89\u5168\u68c0\u67e5\uff0c\u9632\u6b62\u67d0\u4e9b\u6307\u6807\u4e0d\u5b58\u5728\u65f6\u62a5\u9519\n  const metrics = tweetObject.public_metrics || {};\n  const likeCount = metrics.like_count || 0;\n  const retweetCount = metrics.retweet_count || 0;\n  const replyCount = metrics.reply_count || 0;\n  const quoteCount = metrics.quote_count || 0;\n  const engagementScore = likeCount + retweetCount + replyCount + quoteCount;\n\n  // \u6784\u5efa\u4e0e\u5176\u4ed6\u5e73\u53f0\u683c\u5f0f\u5b8c\u5168\u4e00\u81f4\u7684result\u5bf9\u8c61\n  const result = {\n    source_weight: 0.9,                        // \u6743\u91cd\n    source_type: 'twitter',                    // \u6765\u6e90\u7c7b\u578b\n    content: tweetObject.text,                 // \u63a8\u6587\u5185\u5bb9\n    url: `https://x.com/anyuser/status/${tweetObject.id}`, // \u63a8\u6587\u94fe\u63a5\n    engagement_score: engagementScore          // \u4e92\u52a8\u5206\u6570\n  };\n\n  return { json: result };\n\n} catch (error) {\n  console.error('\u5904\u7406\u63a8\u6587JSON\u65f6\u51fa\u9519:', error);\n  return { json: { error: '\u5904\u7406\u63a8\u6587JSON\u5931\u8d25', raw_data: $input.item.json } };\n}"
      },
      "typeVersion": 2,
      "alwaysOutputData": false
    },
    {
      "id": "2a76c59f-7626-41a9-b72d-9197b1173a67",
      "name": "Format YouTube Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -2580,
        340
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "youtube-weight",
              "name": "source_weight",
              "type": "number",
              "value": 0.8
            },
            {
              "id": "youtube-source",
              "name": "source_type",
              "type": "string",
              "value": "youtube"
            },
            {
              "id": "youtube-content",
              "name": "content",
              "type": "string",
              "value": "={{ $json.snippet.title + ' ' + $json.snippet.description }}"
            },
            {
              "id": "youtube-url",
              "name": "url",
              "type": "string",
              "value": "=https://www.youtube.com/watch?v={{ $json.id.videoId }}"
            },
            {
              "id": "youtube-channel",
              "name": "channel",
              "type": "string",
              "value": "={{ $json.snippet.channelTitle }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "21d91bbc-8116-4c48-9f51-f81445e8684c",
      "name": "Merge: All Sources",
      "type": "n8n-nodes-base.merge",
      "position": [
        -2360,
        360
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3
    },
    {
      "id": "1d5341a4-1429-4d7a-afcb-8074e43ff748",
      "name": "AI Pre-filtering",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -2040,
        360
      ],
      "parameters": {
        "text": "\u4f60\u662f\u4e00\u4f4d\u654f\u9510\u7684\u9009\u9898\u7b56\u5212\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u4e3a\u7f16\u8f91\u53d1\u6398\u6709\u6f5c\u529b\u7684\u5185\u5bb9\uff0c\u800c\u4e0d\u662f\u8fc7\u6ee4\u4fe1\u606f\uff0c\u540c\u65f6\u9700\u8981\u3010\u4fdd\u7559\u539f\u59cb\u5185\u5bb9\u3011\u3002\n\n\u8bf7\u6839\u636e\u7ed9\u5b9a\u7684\u5173\u952e\u8bcd\uff0c\u4e3a\u6bcf\u4e00\u6761\u5185\u5bb9\u8fdb\u884c\u5224\u65ad\u3002\u5982\u679c\u5185\u5bb9\u6ee1\u8db3\u3010\u4ee5\u4e0b\u4efb\u4e00\u6761\u4ef6\u3011\uff0c\u5c31\u5fc5\u987b\u6807\u8bb0\u4e3a\"YES\"\uff0c\u5426\u5219\u6807\u8bb0\u4e3a\"NO\"\uff1a\n1. \u5305\u542b\u5f3a\u70c8\u7684\u4e2a\u4eba\u89c2\u70b9\u3001\u60c5\u7eea\u6216\u72ec\u7279\u7684\u4e2a\u4eba\u7ecf\u5386\u3002\n2. \u5f15\u53d1\u4e86\u4e89\u8bae\u6216\u591a\u4eba\u53c2\u4e0e\u7684\u8ba8\u8bba\u3002\n3. \u63d0\u51fa\u4e86\u4e00\u4e2a\u65b0\u9896\u7684\u95ee\u9898\u6216\u4e0e\u4f17\u4e0d\u540c\u7684\u89c1\u89e3\u3002\n4. \u867d\u7136\u7b80\u77ed\uff0c\u4f46\u53ef\u80fd\u662f\u4e00\u4e2a\u65b0\u5174\u8d8b\u52bf\u6216\u7f51\u7edc\u201c\u6897\u201d\u7684\u82d7\u5934\u3002\n\n\u4f60\u7684\u76ee\u6807\u662f\u201c\u5b81\u6ee5\u52ff\u7f3a\u201d\uff0c\u53ea\u8981\u5185\u5bb9\u6709\u4efb\u4f55\u53ef\u80fd\u6210\u4e3a\u597d\u9009\u9898\u7684\u706b\u82b1\uff0c\u90fd\u5e94\u6807\u8bb0\u4e3aYES\u3002\u7eaf\u7cb9\u7684\u5e7f\u544a\u6216\u5783\u573e\u4fe1\u606f\u624d\u5e94\u6807\u8bb0\u4e3aNO\u3002\n\n\u4f60\u7684\u56de\u590d\u5fc5\u987b\u9075\u5faa\u4ee5\u4e0b\u89c4\u5219\uff1a\n1. \u8fd4\u56de\u4e00\u4e2a\u4e25\u683c\u7684JSON\u6570\u7ec4\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u4e0d\u8981\u5305\u542b\u4efb\u4f55markdown\u6807\u8bb0 (\u5982```json)\u3002\n2. \u8be5\u6570\u7ec4\u7684\u957f\u5ea6\u5fc5\u987b\u4e0e\u8f93\u5165\u6570\u7ec4\u5b8c\u5168\u4e00\u81f4\u3002\n3. \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5fc5\u987b\u5305\u542b\u4ee5\u4e0b\u4e09\u4e2a\u5b57\u6bb5\uff1a\n   - `url`: \u539f\u59cb\u5185\u5bb9\u7684URL\u3002\n   - `decision`: \u4f60\u7684\u5224\u65ad\u7ed3\u679c\uff0c\u503c\u4e3a 'YES' \u6216 'NO'\u3002\n   - `content`: \u5fc5\u987b\u539f\u5c01\u4e0d\u52a8\u5730\u8fd4\u56de\u539f\u59cb\u5185\u5bb9\u3002\n\n\u793a\u4f8b\u8f93\u51fa\u683c\u5f0f:\n[\n  { \"url\": \"[http://example.com/article1](http://example.com/article1)\", \"decision\": \"YES\", \"content\": \"\u8fd9\u662f\u7b2c\u4e00\u7bc7\u6587\u7ae0\u7684\u5185\u5bb9...\" },\n  { \"url\": \"[http://example.com/article2](http://example.com/article2)\", \"decision\": \"NO\", \"content\": \"\u8fd9\u662f\u7b2c\u4e8c\u7bc7\u6587\u7ae0\u7684\u5185\u5bb9...\" }\n]\n\n\u5173\u952e\u8bcd: {{ $('\u8bbe\u7f6e\u5206\u6790\u53c2\u6570').item.json.keyword }}\n\n\u5f85\u5904\u7406\u5185\u5bb9\u6570\u7ec4:\n{{ JSON.stringify($json.data) }}",
        "batching": {
          "batchSize": 20
        },
        "messages": {
          "messageValues": [
            {
              "message": "=\u5173\u952e\u8bcd: {{ $('Analysis Parameters').item.json.keyword }}  \u5f85\u5904\u7406\u5185\u5bb9\u6570\u7ec4: {{ JSON.stringify($json) }}"
            }
          ]
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "5198dc72-a270-453f-9e68-78204b6eb9e7",
      "name": "Pre-filter Content",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -2040,
        540
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cdc21593-af88-4d1e-8c0c-79cd831673c7",
      "name": "Parse AI Filter Results",
      "type": "n8n-nodes-base.code",
      "position": [
        -1740,
        360
      ],
      "parameters": {
        "jsCode": "// \u6700\u7ec8\u4ee3\u7801\uff1a\u5728\"Run Once for All Items\"\u6a21\u5f0f\u4e0b\uff0c\u5904\u7406\u6240\u6709\u6279\u6b21\u5e76\u8fd4\u56de\u6240\u6709\u7ed3\u679c\n\n// 1. \u521b\u5efa\u4e00\u4e2a\u7a7a\u6570\u7ec4\uff0c\u7528\u6765\u5b58\u653e\u6240\u6709\u6279\u6b21\u89e3\u6790\u540e\u7684\u6700\u7ec8\u7ed3\u679c\u3002\nconst allParsedItems = [];\n\n// 2. \u904d\u5386\u6240\u6709\u8f93\u5165\u7684\u9879\u76ee\uff08\u60a8\u8fd9\u91cc\u768410\u4e2a\u6279\u6b21\uff09\u3002\n//    $input.all() \u53ef\u4ee5\u83b7\u53d6\u5168\u90e8\u7684\u8f93\u5165\u9879\u3002\nfor (const batchItem of $input.all()) {\n  try {\n    const contentString = batchItem.json.text;\n    if (!contentString) continue; // \u5982\u679c\u67d0\u4e2a\u6279\u6b21\u7684text\u4e3a\u7a7a\uff0c\u5219\u8df3\u8fc7\n\n    const cleanedContent = contentString.replace(/```json/g, '').replace(/```/g, '').trim();\n\n    // 3. \u89e3\u6790\u5f53\u524d\u6279\u6b21\u4e2d\u7684JSON\u5b57\u7b26\u4e32\u3002\n    const itemsInBatch = JSON.parse(cleanedContent);\n\n    // 4. \u5c06\u89e3\u6790\u51fa\u7684\u9879\u76ee\uff08\u4e00\u4e2a\u6570\u7ec4\uff09\u6dfb\u52a0\u5230\u6211\u4eec\u6700\u7ec8\u7684\u603b\u7ed3\u679c\u6570\u7ec4\u4e2d\u3002\n    if (Array.isArray(itemsInBatch)) {\n      allParsedItems.push(...itemsInBatch);\n    }\n\n  } catch (error) {\n    // \u5982\u679c\u67d0\u4e2a\u6279\u6b21\u89e3\u6790\u5931\u8d25\uff0c\u5728\u63a7\u5236\u53f0\u6253\u5370\u9519\u8bef\u5e76\u7ee7\u7eed\u5904\u7406\u4e0b\u4e00\u4e2a\u6279\u6b21\u3002\n    console.error(`\u4e00\u4e2a\u6279\u6b21\u89e3\u6790\u5931\u8d25\u3002\u9519\u8bef: ${error.message}. \u6279\u6b21\u5185\u5bb9: ${batchItem.json.text}`);\n  }\n}\n\n// 5. \u5faa\u73af\u7ed3\u675f\u540e\uff0c\u5c06\u5305\u542b\u4e86\u6240\u6709\u7ed3\u679c\u7684\u603b\u6570\u7ec4\uff0c\u683c\u5f0f\u5316\u6210n8n\u9700\u8981\u7684\u683c\u5f0f\u5e76\u8fd4\u56de\u3002\nreturn allParsedItems.map(item => ({ json: item }));"
      },
      "typeVersion": 2
    },
    {
      "id": "2e736b35-d703-4ef6-9af6-1a681563f2e3",
      "name": "IF: Is Content Relevant",
      "type": "n8n-nodes-base.if",
      "position": [
        -1560,
        360
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "filter-condition",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.decision }}",
              "rightValue": "YES"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "bb893ede-d07b-4c46-81f3-7985ab45dac4",
      "name": "Handle Filter Errors",
      "type": "n8n-nodes-base.code",
      "position": [
        -1340,
        520
      ],
      "parameters": {
        "jsCode": "try {\n  const errorInfo = {\n    error: '\u5de5\u4f5c\u6d41\u6267\u884c\u51fa\u9519',\n    timestamp: new Date().toISOString(),\n    node_error: $input.item(0).json.error || '\u672a\u77e5\u9519\u8bef',\n    analysis_id: $('Analysis Parameters').item.json.analysis_id || 'unknown'\n  };\n  \n  console.error('\u5de5\u4f5c\u6d41\u9519\u8bef:', errorInfo);\n  return { json: errorInfo };\n} catch (e) {\n  return { \n    json: { \n      error: '\u4e25\u91cd\u9519\u8bef: \u9519\u8bef\u5904\u7406\u8282\u70b9\u4e5f\u5931\u8d25\u4e86',\n      timestamp: new Date().toISOString()\n    } \n  };\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "937a9584-02d5-42b4-af30-49346f90ee0f",
      "name": "Aggregate: Relevant Items",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -1340,
        240
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "191fe689-acd1-45bb-a8d4-92b88967c95a",
      "name": "AI Deep Analysis",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -1180,
        240
      ],
      "parameters": {
        "text": "=\u4f60\u662f\u4e00\u4e2a\u5177\u5907\u5a92\u4f53\u7d20\u517b\u548c\u65b0\u95fb\u654f\u611f\u5ea6\u7684\u4fe1\u606f\u5206\u6790\u4e13\u5bb6\u3002\u4f60\u5c06\u6536\u5230\u4e00\u4e2a JSON \u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u5305\u542b\u4e00\u7bc7\u6587\u7ae0\u7684\u5185\u5bb9\u4e0e\u57fa\u7840\u4fe1\u606f\u3002\u8bf7\u9010\u6761\u8fdb\u884c\u6df1\u5ea6\u7ed3\u6784\u5316\u5206\u6790\uff0c\u5e76\u8f93\u51fa\u7edf\u4e00\u683c\u5f0f\u7684 JSON \u7ed3\u679c\u3002\n\n\u5206\u6790\u76ee\u6807\uff1a\n1. \u63d0\u53d6\u6587\u7ae0\u7684\u6838\u5fc3\u4fe1\u606f\uff1b\n2. \u8bc4\u4f30\u5176\u7528\u6237\u60c5\u7eea\u4e0e\u4f20\u64ad\u6f5c\u529b\uff1b\n3. \u7ed9\u51fa\u53ef\u884d\u751f\u7684\u65b0\u9009\u9898\u5efa\u8bae\u3002\n\n\u8bf7\u4e25\u683c\u9075\u5faa\u4ee5\u4e0b\u8f93\u51fa\u683c\u5f0f\uff0c\u8fd4\u56de\u4e00\u4e2aJSON\u5b57\u7b26\u4e32\uff0c\u4e0d\u8981\u5305\u542b\u4efb\u4f55markdown\u6807\u8bb0 (\u5982```json)\uff1a\n\n{\n  \"analyses\": [\n    {\n      \"original_url\": \"...\",\n      \"summary\": \"\u4e00\u53e5\u8bdd\u6838\u5fc3\u6458\u8981\",\n      \"topic\": \"\u6587\u7ae0\u4e3b\u8bdd\u9898\",\n      \"sentiment\": \"positive | negative | mixed\",\n      \"key_arguments\": [\"\u8981\u70b9A\", \"\u8981\u70b9B\", \"\u8981\u70b9C\"],\n      \"trending_potential\": 1-10\u4e4b\u95f4\u7684\u6570\u5b57\uff08\u57fa\u4e8e\u8be5\u5185\u5bb9\u7684\u70ed\u70b9\u6f5c\u529b\uff09,\n      \"audience_interest\": 1-10\u4e4b\u95f4\u7684\u6570\u5b57\uff08\u57fa\u4e8e\u666e\u901a\u7528\u6237\u7684\u5174\u8da3\u5ea6\uff09,\n      \"news_value\": 1-10\u4e4b\u95f4\u7684\u6570\u5b57\uff08\u57fa\u4e8e\u8be5\u5185\u5bb9\u7684\u4fe1\u606f\u4ef7\u503c\uff09,\n      \"angle_suggestions\": [\"\u53ef\u884d\u751f\u9009\u9898\u89d2\u5ea61\", \"\u53ef\u884d\u751f\u9009\u9898\u89d2\u5ea62\"]\n    }\n  ]\n}\n\n\u8bf7\u786e\u4fdd\uff1a\n- \u5206\u6790\u7ef4\u5ea6\u5ba2\u89c2\u4e2d\u7acb\u3002\n- \u8f93\u51fa JSON \u4e25\u683c\u7b26\u5408\u683c\u5f0f\u8981\u6c42\u3002\n- \u6bcf\u6761\u5206\u6790\u5b8c\u6574\u3001\u65e0\u7f3a\u6f0f\u5b57\u6bb5\u3002\n- `original_url` \u5b57\u6bb5\u5fc5\u987b\u5b58\u5728\u5e76\u4e14\u4e0e\u8f93\u5165\u5185\u5bb9\u4e00\u81f4\u3002\n\n\u5173\u952e\u8bcd: {{ $('Analysis Parameters').item.json.keyword }}\n\n\u5f85\u5206\u6790\u5185\u5bb9\u6570\u7ec4:\n{{ JSON.stringify($json.data) }}",
        "batching": {},
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "9ca30e5e-aa64-4da4-9586-9720b23e2f65",
      "name": "Deep Analysis",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1180,
        400
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "606529dc-6f29-437d-be61-d74b987a37ad",
      "name": "Structure Analysis Result",
      "type": "n8n-nodes-base.code",
      "position": [
        -840,
        240
      ],
      "parameters": {
        "jsCode": "// \u65b0\u4ee3\u7801\uff1a\u589e\u52a0\u4e86\u6e05\u7406\u6b65\u9aa4\ntry {\n  // 1. \u4ece 'text' \u5b57\u6bb5\u83b7\u53d6AI\u8fd4\u56de\u7684\u539f\u59cb\u5b57\u7b26\u4e32\n  let contentString = $input.item.json.text;\n  \n  // 2. **\u65b0\u589e\u7684\u5173\u952e\u6b65\u9aa4\uff1a\u6e05\u7406\u5b57\u7b26\u4e32\uff0c\u53bb\u6389AI\u53ef\u80fd\u6dfb\u52a0\u7684markdown\u6807\u8bb0**\n  contentString = contentString.replace(/```json/g, '').replace(/```/g, '').trim();\n  \n  // 3. \u89e3\u6790\u8fd9\u4e2a\u5e72\u51c0\u7684\u5b57\u7b26\u4e32\n  const aiResults = JSON.parse(contentString);\n  \n  // 4. \u4ece\u4e0a\u6e38\u7684\"\u805a\u54081\"\u8282\u70b9\u83b7\u53d6\u539f\u59cb\u6570\u636e\u9879\n  const originalItems = $('Aggregate: Relevant Items').all();\n\n  // 5. \u68c0\u67e5AI\u8f93\u51fa\u662f\u5426\u662f\u6211\u4eec\u671f\u671b\u7684\u683c\u5f0f\n  if (!aiResults.analyses || !Array.isArray(aiResults.analyses)) {\n    throw new Error(\"AI output is not in the expected format: { \\\"analyses\\\": [...] }\");\n  }\n\n  // 6. \u5c06AI\u5206\u6790\u7ed3\u679c\u4e0e\u539f\u59cb\u6570\u636e\u8fdb\u884c\u5339\u914d\u548c\u5408\u5e76\n  const enrichedAnalyses = aiResults.analyses.map(analysis => {\n    const originalItem = originalItems.find(item => item.json.url === analysis.original_url);\n    \n    return {\n      json: {\n        ...analysis,\n        source_info: originalItem ? {\n          type: originalItem.json.source_type,\n          weight: originalItem.json.source_weight,\n          engagement_score: originalItem.json.engagement_score || 0\n        } : {\n          type: 'unknown',\n          url: analysis.original_url\n        },\n        analysis_timestamp: new Date().toISOString()\n      }\n    };\n  });\n  \n  // 7. \u8fd4\u56de\u5305\u542b\u6240\u6709\u5408\u5e76\u540e\u7ed3\u679c\u7684\u6570\u7ec4\n  return enrichedAnalyses;\n\n} catch (error) {\n  console.error('\u6210\u578b\u5206\u6790\u7ed3\u679c\u8282\u70b9\u9519\u8bef:', error);\n  return [{ \n    json: { \n      error: `\u6210\u578b\u5206\u6790\u7ed3\u679c\u5931\u8d25: ${error.message}`,\n      raw_content: $input.item.json.text || 'No raw content available'\n    } \n  }];\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "1223e62f-1e4a-48cc-8f65-6daa0baf5913",
      "name": "Aggregate: Deep Analysis Results",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -600,
        240
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "2b28a672-9be6-4400-9fc1-7ce546c64637",
      "name": "AI: Synthesize Final Report",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -440,
        240
      ],
      "parameters": {
        "text": "={{ `\u4f60\u662f\u4e00\u4f4d\u9876\u7ea7\u7684\u56fe\u4e66\u7f16\u8f91\u548c\u5185\u5bb9\u7b56\u7565\u5e08\u3002\u4f60\u73b0\u5728\u62e5\u6709 ${$json.length} \u7bc7\u5173\u4e8e\u201c${$('Analysis Parameters').item.json.keyword}\u201d\u7684\u9ad8\u8d28\u91cf\u6587\u7ae0\u7684\u7ed3\u6784\u5316\u5206\u6790\u6570\u636e\uff08JSON \u683c\u5f0f\uff09\u3002\n\n\u5206\u6790\u6570\u636e\u5982\u4e0b\uff1a\n${JSON.stringify($json)}\n\n\u8bf7\u57fa\u4e8e\u8fd9\u4e9b\u6570\u636e\uff0c\u5b8c\u6210\u4ee5\u4e0b\u4efb\u52a1\uff0c\u5e76\u76f4\u63a5\u8f93\u51fa\u4e00\u4efd\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u53d1\u9001\u90ae\u4ef6\u7684\u3001\u683c\u5f0f\u4f18\u7f8e\u7684**HTML\u4ee3\u7801**\u3002\u8bf7\u4f7f\u7528 <h1>, <h2>, <h3>\u4f5c\u4e3a\u5404\u7ea7\u6807\u9898\uff0c\u4f7f\u7528<ul>\u548c<li>\u521b\u5efa\u5217\u8868\uff0c\u4f7f\u7528<strong>\u6216<b> \u5bf9\u5173\u952e\u70b9\u8fdb\u884c\u52a0\u7c97\u3002\u8bf7\u786e\u4fdd\u4f60\u7684\u56de\u590d\u53ea\u5305\u542b\u7eaf\u7cb9\u7684HTML\u4ee3\u7801\uff0c\u4e0d\u8981\u6709\u4efb\u4f55\u989d\u5916\u7684\u89e3\u91ca\u6216Markdown\u6807\u8bb0\u3002\n1. **\u805a\u7c7b\u5206\u6790**\uff1a\u8bc6\u522b\u51fa 3-5 \u4e2a\u6700\u70ed\u95e8\u6216\u6700\u6838\u5fc3\u7684\u8ba8\u8bba\u7126\u70b9\u3002\n2. **\u8d8b\u52bf\u9884\u6d4b**\uff1a\u57fa\u4e8e\u7528\u6237\u60c5\u7eea\u548c\u8ba8\u8bba\u70ed\u5ea6\uff0c\u9884\u6d4b\u54ea\u4e2a\u7126\u70b9\u5728\u672a\u6765\u6700\u6709\u6f5c\u529b\u6210\u4e3a\u7206\u6b3e\u3002\n3. **\u9009\u9898\u751f\u6210**\uff1a\u4e3a\u6bcf\u4e2a\u6838\u5fc3\u7126\u70b9\uff0c\u751f\u6210 2 \u4e2a\u5177\u6709\u7206\u6b3e\u6f5c\u529b\u7684\u9009\u9898\u3002\u6bcf\u4e2a\u9009\u9898\u9700\u63d0\u4f9b\uff1a\n   - **\u6807\u9898 (Catchy Title)**\n   - **\u6838\u5fc3\u5927\u7eb2 (Outline)**\n   - **\u5173\u952e\u8bba\u70b9 (Key Arguments)**` }}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2
    },
    {
      "id": "cae79054-712a-40eb-8792-909fc287c246",
      "name": "Synthesis",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -440,
        420
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5d00f35a-4043-4d3f-a46f-058c0038ea48",
      "name": "Format Report Payloads",
      "type": "n8n-nodes-base.set",
      "position": [
        -120,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "27744290-a4c0-4afb-b948-bf19f3998b38",
              "name": "report_title",
              "type": "string",
              "value": "={{ '\u3010' + $('Analysis Parameters').item.json.keyword + '\u3011\u70ed\u70b9\u5206\u6790\u62a5\u544a (' + $('Analysis Parameters').item.json.search_date + ')' }}"
            },
            {
              "id": "9380ff58-c183-4f97-a588-35a7d06a8085",
              "name": "report_content",
              "type": "string",
              "value": "={{ $json.output }}"
            },
            {
              "id": "915a7cac-30dd-44fc-8b1b-4c5fbc29cbff",
              "name": "analysis_summary",
              "type": "string",
              "value": "={{ '\u672c\u6b21\u5206\u6790\u5171\u5408\u5e76\u4e86 ' + $('Merge: All Sources').all().length + ' \u6761\u539f\u59cb\u6570\u636e\uff0c\u7b5b\u9009\u540e\u6df1\u5ea6\u5206\u6790\u4e86 ' + $('Aggregate: Relevant Items').item.json.data.length + ' \u6761\u9ad8\u4ef7\u503c\u5185\u5bb9\u3002' }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8ec130d7-fcc8-4160-8c45-5bd976a4d978",
      "name": "Splicing final report",
      "type": "n8n-nodes-base.set",
      "position": [
        120,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "76202dc1-18f1-47eb-b533-14395a4c01ab",
              "name": "final_report_text",
              "type": "string",
              "value": "={{ $json.report_title + '\\n\\n**\u5206\u6790\u6982\u8981**:\\n' + $json.analysis_summary + '\\n\\n**\u8be6\u7ec6\u62a5\u544a**:\\n' + $json.report_content }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4f6d8ef7-c662-49c4-8e8a-2550366a0cd5",
      "name": "Send HTML Report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        320,
        0
      ],
      "parameters": {
        "message": "={{ $json.final_report_text }}",
        "options": {},
        "subject": "={{ $('Format Report Payloads').item.json.report_title }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "7a964d92-4caa-43b0-b14a-07ee5c902201",
      "name": "Send Feishu Card",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        140,
        240
      ],
      "parameters": {
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "msg_type",
              "value": "interactive"
            },
            {
              "name": "card",
              "value": "={{\n  {\n    \"config\": {\n      \"wide_screen_mode\": true\n    },\n    \"header\": {\n      \"template\": \"blue\",\n      \"title\": {\n        \"tag\": \"plain_text\",\n        \"content\": $json.report_title\n      }\n    },\n    \"elements\": [\n      {\n        \"tag\": \"div\",\n        \"text\": {\n          \"tag\": \"lark_md\",\n          \"content\": $json.analysis_summary\n        }\n      },\n      {\n        \"tag\": \"hr\"\n      },\n      {\n        \"tag\": \"note\",\n        \"elements\": [\n          {\n            \"tag\": \"plain_text\",\n            \"content\": \"\u2705 \u62a5\u544a\u5df2\u751f\u6210\uff0c\u5b8c\u6574\u7684\u8be6\u7ec6\u62a5\u544a\u5df2\u53d1\u9001\u81f3\u60a8\u7684Gmail\u90ae\u7bb1\u3002\"\n          }\n        ]\n      }\n    ]\n  }\n}}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1f3f314f-7f2d-42c8-96e0-1c7cd419e131",
      "name": "Archive Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        140,
        480
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b74fa61d-bbc3-4487-ac13-07606b8f92a3",
  "connections": {
    "Split Out": {
      "main": [
        [
          {
            "node": "Format YouTube Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Synthesis": {
      "ai_languageModel": [
        [
          {
            "node": "AI: Synthesize Final Report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Form Trigger": {
      "main": [
        [
          {
            "node": "Analysis Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Deep Analysis": {
      "ai_languageModel": [
        [
          {
            "node": "AI Deep Analysis",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "AI Pre-filtering",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Deep Analysis": {
      "main": [
        [
          {
            "node": "Structure Analysis Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Pre-filtering": {
      "main": [
        [
          {
            "node": "Parse AI Filter Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "X: Search Tweets": {
      "main": [
        [
          {
            "node": "Parse Twitter Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Reddit Data": {
      "main": [
        [
          {
            "node": "Merge: All Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge: All Sources": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Twitter Data": {
      "main": [
        [
          {
            "node": "Merge: All Sources",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Pre-filter Content": {
      "ai_languageModel": [
        [
          {
            "node": "AI Pre-filtering",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Analysis Parameters": {
      "main": [
        [
          {
            "node": "YouTube: Search Videos",
            "type": "main",
            "index": 0
          },
          {
            "node": "Reddit: Search Posts",
            "type": "main",
            "index": 0
          },
          {
            "node": "X: Search Tweets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format YouTube Data": {
      "main": [
        [
          {
            "node": "Merge: All Sources",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Reddit: Search Posts": {
      "main": [
        [
          {
            "node": "Format Reddit Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Splicing final report": {
      "main": [
        [
          {
            "node": "Send HTML Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Report Payloads": {
      "main": [
        [
          {
            "node": "Archive Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Splicing final report",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Feishu Card",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube: Search Videos": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF: Is Content Relevant": {
      "main": [
        [
          {
            "node": "Aggregate: Relevant Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Filter Errors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Filter Results": {
      "main": [
        [
          {
            "node": "IF: Is Content Relevant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate: Relevant Items": {
      "main": [
        [
          {
            "node": "AI Deep Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structure Analysis Result": {
      "main": [
        [
          {
            "node": "Aggregate: Deep Analysis Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI: Synthesize Final Report": {
      "main": [
        [
          {
            "node": "Format Report Payloads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate: Deep Analysis Results": {
      "main": [
        [
          {
            "node": "AI: Synthesize Final Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}