This workflow corresponds to n8n.io template #9395 — we link there as the canonical source.
This workflow follows the Agent → Google Sheets recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "TdUwxmTIJnTwQhJe",
"meta": {
"templateCredsSetupCompleted": true
},
"name": "Twitter Automation",
"tags": [
{
"id": "GcbJtfnHd72wKEMY",
"name": "admin",
"createdAt": "2025-05-06T11:04:59.376Z",
"updatedAt": "2025-05-06T11:04:59.376Z"
}
],
"nodes": [
{
"id": "1cb94f67-d47c-4cdc-a231-d87adc9f8f42",
"name": "Code1",
"type": "n8n-nodes-base.code",
"position": [
128,
2272
],
"parameters": {
"jsCode": "// Templates for normal tweets\nconst subreddits = [\n \"n8n\",\n \"microsaas\",\n \"SaaS\",\n \"automation\",\n \"n8n_ai_agents\"\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.2) {\n // 20% chance \u2192 promo\n tweet = \"advertise\";\n ads = true;\n } else {\n // 80% chance \u2192 template\n tweet = getRandom(subreddits);\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": "01a9b39a-784a-409d-b4f1-3a1a345e3dca",
"name": "Tweet maker1",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
528,
2272
],
"parameters": {
"text": "={{ $json.tweet }}",
"options": {
"systemMessage": "=You are a ghostwriter who creates short, raw, non-repetitive tweets. \nYour job: generate a tweet refereingcing a post you saw on reddit\n\nYou have access to 3 tools to \n1. get trending posts from a subreddit\n2. get a list of recently posted tweets in the users account\n3. log a tweet based on a subredit post_id so that we dont mrecreate a similar tweet based on the post_id\n\nRules: \n- Get the subreddit from the user\n- Fetch trending subreddit posts from the database reddit tool.\n- Fetch the past tweets that has been posted and logged to the database\n- Choose a subreddit post_id to write about and make sure that post_id in that subreddit has never been used before to write a tweet\n- Generate a unique tweet. Write from the first person point of view. something like i discovered this cool workflow on reddit or this tool. Limit to 200 characters\n- Tweets must be punchy, edgy, and written in modern Twitter style. Have a strong opinion whether u think its cool or not. you are very edgy programmer turned enterpreneur but avoid all words of profanity, vulgar and sexual words\n- Keep it concise (2\u20134 lines). No hashtags. Minimal emojis (only if it fits). Ask for opinions. Always state what u saw\n- Use a separate line for each short phrase or thought"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 2.2
},
{
"id": "183cfd15-198f-4f7d-824d-e11bdadb962c",
"name": "read database2",
"type": "n8n-nodes-base.googleSheetsTool",
"position": [
672,
2464
],
"parameters": {
"options": {},
"filtersUI": {
"values": [
{
"lookupValue": "={{ $fromAI('subreddit', `subreddit`, 'string') }}",
"lookupColumn": "subreddit"
},
{
"lookupValue": "={{ $fromAI('id', `id of the post`, 'string') }}",
"lookupColumn": "post_id"
}
]
},
"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": {
"name": "<your credential>"
}
},
"typeVersion": 4.7
},
{
"id": "beed3c7c-7b8f-4158-a9d4-64e66288659d",
"name": "Google Gemini Chat Model1",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
384,
2320
],
"parameters": {
"options": {}
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "995f4e4e-dd8c-474d-b22d-f4bd4697d043",
"name": "Schedule Trigger1",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-96,
2272
],
"parameters": {
"rule": {
"interval": [
{
"field": "hours",
"hoursInterval": 2
}
]
}
},
"typeVersion": 1.2
},
{
"id": "f19be085-9dce-4751-b51b-a5a05eda309c",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
80,
2160
],
"parameters": {
"width": 256,
"height": 608,
"content": "## Randomly choose sub reddit\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nFor example\n```json\n[\n \"n8n\",\n \"microsaas\",\n \"SaaS\",\n \"automation\",\n \"n8n_ai_agents\"\n]\n```"
},
"typeVersion": 1
},
{
"id": "8afc5b1f-1367-4846-8154-7d2357b8c9d6",
"name": "Creates the tweet1",
"type": "n8n-nodes-base.twitter",
"position": [
1312,
2272
],
"parameters": {
"text": "={{ $json.tweet }}",
"additionalFields": {
"attachments": "={{ $json.image_id || null }}"
}
},
"credentials": {
"twitterOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 2
},
{
"id": "1fbf01eb-2e78-48d1-86b0-aba52156f958",
"name": "Structured Output Parser2",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
832,
2336
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"tweet\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n \"subreddit\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"string\", \n \"description\": \"id of the post on reddit\"\n\t\t}\n\t},\n \"required\": [\"tweet\"]\n}"
},
"typeVersion": 1.3
},
{
"id": "9943e3e6-ad59-4e34-acb0-af2be3f0a062",
"name": "Get many posts in Reddit1",
"type": "n8n-nodes-base.redditTool",
"position": [
496,
2448
],
"parameters": {
"limit": 10,
"filters": {
"category": "rising"
},
"operation": "getAll",
"subreddit": "={{$fromAI('subreddit','name of the subreddit','string')}}"
},
"credentials": {
"redditOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "3de9105e-f1c2-4ad4-8617-48a1ca259069",
"name": "Append row in sheet1",
"type": "n8n-nodes-base.googleSheets",
"position": [
1664,
2272
],
"parameters": {
"columns": {
"value": {
"Date": "={{$now.format('dd/MM/yyyy')}}",
"post_id": "={{ $('Edit Fields1').item.json.post_id }}",
"subreddit": "={{ $('Edit Fields1').item.json.subreddit }}",
"PAST TWEETS": "={{ $('Edit Fields1').item.json.tweet }}"
},
"schema": [
{
"id": "PAST TWEETS",
"type": "string",
"display": true,
"required": false,
"displayName": "PAST TWEETS",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Date",
"type": "string",
"display": true,
"required": false,
"displayName": "Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "subreddit",
"type": "string",
"display": true,
"required": false,
"displayName": "subreddit",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "post_id",
"type": "string",
"display": true,
"required": false,
"displayName": "post_id",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"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": {
"name": "<your credential>"
}
},
"typeVersion": 4.7
},
{
"id": "e100fb38-9f6a-42a3-bd97-a08a0077bfc0",
"name": "Edit Fields1",
"type": "n8n-nodes-base.set",
"position": [
1136,
2272
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "316d8d54-ce09-409b-ae4e-a2dffe41d011",
"name": "tweet",
"type": "string",
"value": "={{$json.output.tweet}}"
},
{
"id": "69c01373-920f-4b2a-92bf-9a3f2fad16b2",
"name": "subreddit",
"type": "string",
"value": "={{$json.output.subreddit || null}}"
},
{
"id": "a8b984bf-a55d-4ac3-9afc-d2fd95d1336c",
"name": "post_id",
"type": "string",
"value": "={{ $json.output.id || null}}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "79f6984b-1080-4477-8c4a-0f77d0459755",
"name": "Sticky Note10",
"type": "n8n-nodes-base.stickyNote",
"position": [
960,
2160
],
"parameters": {
"color": 5,
"width": 624,
"height": 608,
"content": "## Post to Twitter\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nGet your credentials from https://developer.x.com\n\n\n"
},
"typeVersion": 1
},
{
"id": "b5381fec-824a-44c2-9cde-cdabbbe4c542",
"name": "Sticky Note11",
"type": "n8n-nodes-base.stickyNote",
"position": [
1600,
2160
],
"parameters": {
"color": 4,
"width": 512,
"height": 608,
"content": "## Update Google Sheet\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nRecord the post id of the reddit post that we used to repurpose content. \n\nThis ensure we dont write about the same post twice\n\n"
},
"typeVersion": 1
},
{
"id": "bb800730-5a63-411e-bdbb-63b28fb683ae",
"name": "Sticky Note9",
"type": "n8n-nodes-base.stickyNote",
"position": [
352,
2160
],
"parameters": {
"color": 2,
"width": 592,
"height": 608,
"content": "## Repurpose a content from reddit\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThis AI agent\n1. Gets 10 recent posts from the subreddit\n2. Chooses one post as reference\n3. Check Google Sheets to ensure we have not written about this post before\n4. Repurpose that reddit post for twitter \n\n\n"
},
"typeVersion": 1
}
],
"active": true,
"settings": {
"callerPolicy": "workflowsFromSameOwner",
"errorWorkflow": "ernonQOxi07n6WGi",
"executionOrder": "v1",
"timeSavedPerExecution": 5
},
"versionId": "2483f036-f1af-4907-9a3a-26dd84a14018",
"connections": {
"Code1": {
"main": [
[
{
"node": "Tweet maker1",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields1": {
"main": [
[
{
"node": "Creates the tweet1",
"type": "main",
"index": 0
}
]
]
},
"Tweet maker1": {
"main": [
[
{
"node": "Edit Fields1",
"type": "main",
"index": 0
}
]
]
},
"read database2": {
"ai_tool": [
[
{
"node": "Tweet maker1",
"type": "ai_tool",
"index": 0
}
]
]
},
"Schedule Trigger1": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Creates the tweet1": {
"main": [
[
{
"node": "Append row in sheet1",
"type": "main",
"index": 0
}
]
]
},
"Append row in sheet1": {
"main": [
[]
]
},
"Get many posts in Reddit1": {
"ai_tool": [
[
{
"node": "Tweet maker1",
"type": "ai_tool",
"index": 0
}
]
]
},
"Google Gemini Chat Model1": {
"ai_languageModel": [
[
{
"node": "Tweet maker1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output Parser2": {
"ai_outputParser": [
[
{
"node": "Tweet maker1",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
googlePalmApigoogleSheetsOAuth2ApiredditOAuth2ApitwitterOAuth2Api
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Automatically turns trending Reddit posts into punchy, first-person tweets powered by Google Gemini AI, Reddit, and Twitter API, with Google Sheets logging.
Source: https://n8n.io/workflows/9395/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Transform your festival marketing with this comprehensive automation workflow that creates and posts culturally authentic social media content across multiple platforms daily.
Who is this template for? This workflow is perfect for competitive‑intel analysts, product managers, content marketers, and anyone who tracks multiple company blogs or news sources. If you need a week
This automation is designed to help you generate AI-powered music tracks, cover art, and fully rendered music videos — all triggered from a simple Telegram chat and managed via Google Sheets.
This workflow automates the complete blog publishing process. It removes manual work from content creation, image generation, category management, and WordPress publishing by using AI and n8n. It help
This workflow is perfect for creators, solopreneurs, and personal brands who want to consistently publish bold, high-performing content on X (Twitter) — without writing a single line themselves. After