8
n8n 中文网amn8n.com

n8n自动化Twitter回复机器人工作流

高级

这是一个Miscellaneous, Multimodal AI领域的自动化工作流,包含 55 个节点。主要使用 If, Set, Code, Wait, Filter 等节点。 n8n自动化Twitter回复机器人工作流

前置要求
  • MongoDB 连接字符串
  • Twitter API 凭证
  • Telegram Bot Token
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "0035cdfd86961e28eba2da21f160cc35c18ba6c46babe9c0984e61e505c22293"
  },
  "nodes": [
    {
      "id": "ecc6cdb5-59f7-4bfc-83c6-40d87f48502e",
      "name": "当点击“执行工作流”时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        576,
        672
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "cf48f485-1f2b-45ca-951b-29b6fce58c78",
      "name": "如果",
      "type": "n8n-nodes-base.if",
      "position": [
        2768,
        576
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b436d79c-8106-4b3c-b422-3580962d8db5",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{$json}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ee3adcb5-d57b-46a2-a1b4-71ea08f44c1e",
      "name": "查找文档",
      "type": "n8n-nodes-base.mongoDb",
      "position": [
        1232,
        672
      ],
      "parameters": {
        "options": {
          "projection": "{\n    \"tweet_id\": 1,\n    \"_id\": 0\n  }"
        },
        "collection": "collection_name"
      },
      "credentials": {
        "mongoDb": {
          "id": "Rcu1LdHBG501jX7T",
          "name": "MongoDB account"
        }
      },
      "retryOnFail": false,
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "3730bc4b-bb19-4c26-9acc-28f07466283d",
      "name": "聚合1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1408,
        672
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "tweet_id"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1ffd6d06-62c9-4034-8bae-f9818436c256",
      "name": "由 Github 模型提供支持",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        576,
        832
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 20
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "edd31538-108b-48c8-9a6e-90f27fd247d2",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        736,
        928
      ],
      "parameters": {
        "jsCode": "// Force to Kyiv timezone\nconst now = new Date();\n\n// Format to Kyiv and extract hour\nconst formatter = new Intl.DateTimeFormat('en-GB', {\n  timeZone: 'Europe/Kyiv',\n  hour: 'numeric',\n  hour12: false\n});\n\nconst hour = parseInt(formatter.format(now), 10);\n\n// Active hours: 07:00–23:59\nif (hour < 7 || hour >= 24) {\n  return [{ json: { value: false } }];\n}\n\n// Probability (~28%)\nif (Math.random() < 1) {\n  return [{ json: { value: true } }];\n} else {\n  return [{ json: { value: false } }];\n}\n"
      },
      "typeVersion": 2
    },
    {
      "id": "ddfd32d3-e428-4cd9-bfe7-fbbc8110b89d",
      "name": "条件判断1",
      "type": "n8n-nodes-base.if",
      "position": [
        880,
        832
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7b85bd0c-3413-402f-8e6b-85235023fd46",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.value }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a49b0899-268c-4e4e-a676-b396d924b461",
      "name": "无操作,不执行任何操作",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1024,
        928
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "18784d65-ee93-4245-86e5-640f352a3ca0",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        3184,
        752
      ],
      "webhookId": "40c6d879-bac3-4c55-8fd7-3f5c78e3e4e7",
      "parameters": {
        "amount": 3
      },
      "typeVersion": 1.1
    },
    {
      "id": "36ec187d-64dc-437e-b3d1-884fbade96f1",
      "name": "如果5",
      "type": "n8n-nodes-base.if",
      "position": [
        2960,
        800
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8310c6d9-2fa2-492b-8d9a-472ba8139197",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $('Keyword/Community List').item.json.failure }}",
              "rightValue": 3
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6c0d2132-f538-4f9b-bf40-d717fc957fae",
      "name": "当由另一个工作流执行时",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        928,
        1632
      ],
      "parameters": {
        "inputSource": "passthrough"
      },
      "typeVersion": 1.1
    },
    {
      "id": "9b5f56a2-12fc-48e2-91b6-e5a2657c273f",
      "name": "条件判断2",
      "type": "n8n-nodes-base.if",
      "position": [
        2432,
        656
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b436d79c-8106-4b3c-b422-3580962d8db5",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{$json}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "2157f455-c935-40a5-85e4-02e99ce5c6ef",
      "name": "执行工作流",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        3328,
        368
      ],
      "parameters": {
        "options": {},
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "d2ab3cFnoWqP7E49",
          "cachedResultName": "Reply posting on X"
        },
        "workflowInputs": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9e4ea923-1d37-4680-b4e3-1954ac63f018",
      "name": "获取数据集项",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        2256,
        656
      ],
      "parameters": {
        "resource": "Datasets",
        "datasetId": "={{ $json.defaultDatasetId }}"
      },
      "credentials": {
        "apifyApi": {
          "id": "F4hBXSs6AN73jGd5",
          "name": "Apify account"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "67fe82eb-3108-430b-872f-b80e6bb8a9a8",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        336,
        816
      ],
      "parameters": {
        "color": 5,
        "width": 832,
        "height": 256,
        "content": "## 计划触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "e52c138a-46d9-4aee-97ac-1e941702645f",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1552,
        416
      ],
      "parameters": {
        "color": 6,
        "width": 192,
        "height": 432,
        "content": "## 👇要搜索的关键词/社区列表"
      },
      "typeVersion": 1
    },
    {
      "id": "8b97e7fb-9775-46c9-8c0e-7d28fd40b3d5",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2064,
        176
      ],
      "parameters": {
        "color": 4,
        "width": 352,
        "height": 848,
        "content": "## Apify X (Twitter) 抓取"
      },
      "typeVersion": 1
    },
    {
      "id": "9d638975-a8fc-4ad3-923f-d2e529965a42",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        416
      ],
      "parameters": {
        "color": 3,
        "width": 192,
        "height": 432,
        "content": "## Mongo DB"
      },
      "typeVersion": 1
    },
    {
      "id": "703597d7-9b77-4099-b9a0-577970d3c2f1",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2576,
        176
      ],
      "parameters": {
        "color": 2,
        "width": 166,
        "height": 848,
        "content": "## 筛选推文"
      },
      "typeVersion": 1
    },
    {
      "id": "435f2399-99d8-47ca-8972-418a07afee3d",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2864,
        672
      ],
      "parameters": {
        "color": 3,
        "width": 800,
        "height": 432,
        "content": "## 重试部分"
      },
      "typeVersion": 1
    },
    {
      "id": "485a4674-0edb-4199-b304-4a197c5010aa",
      "name": "基础LLM链",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1344,
        1632
      ],
      "parameters": {
        "text": "={{ $json.data }}",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "You are an X (formerly Twitter) reply specialist. Your job is to analyze a list of posts and generate intelligent, engaging replies that maximize engagement potential.\nInput Format\nYou will be given a JSON object containing the current time and a list of posts:\n{\n\"time_now\": \"YYYY-MM-DDTHH:MM:SS.sssZ\", // ISO 8601 format, e.g., \"2025-09-01T06:46:53.131+01:00\"\n\"data\": [\n{\n\"post_id\": \"1234567890\",\n\"screen_name\": \"example_user\",\n\"tweet_text\": \"Post content here\",\n\"created_at\": \"Wed Jun 18 17:15:39 +0000 2025\", // Twitter date format\n\"tweet_likes\": 500,\n\"tweet_retweets\": 100,\n\"tweet_replies\": 50,\n\"tweet_views\": \"9062\",\n\"user_followers_count\": 10000\n},\n// More posts...\n]\n}\nIf any fields are missing, use reasonable defaults (e.g., 0 for engagement metrics).\nYour Task\nGiven the input, you must:\nFilter out ineligible posts first (see below).\nSelect the post with the highest engagement potential from the remaining ones.\nGenerate an optimized reply for that post.\nOutput: Post ID + Generated Reply in JSON.\nPost Filtering (Before Scoring)\nIgnore and exclude posts that:\n- Are giveaways, contests, or promotions requiring specific actions like liking, reposting, or commenting a keyword/phrase to enter or receive something (e.g., \"Comment 'Vault' to win\" or \"Like + RT for free access\"). These are spammy and low-value for engagement.\n- Are purely promotional ads without substantive discussion (e.g., just product plugs with no insight or question).\n- Have no meaningful content for reply (e.g., empty or emoji-only posts).\nIf all posts are filtered out, output the \"No high-potential posts\" error.\nPost Selection Criteria\nPriority ranking (most important first):\nEngagement Potential - High like-to-follower ratio, growing momentum, active replies.\nUser Authority - High follower count, quality engagement.\nTiming Balance - Recent posts (relative to time_now, prefer <6 hours) or older with exceptional metrics.\nDecision Process\nScore each post after filtering:\nEngagement Velocity: (tweet_likes + tweet_retweets + tweet_replies * 2) / max(1, hours_since_posted), where hours_since_posted is calculated as the difference between time_now and created_at in hours.\nAuthority: log10(user_followers_count) * (total_engagement / user_followers_count), where total_engagement = tweet_likes + tweet_retweets + tweet_replies.\nTiming: +3 if hours_since_posted < 6; +2 if velocity > 10/hour; +1 if hours_since_posted < 24.\nOpportunity: 1-5 based on value-add potential (e.g., 5 for questions or posts inviting discussion, 4 for controversial or relatable takes that allow witty twists, 1 for closed statements).\nTotal: (Velocity * 0.4) + (Authority * 0.3) + (Timing * 0.2) + (Opportunity * 0.1)\nSelect the highest-scoring post (>3.0 threshold, else error).\nCraft reply.\nReply Style Guide\nPrioritize a human, casual voice: Sarcastic, witty, dry humor, or self-deprecating where it fits—avoid generic positivity or spam-like enthusiasm. Mix styles based on the post, but lean toward edge for better engagement.\nChoose/mix the most effective:\nWitty/Sarcastic - For controversial or bold statements. Example: \"Subscriptions cost more than owning stuff outright. Wild plot twist. Who saw that coming?\"\nHumorous/Exaggerated - For relatable or fun posts. Example: \"$350M for no Mac? I’d take the cash and type on a banana if I had to.\"\nInformational/Educational - For advice-seeking posts. Example: \"SaaS isn’t just revenue—it’s low inventory risk. But good luck explaining that to your accountant.\"\nThought-Provoking - For shallow observations. Example: \"Subscriptions swap financial anxiety for predictable costs. Until the price hikes hit, anyway.\"\nEmpathetic/Supportive - For emotional content. Example: \"Been there—tough spot. X worked for me, but honestly, it was a grind.\"\nReply Quality Standards\nIntelligent and nuanced.\nAuthentic human voice: Conversational, natural, with a touch of personality—like sarcasm, irony, or understatement. Avoid sounding like a bot or marketer (no exclamation overload, no forced hype).\nAdd meaningful value (insight, humor, or perspective) with a unique twist that surprises or amuses.\n<100 characters. The shorter, the better!!!!\nStandalone replies in 95% of cases: Deliver a complete, engaging point without expecting a response. Avoid questions unless strictly necessary.\nQuestions only in 5% of cases: Include a question only if the original post is a direct question (e.g., “What’s your top red flag?”) or explicitly invites discussion (e.g., “Can you do this for 30 days?”), and the question adds unique, specific value likely to spark meaningful replies. Do not mirror the original question or add redundant questions. For the most part, avoid questions in the replies!!!!\nYou can use 1 emoji, but try to avoid it, only use it when necessary.\nAvoid hashtags.\nThink step-by-step: Analyze the post’s intent and tone. Select style that matches but adds edge (e.g., sarcasm for boastful posts, humor for absurd ones). Craft reply as a punchy, standalone zinger. Verify it's natural, question-free unless essential, and feels like a clever friend's quip—not generic praise.\nOutput Format\nValid JSON only:\n{\n\"selected_tweet_id\": \"id_here\",\n\"screen_name\": \"name_here\",\n\"reply\": \"reply_here\"\n}\nEdge Cases\nEmpty data list: {\"error\": \"No posts provided.\"}\nNo post scores >3.0 or all filtered out: {\"error\": \"No high-potential posts.\"}\nRemember: Focus on one brilliant, value-adding reply that feels natural, standalone, and conversational with a human edge."
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "3e265172-5389-4249-91f6-c82fde2e5557",
      "name": "OpenRouter聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        1328,
        1824
      ],
      "parameters": {
        "model": "x-ai/grok-3",
        "options": {
          "responseFormat": "json_object"
        }
      },
      "credentials": {
        "openRouterApi": {
          "id": "W4hVzYL6LmhM62Z1",
          "name": "OpenRouter account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d666ab13-f11d-4eba-bd3f-f92ef54fa085",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1440,
        1808
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{ \n  \"selected_tweet_id\": \"tweet_id_here\",\n  \"screen_name\": \"author_screen_name\",\n  \"reply\": \"your_generated_reply_here\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "0b0f7f12-2b65-4df3-a292-a05f25477960",
      "name": "创建推文",
      "type": "n8n-nodes-base.twitter",
      "onError": "continueErrorOutput",
      "position": [
        1696,
        1632
      ],
      "parameters": {
        "text": "={{ $json.output.reply }}",
        "additionalFields": {
          "inReplyToStatusId": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $json.output.selected_tweet_id }}"
          }
        }
      },
      "credentials": {
        "twitterOAuth2Api": {
          "id": "OLmaX9DbPcvIg0qZ",
          "name": "X account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "e27abf81-aa67-4f21-aafd-ec1aa4a62f80",
      "name": "OpenRouter聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        1424,
        1936
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "id": "W4hVzYL6LmhM62Z1",
          "name": "OpenRouter account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b34cf3c1-5998-4e1b-a7d6-941d2d64fefa",
      "name": "发送成功回复",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1920,
        1536
      ],
      "webhookId": "4511ad2c-7344-4978-a5eb-a145d66c458c",
      "parameters": {
        "text": "=🟢 Posted a reply successfully\n\nhttps://x.com/{{ $('Basic LLM Chain').item.json.output.screen_name }}/status/{{ $('Basic LLM Chain').item.json.output.selected_tweet_id }}\n\n<code>{{ $('Basic LLM Chain').item.json.output.reply }}</code>\n",
        "chatId": "11111111111111",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false,
          "disable_notification": true
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "V40eZxEGtHH2pkXZ",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "bdd0ff4f-733f-4ca8-8f64-64dd2c8b1ca1",
      "name": "发送失败回复",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1920,
        1744
      ],
      "webhookId": "4511ad2c-7344-4978-a5eb-a145d66c458c",
      "parameters": {
        "text": "=🔴 Posted a reply unsuccessfully due to X (Twitter) API limitation, (17 posts a day for free tier)\n\nhttps://x.com/{{ $('Basic LLM Chain').item.json.output.screen_name }}/status/{{ $('Basic LLM Chain').item.json.output.selected_tweet_id }}\n\n<code>{{ $('Basic LLM Chain').item.json.output.reply }}</code>\n",
        "chatId": "11111111111111",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false,
          "disable_notification": true
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "V40eZxEGtHH2pkXZ",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0465ce22-961e-485c-87fc-bfaf414fe160",
      "name": "解析回复",
      "type": "n8n-nodes-base.set",
      "position": [
        2144,
        1632
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0c5f816e-b877-4fd6-8503-bdef0343079d",
              "name": "tweet_id",
              "type": "string",
              "value": "={{ $('Basic LLM Chain').item.json.output.selected_tweet_id }}"
            },
            {
              "id": "94ae6af6-9e8c-44e1-b53e-eea2a133cc8e",
              "name": "screen_name",
              "type": "string",
              "value": "={{ $('Basic LLM Chain').item.json.output.screen_name }}"
            },
            {
              "id": "6da73fce-869a-4c13-b3c3-3602d7ba55c9",
              "name": "reply",
              "type": "string",
              "value": "={{ $('Basic LLM Chain').item.json.output.reply }}"
            },
            {
              "id": "11bd3d58-f53d-410c-bfe0-b1259d41a1fb",
              "name": "tweet_url",
              "type": "string",
              "value": "=https://x.com/{{ $('Basic LLM Chain').item.json.output.screen_name }}/status/{{ $('Basic LLM Chain').item.json.output.selected_tweet_id }}"
            },
            {
              "id": "c5241ce8-609b-46f1-9360-cbf5d779953b",
              "name": "date",
              "type": "string",
              "value": "={{ $now.format('HH:mm; dd.MM.yyyy')}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "45246617-5c18-467b-a4d2-5416fd822ae0",
      "name": "插入文档",
      "type": "n8n-nodes-base.mongoDb",
      "position": [
        2320,
        1632
      ],
      "parameters": {
        "fields": "=tweet_id, screen_name, reply, tweet_url, date",
        "options": {
          "dateFields": ""
        },
        "operation": "insert",
        "collection": "collection_name"
      },
      "credentials": {
        "mongoDb": {
          "id": "Rcu1LdHBG501jX7T",
          "name": "MongoDB account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "66b0ce1c-eb96-4034-a184-66ff71e6a823",
      "name": "修改推文数据",
      "type": "n8n-nodes-base.set",
      "position": [
        1168,
        1632
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "310097a1-1356-4c9c-b5d5-1c4e944aba61",
              "name": "time_now",
              "type": "string",
              "value": "={{ $now }}"
            },
            {
              "id": "2d7f2ada-72ef-4bad-936d-5eeb90bd4e38",
              "name": "data",
              "type": "array",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2f0a83c2-67da-47c5-92f4-1785963783ea",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        592,
        528
      ],
      "webhookId": "e2353116-ed7b-4d40-a10a-a889f507052d",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "V40eZxEGtHH2pkXZ",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1154db08-9329-4c58-bf8f-2713ac8b6d49",
      "name": "如果3",
      "type": "n8n-nodes-base.if",
      "position": [
        816,
        528
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d837eb25-886e-450c-9145-7a1e483d630e",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.message.text }}",
              "rightValue": "/reply"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "63dde44f-4f97-463b-9a84-799b7c34be97",
      "name": "无操作,不执行任何操作1",
      "type": "n8n-nodes-base.noOp",
      "position": [
        960,
        352
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "18537add-f26a-464b-b887-72c002908422",
      "name": "### 需要帮助?",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        352
      ],
      "parameters": {
        "color": 4,
        "width": 576,
        "height": 336,
        "content": "## Telegram 触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "1251926c-16ad-42e7-a998-ec2744ca0449",
      "name": "## 试试看!",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        1424
      ],
      "parameters": {
        "color": 3,
        "width": 192,
        "height": 384,
        "content": "## 添加当前日期"
      },
      "typeVersion": 1
    },
    {
      "id": "feaa97ff-885d-4e8e-8d45-882981153b36",
      "name": "GET 模型",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        1424
      ],
      "parameters": {
        "width": 368,
        "height": 656,
        "content": "## LLM 推文处理"
      },
      "typeVersion": 1
    },
    {
      "id": "f14dfad5-89e9-41a5-9f26-72b6eb933160",
      "name": "## 1. 创建新的自定义 OpenAI 凭据",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1840,
        1424
      ],
      "parameters": {
        "color": 6,
        "height": 560,
        "content": "## 向 Telegram 提供状态消息"
      },
      "typeVersion": 1
    },
    {
      "id": "857e08df-a675-4274-a7e6-38552f5df5f6",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        1424
      ],
      "parameters": {
        "color": 4,
        "width": 150,
        "height": 560,
        "content": "## 回复帖子"
      },
      "typeVersion": 1
    },
    {
      "id": "606e31d4-5d39-4018-ba0f-39fae1095fd6",
      "name": "便签 11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2080,
        1424
      ],
      "parameters": {
        "width": 480,
        "height": 384,
        "content": "## 将回复保存到数据库以避免重复"
      },
      "typeVersion": 1
    },
    {
      "id": "7ddb2983-ac6e-408b-8296-d3eca2d65ba6",
      "name": "便利贴13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2416,
        416
      ],
      "parameters": {
        "color": 3,
        "width": 150,
        "height": 432,
        "content": "## 检查是否有结果"
      },
      "typeVersion": 1
    },
    {
      "id": "8c505aee-c842-4849-b231-05f1f8204a0c",
      "name": "便签14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2912,
        288
      ],
      "parameters": {
        "color": 5,
        "width": 608,
        "height": 256,
        "content": "## 将推文数据发送到子工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "26ab8845-7d5f-4431-9ac9-a28f0c4d1039",
      "name": "便签16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        0
      ],
      "parameters": {
        "width": 3936,
        "height": 1216,
        "content": "# 👇👇👇"
      },
      "typeVersion": 1
    },
    {
      "id": "d891c53f-54d9-49f2-bd30-8fc61f8f95b5",
      "name": "便签 12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        1280
      ],
      "parameters": {
        "color": 5,
        "width": 1872,
        "height": 912,
        "content": "# 执行工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "07aa12a2-1ccc-4f7e-acf2-e824a446a1fc",
      "name": "获取推文数据",
      "type": "n8n-nodes-base.set",
      "position": [
        2960,
        368
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a2b5edfc-0e25-4492-bc6f-69e12e42cddb",
              "name": "id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "2d24a106-0404-4dc3-977e-97281311af0d",
              "name": "screen_name",
              "type": "string",
              "value": "={{ $json.author.userName }}"
            },
            {
              "id": "0e403383-bddf-4739-bc6a-9cf5cf299236",
              "name": "user_followers_count",
              "type": "number",
              "value": "={{ $json.author.followers }}"
            },
            {
              "id": "bfe1a4a3-5b37-4bc0-a174-2262393c50ba",
              "name": "created_at",
              "type": "string",
              "value": "={{ $json.createdAt }}"
            },
            {
              "id": "6434ee6b-7e9b-4a82-b2a0-a504e61767ae",
              "name": "tweet_text",
              "type": "string",
              "value": "={{ $json.text.replace(/\\s*https?:\\/\\/\\S+$/, '') }}\n"
            },
            {
              "id": "2e43111a-7963-4f20-b6e1-2d0986ac2551",
              "name": "tweet_likes",
              "type": "number",
              "value": "={{ $json.likeCount }}"
            },
            {
              "id": "1b856625-d214-4700-b37b-8d56649af3b9",
              "name": "tweet_retweets",
              "type": "number",
              "value": "={{ $json.retweetCount }}"
            },
            {
              "id": "afb5df07-042f-4b51-880c-201061cae0be",
              "name": "tweet_views",
              "type": "string",
              "value": "={{ $json.viewCount }}"
            },
            {
              "id": "490aa9a3-65ff-4f33-bfe7-97c8bf6b8436",
              "name": "tweet_replies",
              "type": "number",
              "value": "={{ $json.replyCount }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f339aa30-a798-4fb1-8d26-d7c79fece3b7",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        3136,
        368
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "d6bfb139-0065-48cd-8075-f1d9a205c6e2",
      "name": "社区筛选器",
      "type": "n8n-nodes-base.filter",
      "position": [
        2608,
        592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "abda82ba-a65f-4af9-b5dc-c91a27d7c993",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.text.length }}",
              "rightValue": 60
            },
            {
              "id": "e269fa10-d9e1-4398-95a9-18f393408bad",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.author.followers }}",
              "rightValue": 100
            },
            {
              "id": "f2d57a64-ad49-453b-ad04-8d4b7d03c5be",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ !$('Aggregate1').item.json.tweet_id.includes($json.id) }}",
              "rightValue": "="
            },
            {
              "id": "bb6e7ed7-c9e5-4454-8f7c-6fea447a9f9b",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.replyCount }}",
              "rightValue": 3
            },
            {
              "id": "6681f28a-8904-4869-84e7-5b479b092ec2",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.likeCount }}",
              "rightValue": 10
            },
            {
              "id": "38e16cbc-2ec1-4087-95a3-af0ccee0a005",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.lang }}",
              "rightValue": "en"
            },
            {
              "id": "70719339-978b-472b-b3fc-98620fd42c28",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.viewCount }}",
              "rightValue": 100
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "0600faa2-8e57-4461-b389-47da9a977ae0",
      "name": "社区搜索执行器",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        2112,
        512
      ],
      "parameters": {
        "actorId": {
          "__rl": true,
          "mode": "id",
          "value": "upbwCMnBATzmzcaNu"
        },
        "timeout": {},
        "customBody": "={\n    \"communityIds\": [\n        \"{{ $json.randomized_item }}\"\n    ],\n    \"numberOfTweets\": 40\n}"
      },
      "credentials": {
        "apifyApi": {
          "id": "iORjQCzUmst61lYC",
          "name": "Apify Canopy"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9a6fecf4-16a9-42f1-9c04-a21e911e27f0",
      "name": "关键词/社区列表",
      "type": "n8n-nodes-base.set",
      "position": [
        1600,
        672
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={\n  \"keyword_community_list\": [\n    \"BuildInPublic\",\n    \"Automation\",\n    \"n8n\",\n    \"cats OR dogs\",\n    \"AI\",\n    \"#devtools\",\n    \"#Networking OR #TechCommunity\",\n    \"1699807431709041070\",\n    \"1472105760389668865\",\n    \"1699807431709041070\",\n    \"1808786876314026197\",\n    \"1488952693443997701\"\n  ],\n  \"failure\": {{ $runIndex === 0 ? 0 : ($json.failure || 0) }}\n}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "8f1d16fe-2d34-4bd5-b674-6745c4c3b4f5",
      "name": "随机化的社区、关键词",
      "type": "n8n-nodes-base.set",
      "position": [
        1792,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1c216d43-8f92-4a73-bd6e-b85368fb1b84",
              "name": "randomized_item",
              "type": "string",
              "value": "={{ $json.keyword_community_list.randomItem() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c00ce586-7400-4130-9259-38bd88505230",
      "name": "如果4",
      "type": "n8n-nodes-base.if",
      "position": [
        1952,
        672
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6f1f27b9-5a72-42b3-bee1-e23e30c648f6",
              "operator": {
                "type": "string",
                "operation": "regex"
              },
              "leftValue": "={{ $json.randomized_item }}",
              "rightValue": "\\d{19}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "cbfaea8c-a107-492b-873f-4f829532c091",
      "name": "便签15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        416
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 432,
        "content": "## 获取随机项,路由到正确的 API"
      },
      "typeVersion": 1
    },
    {
      "id": "4baacafe-5a2b-45b6-83fc-6ada987c2466",
      "name": "便签17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        416
      ],
      "parameters": {
        "color": 2,
        "width": 166,
        "height": 432,
        "content": "## 将已发布的回复聚合到统一列表"
      },
      "typeVersion": 1
    },
    {
      "id": "62c7cd3b-8ada-472f-b77e-b3c99a39927c",
      "name": "发送抓取失败消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3184,
        896
      ],
      "webhookId": "4511ad2c-7344-4978-a5eb-a145d66c458c",
      "parameters": {
        "text": "=🔴 Parsed search unsuccessfully. Failed after 4 retries\n\nclick /reply to try again\n",
        "chatId": "11111111111111",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false,
          "disable_notification": true
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "V40eZxEGtHH2pkXZ",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8fc09efc-025f-4911-8bef-64b9260800fc",
      "name": "增加失败计数器",
      "type": "n8n-nodes-base.set",
      "position": [
        3456,
        912
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "increment-failure-counter",
              "name": "failure",
              "type": "number",
              "value": "={{ $('Keyword/Community List').item.json.failure +1 }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e92c86cf-a55f-426b-a64f-befd8ac0fb91",
      "name": "搜索关键词执行器",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        2112,
        800
      ],
      "parameters": {
        "actorId": {
          "__rl": true,
          "mode": "id",
          "value": "0oVSlMlAX47R2EyoP"
        },
        "customBody": "={\n    \"contentLanguage\": \"en\",\n    \"contentQuestionMarks\": false,\n    \"engagementHasEngagement\": false,\n    \"engagementMinLikes\": 10,\n    \"engagementMinReplies\": 5,\n    \"engagementMinRetweets\": 0,\n    \"mediaHasHashtags\": false,\n    \"mediaHasLinks\": false,\n    \"mediaHasMentions\": false,\n    \"mediaNewsOnly\": false,\n    \"mediaSafeContentOnly\": false,\n    \"numberOfTweets\": 20,\n    \"query\": \"{{ $json.randomized_item }}\",\n    \"timeWithinTime\": \"2d\",\n    \"tweetTypes\": [\n        \"original\"\n    ],\n    \"usersBlueVerifiedOnly\": true,\n    \"usersVerifiedOnly\": false\n}"
      },
      "credentials": {
        "apifyApi": {
          "id": "iORjQCzUmst61lYC",
          "name": "Apify Canopy"
        }
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Get tweet data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Find documents",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [
          {
            "node": "Community filter",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If3": {
      "main": [
        [
          {
            "node": "Find documents",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If4": {
      "main": [
        [
          {
            "node": "Community search actor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Search keyword actor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If5": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a scraping failure message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Increment Failure Counter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Execute Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate1": {
      "main": [
        [
          {
            "node": "Keyword/Community List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "parse reply": {
      "main": [
        [
          {
            "node": "Insert documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Tweet": {
      "main": [
        [
          {
            "node": "Send a success reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a failed reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find documents": {
      "main": [
        [
          {
            "node": "Aggregate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get tweet data": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Create Tweet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Community filter": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "If3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get dataset items": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "modify tweet data": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a failed reply": {
      "main": [
        [
          {
            "node": "parse reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search keyword actor": {
      "main": [
        [
          {
            "node": "Get dataset items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a success reply": {
      "main": [
        [
          {
            "node": "parse reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Community search actor": {
      "main": [
        [
          {
            "node": "Get dataset items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keyword/Community List": {
      "main": [
        [
          {
            "node": "Randomized community, keyword",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Increment Failure Counter": {
      "main": [
        [
          {
            "node": "Keyword/Community List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Randomized community, keyword": {
      "main": [
        [
          {
            "node": "If4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "modify tweet data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Find documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 杂项, 多模态 AI

需要付费吗?

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

工作流信息
难度等级
高级
节点数量55
分类2
节点类型20
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者

Playing around. Contact me at: https://t.me/demploy https://x.com/MaxDziura

外部链接
在 n8n.io 查看

分享此工作流