8
n8n 中文网amn8n.com

Twitter自动化

高级

这是一个Miscellaneous, Multimodal AI领域的自动化工作流,包含 20 个节点。主要使用 If, Set, Code, Twitter, Agent 等节点。 使用Gemini AI和Google Sheets的自动化内容与推广推文调度器

前置要求
  • Twitter API 凭证
  • Google Sheets API 凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "TdUwxmTIJnTwQhJe",
  "meta": {
    "instanceId": "52254486b159b349334953c1738da94e90477c7604aa8db2062d11afc0120739",
    "templateCredsSetupCompleted": true
  },
  "name": "Twitter自动化",
  "tags": [
    {
      "id": "GcbJtfnHd72wKEMY",
      "name": "admin",
      "createdAt": "2025-05-06T11:04:59.376Z",
      "updatedAt": "2025-05-06T11:04:59.376Z"
    }
  ],
  "nodes": [
    {
      "id": "d09f13f7-1b8a-4b31-946a-fc100cfae834",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        48,
        160
      ],
      "parameters": {
        "jsCode": "// Templates for normal tweets\nconst templates = [\n  \"transformation\",\n  \"hook-list-takeaway\",\n  \"interesting fact\",\n  \"Metaphor\",\n  \"contrast\",\n  \"motivation\",\n  \"triad\",\n  \"comparison\",\n  \"80/20 rule\",\n  \"callout\"\n];\n\n// Track last output to avoid duplicates\nif (!global.lastTweet) {\n  global.lastTweet = null;\n}\n\nfunction getRandom(arr) {\n  return arr[Math.floor(Math.random() * arr.length)];\n}\n\nlet tweet;\nlet ads = false\n\ndo {\n  if (Math.random() < 0.3) {\n    // 20% chance → promo\n    tweet = \"advertise\";\n    ads = true;\n  } else {\n    // 80% chance → template\n    tweet = getRandom(templates);\n  }\n} while (tweet === global.lastTweet); // prevent repeats\n\n// Save for next run\nglobal.lastTweet = tweet;\n\nreturn [{ json: { tweet, ads} }];\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "bc60c259-c76c-4d73-909b-efb38fa3105c",
      "name": "推文生成器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        624,
        608
      ],
      "parameters": {
        "text": "={{ $json.tweet }}",
        "options": {
          "systemMessage": "=You are a ghostwriter who creates short, raw, non-repetitive tweets.  \nI will give you a \"content type\" (template).  \nYour job: generate a tweet in that style.  \n\nRules:  \n- Generate a tweet based on the given template.\n- Read all past tweets from the database using the Read Database tool (past_tweets column).\n- If the exact tweet (or a close duplicate) appears in read database tool in column past_tweets , regenerate and repeat this check until the tweet is unique.\n- Once a unique tweet is generated, append it to the past_tweets column in the log database tool for future reference.\n- Tweets must be punchy, edgy, and written in modern Twitter style.  \n- Keep it concise (2–4 lines). No hashtags. Minimal emojis (🔥 👑 only if it fits)  \n-Make tweets in the format of example tweets  for each template\n-- Use a separate line for each short phrase or thought.\n\nAvailable templates & patterns:  \n\n1. **Transformation** → Fail/fail/fail → sudden win.  \n   Example:  \n   2021: Skinny  \n   2022: Skinny  \n   2023: Skinny  \n   2024: Skinny  \n   2025: Unrecognizable  \n\n2. **Hook–List–Takeaway** → Bold statement → short list → lesson.  \n   Example:  \n   Don’t chase girls  \n   Chase:  \n   • skills  \n   • fitness  \n   • money  \n   Women chase you after  \n\n3. **Interesting Fact** → Myth-bust → stat → reassurance.  \n   Example:  \n   Success isn’t early  \n   The average founder is 45  \n   You’re not late  \n   You’re loading  \n\n4. **Metaphor** → Proverb → apply to daily grind.  \n   Example:  \n   Chess isn’t won in one move  \n   It’s a hundred small ones  \n   Your life is the same  \n   Win by inches  \n\n5. **Contrast** → Dumb vs smart behavior.  \n   Example:  \n   Losers scroll TikTok for fun  \n   Winners use it to sell  \n\n6. **Motivation** → Reject convention → replace with work.  \n   Example:  \n   Sleep in on Sunday?  \n   Someone else is training  \n   While you’re dreaming  \n   They’re eating your future  \n\n7. **Triad** → 3 parallel actions = new identity.  \n   Example:  \n   Build the body  \n   Build the mind  \n   Build the bank account  \n\n8. **Comparison** → System vs self-action.  \n   Example:  \n   Netflix kills time  \n   Books create empires  \n\n9. **80/20 Rule** → Split effort/discipline.  \n   Example:  \n   20% of gym time builds your body  \n   80% is in the kitchen  \n\n10. **Callout** → Excuse → “wrong” → harsh truth.  \n   Example:  \n   “I can’t focus”  \n   Wrong  \n   You just can’t put down your phone  \n\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "551ff01d-1879-4070-a2a7-c091d0dc2023",
      "name": "读取数据库",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        576,
        800
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "=",
              "lookupColumn": "Date"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit#gid=0",
          "cachedResultName": "posts"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit?usp=drivesdk",
          "cachedResultName": "Twitter Automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "dNmdYyKDCj9rTeSw",
          "name": "Gsheet"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "c7bdd791-9b10-46b4-b8d4-8f34e976b2f4",
      "name": "记录数据库",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        720,
        800
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{$now.format('dd/MM/yyyy')}}",
            "PAST TWEETS": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('PAST_TWEETS', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "PAST TWEETS",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "PAST TWEETS",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "PAST TWEETS"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit#gid=0",
          "cachedResultName": "posts"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit?usp=drivesdk",
          "cachedResultName": "Twitter Automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "dNmdYyKDCj9rTeSw",
          "name": "Gsheet"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "46b83045-f664-4220-975e-da419a34bc4f",
      "name": "如果",
      "type": "n8n-nodes-base.if",
      "position": [
        288,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "ac140c17-1fd3-4f59-a448-acdc6c868eb7",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.ads }}",
              "rightValue": "n8n Discord Trigger Bot"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "bf677bd2-4ada-4c42-9827-6364d6b162a4",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        576,
        288
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "VogGayxALH0ssmBl",
          "name": "Gemini account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "63b155b4-c6a2-45cd-9a77-f9f6e4b3aba5",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -400,
        160
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 2
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "77dd71dc-3990-4543-8971-10b47089f632",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        -80
      ],
      "parameters": {
        "width": 432,
        "height": 400,
        "content": "## 触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "559d7e1f-116e-4a03-ab94-d0b42ad08e18",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        64
      ],
      "parameters": {
        "color": 5,
        "width": 150,
        "height": 224,
        "content": "**在上午8点、中午12点、下午6点触发**"
      },
      "typeVersion": 1
    },
    {
      "id": "1c5f9e39-8e99-48a2-9ce4-cebfb047cab3",
      "name": "时间随机化器",
      "type": "n8n-nodes-base.code",
      "disabled": true,
      "position": [
        -176,
        160
      ],
      "parameters": {
        "jsCode": "// random delay in minutes\nconst delayMinutes = Math.floor(Math.random() * 120); // 0–120 for 2-hour window\nconst delayMilliseconds = delayMinutes * 60 * 1000;\n\nreturn new Promise(resolve => setTimeout(() => resolve([{ json: {} }]), delayMilliseconds ));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "606de6ed-0e95-430e-9452-2941ab0eb28f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -16
      ],
      "parameters": {
        "color": 5,
        "width": 208,
        "height": 304,
        "content": "**生成一个0到120之间的随机数,并等待那么多分钟,允许推文在全天以伪随机时间发布,而不是固定的预定时间**"
      },
      "typeVersion": 1
    },
    {
      "id": "31fdce97-7c97-4f46-8c9b-0175e548e7b3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -80
      ],
      "parameters": {
        "color": 4,
        "width": 192,
        "height": 400,
        "content": "**随机选择10个内容策略模板之一或4个促销广告之一,有80%的几率选择模板,20%的几率选择促销**"
      },
      "typeVersion": 1
    },
    {
      "id": "226f79d0-3998-4f15-b01a-a092cbd3648e",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -80
      ],
      "parameters": {
        "color": 6,
        "height": 400,
        "content": "**检查随机选择的项目是内容策略模板还是促销广告,然后相应地路由它:模板转到主推文生成器,促销转到促销推文生成器**"
      },
      "typeVersion": 1
    },
    {
      "id": "895c1a3b-39a0-4cfb-abbf-168e2d4675a4",
      "name": "促销推文生成器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        608,
        48
      ],
      "parameters": {
        "text": "=You must get the list of contents from google sheets and choose one that has not recently been posted",
        "options": {
          "systemMessage": "=You are a professional tweet generator. Your job is to create a punchy, short, unique tweet for Twitter based on the ad object provided as input.\n\nInstructions for generating the tweet:\n1. Use only one row from the google sheet to generate a tweet \n2. Make the tweet punchy, short, Twitter-style, unique like a conversation piece\n3. Check the tweet database to avoid repeating past tweets.  \n4. Log the final tweet and update the column \"last_posted\"\n5. Output **only one valid tweet** in plain text.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "86ecdfdf-aa00-4e31-98a4-5a7103d344e8",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        -96
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 624,
        "content": "## **根据提供的广告模板生成促销推文,确保其遵循广告的结构和消息传递。**"
      },
      "typeVersion": 1
    },
    {
      "id": "75919d47-faff-492c-9b04-42078b327e0c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        432
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 512,
        "content": "## **生成独特的推文,同时检查数据库以避免重复,并将新创建的推文记录到数据库中,以供将来参考和跟踪。**"
      },
      "typeVersion": 1
    },
    {
      "id": "c8dfaf2b-7d40-4dc1-9f8a-fc178a860817",
      "name": "推文",
      "type": "n8n-nodes-base.set",
      "position": [
        1120,
        304
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f1646841-fab2-4f7e-88e0-3107c176e4fa",
              "name": "Tweet",
              "type": "string",
              "value": "={{ $json.output }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "933f2594-253d-41cc-827d-37ea284597d4",
      "name": "创建推文",
      "type": "n8n-nodes-base.twitter",
      "position": [
        1344,
        304
      ],
      "parameters": {
        "text": "={{ $json.Tweet }}",
        "additionalFields": {}
      },
      "credentials": {
        "twitterOAuth2Api": {
          "id": "Ig60ncJDzlhLU0Ap",
          "name": "X account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "b11f3dab-6b58-41a3-aa85-d1574cb5bdb9",
      "name": "读取数据库1",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        720,
        288
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 814034323,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit#gid=814034323",
          "cachedResultName": "promo"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit?usp=drivesdk",
          "cachedResultName": "Twitter Automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "dNmdYyKDCj9rTeSw",
          "name": "Gsheet"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "15c082ad-6d6f-4014-890b-3001dfaa9342",
      "name": "记录数据库1",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        848,
        288
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ $fromAI('name', 'name of the row', 'string') }}",
            "last_posted": "={{$now.format('dd/MM/yyyy')}}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "url",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "category",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "goal",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "goal",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "price_points",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "price_points",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "call_to_action",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "call_to_action",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "key_proof",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "key_proof",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_posted",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "last_posted",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 814034323,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit#gid=814034323",
          "cachedResultName": "promo"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DbPO7U68-YlOHhb8fIlGu2ImD_N-cm0E-8pwc7qnAo4/edit?usp=drivesdk",
          "cachedResultName": "Twitter Automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "dNmdYyKDCj9rTeSw",
          "name": "Gsheet"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "34a4b44e-e2e1-41ca-8a2b-922144bde668",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Promotional Tweet maker",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Tweet maker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tweet": {
      "main": [
        [
          {
            "node": "Creates the tweet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tweet maker": {
      "main": [
        [
          {
            "node": "Tweet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "log database": {
      "ai_tool": [
        [
          {
            "node": "Tweet maker",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "log database1": {
      "ai_tool": [
        [
          {
            "node": "Promotional Tweet maker",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "read database": {
      "ai_tool": [
        [
          {
            "node": "Tweet maker",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "read database1": {
      "ai_tool": [
        [
          {
            "node": "Promotional Tweet maker",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Time randomizer": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Time randomizer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Promotional Tweet maker": {
      "main": [
        [
          {
            "node": "Tweet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Tweet maker",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Promotional Tweet maker",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 杂项, 多模态 AI

需要付费吗?

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

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

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

作者
Jay Emp0

Jay Emp0

@jay-emp0

AI and Automation developer. Im implementing n8n and ai tools to automate marketing and sales in companies

外部链接
在 n8n.io 查看

分享此工作流