AI 驱动的 Twitter 自动化与内容生成和互动
高级
这是一个Social Media, Multimodal AI领域的自动化工作流,包含 24 个节点。主要使用 Set, Code, Merge, Twitter, FormTrigger 等节点。 使用Gemini AI实现Twitter内容自动化,包括推文、图片和互动
前置要求
- •Twitter API 凭证
- •可能需要目标 API 的认证凭证
- •Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "0cppyRyk426a9Syl",
"meta": {
"instanceId": "f678cb66f902ee934e7c819f39c2d7d59eee478ead5d09104fa91cfa2f204413"
},
"name": "AI 驱动的 Twitter 自动化与内容生成和互动",
"tags": [],
"nodes": [
{
"id": "8e1cf93a-2686-4255-a52c-c587d1009c08",
"name": "Twitter 内容表单",
"type": "n8n-nodes-base.formTrigger",
"position": [
528,
544
],
"webhookId": "0a74c675-cdc3-46e8-a496-213d9cf8afa8",
"parameters": {
"options": {
"path": "twitter-content-form",
"buttonLabel": "Generate Content"
},
"formTitle": "Twitter Content Generator",
"formFields": {
"values": [
{
"fieldLabel": "Topic/Niche",
"placeholder": "What topic or niche should the tweet be about?",
"requiredField": true
},
{
"fieldType": "dropdown",
"fieldLabel": "Tone",
"fieldOptions": {
"values": [
{
"option": "Casual"
},
{
"option": "Professional"
},
{
"option": "Normal"
},
{
"option": "Humorous"
}
]
},
"requiredField": true
},
{
"fieldType": "dropdown",
"fieldLabel": "Action Type",
"fieldOptions": {
"values": [
{
"option": "Post Tweet"
},
{
"option": "Engage with Posts"
},
{
"option": "Send Direct Message"
}
]
}
},
{
"fieldLabel": "Additional Instructions For Image(Prompt)",
"placeholder": "Any specific instructions for the AI?"
}
]
},
"formDescription": "Submit your content preferences for AI-powered Twitter automation"
},
"typeVersion": 2.3
},
{
"id": "0da7cb0f-a12a-46e6-9d19-30cc58df4da0",
"name": "工作流配置",
"type": "n8n-nodes-base.set",
"position": [
752,
544
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "id-1",
"name": "imageGenerationChance",
"type": "number",
"value": 0.3
},
{
"id": "id-2",
"name": "maxTweetLength",
"type": "number",
"value": 280
},
{
"id": "id-3",
"name": "imageModelUrl",
"type": "string",
"value": "https://openrouter.ai/api/v1/images/generations"
}
]
},
"includeOtherFields": true
},
"typeVersion": 3.4
},
{
"id": "25a1ccc6-d24e-4bc0-a6e6-289d44ac2064",
"name": "Twitter 发布工具",
"type": "n8n-nodes-base.twitterTool",
"position": [
2496,
816
],
"parameters": {
"text": "={{ $fromAI('tweet_text', 'The tweet content to post', 'string') }}",
"additionalFields": {
"attachments": "binary:imageData"
}
},
"typeVersion": 2
},
{
"id": "dab13c9d-a7e2-48ba-8179-d75d82372fcc",
"name": "Twitter 私信工具",
"type": "n8n-nodes-base.twitterTool",
"position": [
2608,
816
],
"parameters": {
"text": "={{ $fromAI('dm_message', 'The direct message content', 'string') }}",
"user": {
"__rl": true,
"mode": "username",
"value": "={{ $fromAI('recipient_username', 'The username to send the DM to', 'string') }}"
},
"resource": "directMessage",
"additionalFields": {}
},
"typeVersion": 2
},
{
"id": "c32402c6-0a70-4988-9673-4952f30158eb",
"name": "Twitter AI 代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
2432,
576
],
"parameters": {
"text": "=Topic: {{ $json['Topic/Niche'] }}\nTone: {{ $json.Tone }}\nAction: {{ $json['Action Type'] }}\nAdditional Instructions: {{ $json['Additional Instructions'] }}\nMax Tweet Length: {{ $json.maxTweetLength }} characters",
"options": {
"systemMessage": "=You are a Twitter automation assistant that helps create engaging content and manage Twitter interactions.\n\nYour capabilities:\n1. **Post Tweets**: Create compelling tweets based on the given topic, niche, and tone. Keep tweets under the specified character limit. You can include an image that is provided as input when posting the tweet. You do not create or generate images yourself."
},
"promptType": "define"
},
"typeVersion": 3
},
{
"id": "2d3f7d79-844f-4642-940c-6c64ffb6094f",
"name": "处理 AI 响应",
"type": "n8n-nodes-base.code",
"position": [
2736,
576
],
"parameters": {
"jsCode": "// Extract and format the AI agent's response\nconst items = $input.all();\n\nconst processedResults = items.map((item, index) => {\n const agentResponse = item.json;\n \n return {\n json: {\n timestamp: new Date().toISOString(),\n itemIndex: index,\n agentOutput: agentResponse.output || agentResponse.text || '',\n fullResponse: agentResponse,\n status: 'processed'\n }\n };\n});\n\nreturn processedResults;"
},
"typeVersion": 2
},
{
"id": "0559c71c-7a6a-44a5-93a0-b7d148d07811",
"name": "字段 - 设置值",
"type": "n8n-nodes-base.set",
"position": [
992,
400
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "4e04fec4-441e-45f7-acea-0017a4b5c104",
"name": "model",
"type": "string",
"value": "flux"
},
{
"id": "aa80cd68-1c82-4032-b1d7-e098856eec38",
"name": "width",
"type": "string",
"value": "1080"
},
{
"id": "da6d305f-aece-49bd-ae02-52df59915c60",
"name": "height",
"type": "string",
"value": "1920"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "a2e8982a-b501-435b-84b9-c2c86cda7cba",
"name": "代码 - 清理 Json",
"type": "n8n-nodes-base.code",
"position": [
1552,
400
],
"parameters": {
"jsCode": "function cleanAndExtractJSON(response) {\n try {\n const result = {\n image_prompt: []\n };\n\n const lines = response.split('\\n');\n let currentPrompt = '';\n\n for (const line of lines) {\n if (line.includes('\"prompt\":')) {\n if (currentPrompt) {\n result.image_prompt.push(currentPrompt.trim());\n }\n currentPrompt = line.split('\"prompt\":')[1].trim();\n }\n }\n\n if (currentPrompt) {\n result.image_prompt.push(currentPrompt.trim());\n }\n\n return { json: result };\n \n } catch (error) {\n return { \n json: {\n image_prompt: []\n }\n };\n }\n}\n\nconst response = $input.first().json.output;\nreturn cleanAndExtractJSON(response);"
},
"executeOnce": false,
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "15ce60b3-2822-49b7-8a80-e9709d33f9a4",
"name": "代码 - 获取提示",
"type": "n8n-nodes-base.code",
"position": [
1744,
400
],
"parameters": {
"jsCode": "return $input.first().json.image_prompt.map(prompt => ({\n json: {\n body: {\n prompt: prompt,\n \"image_size\": {\n \"width\": $('Fields - Set Values').first().json.width,\n \"height\": $('Fields - Set Values').first().json.height\n },\n \"num_inference_steps\": 12,\n \"guidance_scale\": 3.5,\n \"num_images\": 1,\n \"enable_safety_checker\": true,\n}\n }\n }\n));"
},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "df0bd8e3-bab9-401a-a611-dea217d059d0",
"name": "HTTP 请求 - 创建图像",
"type": "n8n-nodes-base.httpRequest",
"position": [
2128,
400
],
"parameters": {
"url": "=https://image.pollinations.ai/prompt/ {{ $('Code - Get Prompt').item.json.body.prompt }}",
"options": {
"response": {
"response": {
"responseFormat": "file",
"outputPropertyName": "imageData"
}
}
},
"jsonQuery": "={\n \"width\": {{ $('Fields - Set Values').item.json.width }},\n \"height\": {{ $('Fields - Set Values').item.json.height }},\n \"model\": \"{{ $('Fields - Set Values').item.json.model }}\",\n \"seed\": 42,\n \"nologo\": true\n}",
"sendQuery": true,
"sendHeaders": true,
"specifyQuery": "json",
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Accept",
"value": "application/json"
}
]
}
},
"retryOnFail": true,
"typeVersion": 4.2,
"alwaysOutputData": true,
"waitBetweenTries": 5000
},
{
"id": "7e832f3a-b2fa-4d36-9eab-399480545267",
"name": "代码 - 设置文件名",
"type": "n8n-nodes-base.code",
"position": [
1904,
400
],
"parameters": {
"jsCode": "for (let i = 0; i < items.length; i++) {\n items[i].json.fileName = `images_${(i + 1).toString().padStart(3, '0')}.png`;\n}\nreturn items;"
},
"typeVersion": 2
},
{
"id": "4932d5ff-7acc-4129-b376-cb8061042bf8",
"name": "AI 代理 - 从提示创建图像",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1232,
400
],
"parameters": {
"text": "={{ $('Workflow Configuration').item.json['Additional Instructions'] }}",
"options": {
"systemMessage": "=You are an AI image-prompt creation expert. Please create a post using the following JSON format:\nAI Image Generation Prompt Guidelines:\nObjective\nCreate highly realistic, high‐quality images\nEnsure the image content faithfully conveys the spirit of the original text\nIntegrate short text (10–20 characters) naturally into the image\nMaintain consistency and professionalism\n\nStandard Prompt Structure\n[Main Scene] | [Key Elements] | [Text Integration] | [Lighting & Atmosphere] | [Technical Parameters] | [Style Parameters]\n\nComponent Breakdown\n1. Main Scene (Weight ::8)\nDescribe the primary setting in line with the content.\nExamples:\nTech news: “modern tech office setting, minimalist workspace”\nEconomy news: “professional financial district, corporate environment”\nEducation news: “modern classroom, advanced learning environment”\n\n2. Key Elements (Weight ::8)\nList the main visual elements required.\nExamples:\n“large HD display showing text ‘AI Ethics’ in modern typography”\n“professional people in business attire discussing around interactive screen”\n“detailed infographic elements floating in augmented reality style”\n\n3. Text Integration (Weight ::7)\nHow to display text within the image:\ntext elements | elegant typography, clear readable text, integrated naturally into scene ::7\n\n4. Lighting & Atmosphere (Weight ::7)\nlighting | cinematic dramatic lighting, natural ambient light, professional studio setup ::7\nbackground | depth of field blur, clean professional environment ::6\n\n5. Technical Parameters\nparameters | 8k resolution, hyperrealistic, photorealistic quality, octane render, cinematic composition --ar 16:9\nsettings | sharp focus, high detail, professional photography --s 1000 --q 2\nComplete Examples\nExample 1: AI Ethics News\nprofessional tech conference room | large display showing \"AI Ethics Now\" in modern typography, group of diverse executives in discussion ::8 | clean modern workspace, glass walls, tech atmosphere ::7 | cinematic lighting, natural window light ::7 | 8k resolution, hyperrealistic quality, octane render --ar 16:9 --s 1000 --q 2\nExample 2: Financial Market News\nmodern stock exchange environment | giant LED wall showing \"Market Alert\" in bold typography, professional traders in action ::8 | dynamic financial data visualization, sleek modern interior ::7 | dramatic lighting, blue-tinted atmosphere ::7 | 8k resolution, photorealistic quality --ar 16:9 --s 1000 --q 2\n\nAdditional Parameters\n--chaos [0–100]: Adjust randomness\n--stylize [0–1000]: Degree of stylization\n--seed [number]: Ensure consistency across generations\n--niji: Optimized for Asian‐style aesthetics\n--v 5.2: Use the latest model version\n\nImportant Notes\nText in Image\nKeep it short and legible\nUse professional fonts\nIntegrate naturally into the scene\n\nComposition\nFollow the rule of thirds\nEnsure a clear focal point\nBalance text and imagery\n\nColor\nMatch a professional tone\nProvide sufficient contrast for readability\nMaintain visual consistency\n\nTechnical Details\nAlways use high resolution (8k)\nEnsure professional lighting\nOptimize for sharpness and detail\n\nCommon Pitfalls to Avoid\nOverly generic prompts\nMissing text‐integration guidance\nFailing to specify composition rules\nOmitting key technical parameters\n\nThe structure is:\n{\n prompt_image {prompt : \"\" , ...}\n}"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.7
},
{
"id": "2153e1ab-de35-4e2f-a5e5-1ff44443a6ba",
"name": "Google Gemini聊天模型2",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
1232,
560
],
"parameters": {
"options": {
"topK": 40,
"topP": 1,
"temperature": 0.5,
"safetySettings": {
"values": [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE"
}
]
},
"maxOutputTokens": 65536
},
"modelName": "models/gemini-2.0-flash"
},
"typeVersion": 1
},
{
"id": "d4020d18-38e6-46d6-b253-b4305e25bf52",
"name": "Twitter 互动工具",
"type": "n8n-nodes-base.twitterTool",
"position": [
2720,
816
],
"parameters": {
"tweetId": {
"__rl": true,
"mode": "id",
"value": "={{ $fromAI('tweet_id', 'The ID of the tweet to like, retweet, or reply to', 'string') }}"
},
"operation": "like"
},
"typeVersion": 2
},
{
"id": "9485ce18-f55e-461a-b49f-c20f5e0b2f8a",
"name": "创建推文",
"type": "n8n-nodes-base.twitter",
"position": [
3136,
400
],
"parameters": {
"text": "={{ $('Twitter AI Agent').first().json.output }}",
"additionalFields": {}
},
"typeVersion": 2
},
{
"id": "b2d84a23-05ee-4642-a3be-9b8821ebfa81",
"name": "合并推文文本和图像",
"type": "n8n-nodes-base.merge",
"position": [
2496,
384
],
"parameters": {},
"typeVersion": 3.2
},
{
"id": "2637e5e1-f6a1-4780-ad62-70c5591d6a79",
"name": "Google Gemini 聊天模型3",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
2400,
816
],
"parameters": {
"options": {},
"modelName": "models/gemini-2.0-flash"
},
"typeVersion": 1
},
{
"id": "c3c7a659-1423-4d54-82d6-d69e427d5a84",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
1872,
128
],
"parameters": {
"color": 6,
"width": 420,
"height": 604,
"content": "## **图像生成输出**"
},
"typeVersion": 1
},
{
"id": "b06e67ba-79c7-465e-8059-b47fa7e0c650",
"name": "固定 - Twitter 表单",
"type": "n8n-nodes-base.stickyNote",
"position": [
448,
128
],
"parameters": {
"color": 5,
"width": 492,
"height": 600,
"content": "## Twitter 表单和配置"
},
"typeVersion": 1
},
{
"id": "149b85fd-1623-4819-8cfd-968d5bf3a18a",
"name": "固定 - Twitter AI",
"type": "n8n-nodes-base.stickyNote",
"position": [
2304,
560
],
"parameters": {
"color": 7,
"width": 600,
"height": 608,
"content": "## Twitter 内容 AI"
},
"typeVersion": 1
},
{
"id": "d9e44007-bc90-4b4c-a117-803562a10afa",
"name": "固定 - 图像生成流程",
"type": "n8n-nodes-base.stickyNote",
"position": [
960,
128
],
"parameters": {
"color": 6,
"width": 892,
"height": 596,
"content": "## 可选的图像生成路径"
},
"typeVersion": 1
},
{
"id": "aa00fd60-272a-40fd-8d28-95dd4bfa5832",
"name": "固定 - Twitter 操作",
"type": "n8n-nodes-base.stickyNote",
"position": [
2800,
128
],
"parameters": {
"color": 6,
"width": 464,
"height": 408,
"content": "## 发布/私信/互动"
},
"typeVersion": 1
},
{
"id": "0e1dfb5b-22bb-4de8-b308-63c34b3f3e86",
"name": "固定 - 凭据",
"type": "n8n-nodes-base.stickyNote",
"position": [
448,
752
],
"parameters": {
"color": 4,
"width": 488,
"height": 284,
"content": "## 凭据和环境"
},
"typeVersion": 1
},
{
"id": "dc096eb0-7f37-4dfc-8c24-bef1e1dc2acf",
"name": "Sticky – Merge & Tweet",
"type": "n8n-nodes-base.stickyNote",
"position": [
2320,
128
],
"parameters": {
"color": 2,
"width": 468,
"height": 412,
"content": "## Merge & Publish (Twitter)\n**Node:** *Merge Tweet Text and Image*\nCombines text from the AI with optional `imageData` from the image flow. Downstream *Create Tweet* will post the composed content.\n\n**Tip:** If you want image-optional posting, add an IF check for `imageData` before Merge."
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "a6591255-d7b1-4591-8683-4bc3e546b199",
"connections": {
"Twitter DM Tool": {
"ai_tool": [
[
{
"node": "Twitter AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Twitter AI Agent": {
"main": [
[
{
"node": "Process AI Response",
"type": "main",
"index": 0
},
{
"node": "Merge Tweet Text and Image",
"type": "main",
"index": 0
}
]
]
},
"Code - Clean Json": {
"main": [
[
{
"node": "Code - Get Prompt",
"type": "main",
"index": 0
}
]
]
},
"Code - Get Prompt": {
"main": [
[
{
"node": "Code - Set Filename",
"type": "main",
"index": 0
}
]
]
},
"Twitter Post Tool": {
"ai_tool": [
[
{
"node": "Twitter AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Code - Set Filename": {
"main": [
[
{
"node": "HTTP Request - Create Image",
"type": "main",
"index": 0
}
]
]
},
"Fields - Set Values": {
"main": [
[
{
"node": "AI Agent - Create Image From Prompt",
"type": "main",
"index": 0
}
]
]
},
"Process AI Response": {
"main": [
[
{
"node": "Create Tweet",
"type": "main",
"index": 0
}
]
]
},
"Twitter Content Form": {
"main": [
[
{
"node": "Workflow Configuration",
"type": "main",
"index": 0
}
]
]
},
"Workflow Configuration": {
"main": [
[
{
"node": "Twitter AI Agent",
"type": "main",
"index": 0
},
{
"node": "Fields - Set Values",
"type": "main",
"index": 0
}
]
]
},
"Twitter Engagement Tool": {
"ai_tool": [
[
{
"node": "Twitter AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Google Gemini Chat Model2": {
"ai_languageModel": [
[
{
"node": "AI Agent - Create Image From Prompt",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Google Gemini Chat Model3": {
"ai_languageModel": [
[
{
"node": "Twitter AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Merge Tweet Text and Image": {
"main": [
[
{
"node": "Create Tweet",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request - Create Image": {
"main": [
[
{
"node": "Merge Tweet Text and Image",
"type": "main",
"index": 1
}
]
]
},
"AI Agent - Create Image From Prompt": {
"main": [
[
{
"node": "Code - Clean Json",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 社交媒体, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Reddit问题的AI自动化
使用Google Gemini和Sheets检测Reddit问题并自动评论解决方案
If
Set
Merge
+6
20 节点Virtual Depth
社交媒体
Twitter品牌自动推广
使用Anthropic Claude AI和Google Sheets报告自动进行Twitter品牌推广
Set
Code
Wait
+10
26 节点Pavlo Hurhu
社交媒体
✨🩷自动化社交媒体内容发布工厂 + 系统提示组合
使用GPT-4o为6个平台生成平台优化的社交媒体内容
If
Set
Code
+20
100 节点Luan Correia
社交媒体
基于GPT-4和审批流程的WhatsApp到社交媒体内容生成
基于GPT-4和审批流程的WhatsApp到社交媒体内容生成
If
Set
Gmail
+13
54 节点Jamot
社交媒体
内容聚合
使用Gemini AI从网站文章自动化社交媒体帖子发布到LinkedIn和X/Twitter
If
Set
Xml
+16
34 节点Vadim
内容创作
我的工作流5
基于 Gemini AI、网络搜索和 PDF 交付的全面研究报告生成器
Set
Code
Html
+14
102 节点Hichul
内容创作