{
  "id": "fDLwldlY6FV3fqJ2",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Generate and post Content on Linkedin using AI Agent with Gemini Chat API",
  "tags": [],
  "nodes": [
    {
      "id": "d24cd7a9-52b3-4cde-8323-748f4a474e9f",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -528,
        -64
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9d8dc5b0-603a-484a-b710-0484141017ec",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -304,
        -64
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "baaa3fc3-f510-4af1-80ac-7b46619de020",
              "name": "niche",
              "type": "string",
              "value": "startup founders in SaaS"
            },
            {
              "id": "287ddc20-8032-4fc4-8913-ca52fbb58d29",
              "name": "audience",
              "type": "string",
              "value": "growth-focused professionals"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d7740a8c-0cf3-4bdc-84c9-4e5261ace324",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -80,
        -64
      ],
      "parameters": {
        "text": "=You are a content strategist for LinkedIn.\nGiven a niche and audience, return 10 scroll-stopping post ideas as compact titles.\nOutput STRICT JSON:\n{\n  \"ideas\": [\n    {\"id\": 1, \"title\": \"...\"},\n    ...\n    {\"id\": 10, \"title\": \"...\"}\n  ]\n}\nNiche: {{$json.niche}}\nAudience: {{$json.audience}}\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "80d63523-f0e3-4253-8d66-1de45233dfbe",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -8,
        160
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "be593fa2-f68c-461d-994a-d5b7274c3a6a",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        272,
        -64
      ],
      "parameters": {
        "jsCode": "// 1) Get raw AI output from the previous node\nlet raw = $input.first().json.output || $json.data || \"\";\n\n// 2) Remove ```json fences if present\nraw = raw.replace(/```json/i, \"\").replace(/```/g, \"\").trim();\n\n// 3) Parse\nlet data;\ntry { data = JSON.parse(raw); }\ncatch (e) { throw new Error(\"Gemini did not return valid JSON:\\n\" + raw); }\n\nconst ideas = data.ideas || [];\n\n// 4) Create correlationId for this email thread/session\nconst correlationId = Date.now().toString() + '-' + Math.random().toString(36).slice(2,8);\n\n// 5) Build a nice email body\nlet body = `Here are 10 LinkedIn post ideas for \u201c$('Edit Fields').first().json.audience\u201d in \u201c$('Edit Fields').first().json.niche\u201d:\\n\\n`;\nideas.forEach(i => { body += `${i.id}. ${i.title}\\n`; });\nbody += `\\nReply with the number (1\u201310) to draft posts.\\n`;\n\n// 6) Return\nreturn [{\n  correlationId,\n  niche: $('Edit Fields').first().json.niche,\n  audience: $('Edit Fields').first().json.audience,\n  ideas,\n  emailBody: body\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "db32c86a-f3d3-4257-80cc-1d9c45f2d9df",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        720,
        -64
      ],
      "parameters": {
        "sendTo": "user@example.com ",
        "message": "={{ $('Code').item.json.emailBody }}",
        "options": {},
        "subject": "=Your 10 LinkedIn Ideas [CID: {{ $json['correlationId '] }}]"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "eeafee6c-8258-48d7-99f6-7cd80b1c95bf",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -528,
        516
      ],
      "parameters": {
        "filters": {
          "q": "to:me subject:\"[CID:\" is:inbox -category:promotions",
          "sender": "user@example.com ",
          "includeSpamTrash": false
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.3
    },
    {
      "id": "812e4f0c-4d66-4fba-a7dc-882504ac3cd5",
      "name": "Code1",
      "type": "n8n-nodes-base.code",
      "position": [
        -304,
        516
      ],
      "parameters": {
        "jsCode": "// Pull a plain text we can regex against (snippet is usually fine)\nconst text = ($input.first().json.snippet || '').trim();\n\n// First number in the reply\nconst numMatch = text.match(/\\d+/);\nconst selectedNumber = numMatch ? Number(numMatch[0]) : null;\n\n// Extract correlationId from Subject header\nlet subject = $input.first().json.Subject\nconst cidMatch = subject.match(/\\[CID:\\s*([^\\]]+)\\]/i);\nconst correlationId = cidMatch ? cidMatch[1] : null;\n\n// Who replied (optional, can be useful)\nlet from = '';\nif ($json.payload && $json.payload.headers) {\n  const f = $json.payload.headers.find(h => h.name === 'From');\n  from = f ? f.value : '';\n}\n\nif (!correlationId || !selectedNumber) {\n  return [{ kind: 'unknown', reason: 'Missing CID or number', subject, text }];\n}\n\nreturn [{\n  kind: 'numberReply',\n  selectedNumber,\n  correlationId,\n  from\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "fdcd4332-9481-48c9-98a0-00b9aa2f6d85",
      "name": "Code2",
      "type": "n8n-nodes-base.code",
      "position": [
        464,
        384
      ],
      "parameters": {
        "jsCode": "// Parse ideas into array\nconst ideas = JSON.parse($input.first().json.ideas || \"[]\");\n\n// Convert selected number to string because ids are strings in your JSON\nconst selectedNumber = $('Code1').first().json.selectedNumber;\n\n// Find chosen idea\nconst chosen = ideas.find(i => i.id === selectedNumber);\n\nif (!chosen) {\n  return [{\n    error: true,\n    msg: 'Idea not found',\n    selectedNumber\n  }];\n}\n\nreturn [{\n  correlationId: $input.first().json['correlationId '],\n  selectedTopic: chosen.title,\n  niche: $input.first().json.niche,\n  audience: $input.first().json.audience\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d809b62b-d5d9-4d87-8961-6be7ee9b2ae8",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        704,
        272
      ],
      "parameters": {
        "text": "=Create 3 LinkedIn post drafts about the topic below, tailored to the audience.\nLength: 120\u2013200 words each, plain text. Avoid emojis unless natural.\nOutput strict JSON:\n{\n  \"drafts\": [\n    {\"id\": 1, \"text\": \"...\"},\n    {\"id\": 2, \"text\": \"...\"},\n    {\"id\": 3, \"text\": \"...\"}\n  ]\n}\nTopic: {{$json.selectedTopic}}\nAudience: {{$json.audience}}\nNiche: {{$json.niche}}\nTone: insightful, practical, founder-friendly\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "2594ad03-fcb3-4ac8-b707-663cac6fb1b9",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        768,
        480
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "aee41c79-9bce-4756-8603-15406165f11b",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        496,
        -64
      ],
      "parameters": {
        "columns": {
          "value": {
            "ideas": "={{ $json.ideas }}",
            "niche": "={{ $json.niche }}",
            "stage": "=\"ideas\"",
            "audience": "={{ $json.audience }}",
            "correlationId ": "={{ $json.correlationId }}"
          },
          "schema": [
            {
              "id": "correlationId ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "correlationId ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "stage",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "stage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "niche",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "niche",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "audience",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "audience",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ideas",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ideas",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "selectedTopic",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "selectedTopic",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "drafts",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "drafts",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "linkedinUrn",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "linkedinUrn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "correlationId"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1O0ewqwJerpjv6h8Zq5jrA4NC-crh4CVcH1uT2PHuUQg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/",
          "cachedResultName": "Linkedin Post Idea"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "4a3db0b9-20c7-423e-b0e3-90d9249b63c9",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        144,
        500
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Drafts Path",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a7824eea-4a1c-4e56-abfb-7b01f2195d76",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.stage }}",
                    "rightValue": "\"ideas\""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Publish Path",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "9fcf7470-47bb-4ec6-bf94-dd154f4c5220",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.stage }}",
                    "rightValue": "\"drafts\""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "END",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c92dcf46-6b16-49d2-b4a8-9612c8615a42",
                    "operator": {
                      "type": "string",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.stage }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "6f8f75a6-2226-412f-9f2b-694f7cde6e10",
      "name": "Code3",
      "type": "n8n-nodes-base.code",
      "position": [
        1056,
        272
      ],
      "parameters": {
        "jsCode": "let raw = $input.first().json.output || $json.data || \"\";\nraw = raw.replace(/```json/i, \"\").replace(/```/g, \"\").trim();\n\nlet data;\ntry { data = JSON.parse(raw); }\ncatch(e) { throw new Error(\"Gemini drafts JSON parse error:\\n\" + raw); }\n\nconst drafts = data.drafts || [];\nlet body = `Here are 3 drafts for:\\n\u201c$('Code2').first().json.selectedTopic\u201d\\n\\n`;\ndrafts.forEach(d => { body += `${d.id}. ${d.text}\\n\\n`; });\nbody += `Reply with 1, 2, or 3 to publish on LinkedIn.\\n`;\n\nreturn [{\n  correlationId: $('Code2').first().json.correlationId,\n  selectedTopic: $('Code2').first().json.selectedTopic,\n  drafts,\n  emailBody: body\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "6570f3c1-e3a8-4a27-a600-e0d101bb0f03",
      "name": "Update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1296,
        272
      ],
      "parameters": {
        "columns": {
          "value": {
            "stage": "\"drafts\"",
            "drafts": "={{ $json.drafts }}",
            "selectedTopic": "={{ $json.selectedTopic }}",
            "correlationId ": "={{ $json.correlationId }}"
          },
          "schema": [
            {
              "id": "correlationId ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "correlationId ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "stage",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "stage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "niche",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "niche",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "audience",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "audience",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ideas",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ideas",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "selectedTopic",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "selectedTopic",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "drafts",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "drafts",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "linkedinUrn",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "linkedinUrn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "correlationId "
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1O0ewqwJerpjv6h8Zq5jrA4NC-crh4CVcH1uT2PHuUQg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/k",
          "cachedResultName": "Linkedin Post Idea"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "eea1b34d-eb46-4ea6-b592-1143d11f7065",
      "name": "Send a message1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1536,
        272
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $('Code3').item.json.emailBody }}",
        "options": {},
        "subject": "=Drafts for \"{{$json.selectedTopic}}\" [CID: {{ $json['correlationId '] }}]"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "af15a85f-d54b-49d1-9225-c1a6bc34a30c",
      "name": "Code4",
      "type": "n8n-nodes-base.code",
      "position": [
        464,
        688
      ],
      "parameters": {
        "jsCode": "// Extract drafts from sheet row\nlet drafts = $input.first().json.drafts || [];\nif (typeof drafts === 'string') {\n  try {\n    drafts = JSON.parse(drafts);\n  } catch (e) {\n    return [{ error: true, msg: 'Failed to parse drafts JSON', raw: drafts }];\n  }\n}\n\n// Get selected number from earlier node\nconst idx = $item(0).$node[\"Code1\"].json.selectedNumber;\nconst selected = drafts.find(d => Number(d.id) === Number(idx));\n\nif (!selected) {\n  return [{\n    error: true,\n    msg: `Draft #${idx} not found`,\n    availableDrafts: drafts.map(d => d.id)\n  }];\n}\n\nreturn [{\n  correlationId: $json.correlationId,\n  selectedTopic: $json.selectedTopic,\n  finalPost: selected.text\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d4da723f-bf55-4718-9e69-d928d1d871eb",
      "name": "Create a post",
      "type": "n8n-nodes-base.linkedIn",
      "position": [
        752,
        688
      ],
      "parameters": {
        "text": "={{ $json.finalPost }}",
        "postAs": "organization",
        "organization": "79935287",
        "authentication": "communityManagement",
        "additionalFields": {}
      },
      "credentials": {
        "linkedInCommunityManagementOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9f09d25f-4e52-4a32-b819-3801cd48b46a",
      "name": "Update row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        992,
        688
      ],
      "parameters": {
        "columns": {
          "value": {
            "stage": "Posted",
            "linkedinUrn": "={{ $json.urn }}",
            "correlationId ": "={{ $('Get row(s) in sheet').item.json['correlationId '] }}"
          },
          "schema": [
            {
              "id": "correlationId ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "correlationId ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "stage",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "stage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "niche",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "niche",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "audience",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "audience",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ideas",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ideas",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "selectedTopic",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "selectedTopic",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "drafts",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "drafts",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "linkedinUrn",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "linkedinUrn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "correlationId "
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1O0ewqwJerpjv6h8Zq5jrA4NC-crh4CVcH1uT2PHuUQg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/",
          "cachedResultName": "Linkedin Post Idea"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b7d82533-a238-4bb3-8ee5-a024344031dc",
      "name": "Send a message2",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1216,
        688
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=Published to LinkedIn \u2705\n\nTopic:\n{{ $('Code4').item.json.selectedTopic }}\n\nPreview:\n{{($('Code4').item.json.finalPost).slice(0, 200) }}\u2026\n",
        "options": {},
        "subject": "=Posted \u2705 \u201c{{ $('Code4').item.json.selectedTopic }}\u201d [CID: {{ $json['correlationId '] }}]"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "27456f83-4fab-47f3-b0da-967e0ceb578c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        -288
      ],
      "parameters": {
        "width": 704,
        "height": 1360,
        "content": "Turn a simple email workflow into a **LinkedIn content machine**. Generate post ideas, draft full posts, and auto-publish to LinkedIn \u2014 all controlled by replying to emails.  \n\n---\n\n## \ud83d\udccc Purpose  \nAutomate your LinkedIn posting pipeline using **AI + Email approvals**.  \n- Generate **10 scroll-stopping post ideas** tailored to your niche & audience.  \n- Approve your favorite by replying to the email with a number.  \n- Receive **3 AI-written drafts** for the chosen idea.  \n- Pick your favorite draft via email reply.  \n- The selected post gets **auto-published to LinkedIn** \u2705.  \n- All steps are logged in **Google Sheets**.  \n\n---\n\n## \ud83d\udd17 Apps Used  \n- **Google Gemini** \u2192 generates ideas & drafts  \n- **Gmail** \u2192 email-based approval workflow  \n- **Google Sheets** \u2192 tracks ideas, drafts, and published posts  \n- **LinkedIn API** \u2192 posts directly to your company or personal account  \n\n---\n\n## \u2728 Highlights  \n- \ud83d\udcec Email-based approval \u2192 no dashboards, just reply with a number  \n- \ud83d\udcdd 10 AI-generated content ideas + 3 full drafts per topic  \n- \ud83d\udd04 End-to-end tracking in Google Sheets (`ideas \u2192 drafts \u2192 published`)  \n- \u26a1 Auto-posting directly to LinkedIn  \n- \u2705 Final confirmation email with preview  \n\n---\n\n## \ud83d\udc64 Best For  \n- Startup founders  \n- Agencies managing multiple clients\u2019 LinkedIn  \n- Solopreneurs & creators who want consistent posting  \n\n---\n\n## \ud83d\udee0\ufe0f Workflow Overview  \n\n```mermaid\nflowchart TD\n    A[Manual Trigger] --&gt; B[AI Agent - Generate 10 Ideas]\n    B --&gt; C[Code - Parse JSON + Correlation ID]\n    C --&gt; D[Google Sheets - Append Ideas]\n    D --&gt; E[Gmail - Send Ideas Email]\n    E --&gt; F[Gmail Trigger - Await Reply]\n    F --&gt; G[Code1 - Extract Reply Number]\n    G --&gt; H[Google Sheets - Fetch Row]\n    H --&gt; I{Switch Stage}\n    I --&gt;|Ideas| J[AI Agent - Generate 3 Drafts]\n    J --&gt; K[Code3 - Parse Drafts]\n    K --&gt; L[Google Sheets - Update Drafts]\n    L --&gt; M[Gmail - Send Drafts Email]\n    I --&gt;|Drafts| N[Code4 - Select Final Draft]\n    N --&gt; O[LinkedIn - Publish Post]\n    O --&gt; P[Google Sheets - Update Posted]\n    P --&gt; Q[Gmail - Send Confirmation]\n"
      },
      "typeVersion": 1
    },
    {
      "id": "fd24d63f-ff08-4bbb-ad21-ef373f050b00",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -616,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 272,
        "height": 256,
        "content": "### 1. Manual Trigger  \nRuns workflow manually for testing or ad-hoc posting."
      },
      "typeVersion": 1
    },
    {
      "id": "bf456d49-6752-4a42-a0e0-728b42c091fe",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        -160
      ],
      "parameters": {
        "content": "### 2. Edit Fields (Set Node)  \nDefines **niche** & **audience** for content generation."
      },
      "typeVersion": 1
    },
    {
      "id": "5fdf070e-5045-4178-ae6e-e97b5514711f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        -256
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 352,
        "content": "### 3. AI Agent (LangChain Agent)  \nGenerates **10 post ideas** in strict JSON format."
      },
      "typeVersion": 1
    },
    {
      "id": "a99ee1f8-19df-4f85-8f5e-7029b76b893d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        128
      ],
      "parameters": {
        "color": 3,
        "width": 352,
        "content": "### 4. Google Gemini Chat Model  \nLLM backend for AI Agent. Requires Gemini API credentials."
      },
      "typeVersion": 1
    },
    {
      "id": "f0dde27d-4d91-4ecb-808f-974cc27b93b5",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -128
      ],
      "parameters": {
        "width": 224,
        "height": 224,
        "content": "### 5. Code (Parse AI Output)  \nCleans JSON, generates correlationId, builds email body."
      },
      "typeVersion": 1
    },
    {
      "id": "6e382e0e-864c-4804-8e52-fe61ee75b813",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        424,
        -192
      ],
      "parameters": {
        "color": 5,
        "height": 288,
        "content": "### 6. Append Row in Sheet (Google Sheets)  \nLogs generated ideas, stage set to *ideas*."
      },
      "typeVersion": 1
    },
    {
      "id": "f8163c49-3c9c-4587-8666-ec93ada62ce1",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        672,
        -240
      ],
      "parameters": {
        "color": 7,
        "height": 336,
        "content": "### 7. Send a Message (Gmail)  \nEmails you the ideas. You reply with a number."
      },
      "typeVersion": 1
    },
    {
      "id": "391c04c2-7832-4cd1-be7f-57b8d2783231",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -600,
        324
      ],
      "parameters": {
        "color": 4,
        "height": 352,
        "content": "### 8. Gmail Trigger  \nListens for replies with `[CID: ...]`."
      },
      "typeVersion": 1
    },
    {
      "id": "ba7c562d-6bc2-47c9-a4d1-0e26d2f0c04b",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -376,
        356
      ],
      "parameters": {
        "height": 320,
        "content": "### 9. Code1 (Extract Reply)  \nParses reply to extract chosen number & correlationId."
      },
      "typeVersion": 1
    },
    {
      "id": "a86524e5-e4da-47ad-b2be-8f309d2860f3",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -80,
        516
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.correlationId }}",
              "lookupColumn": "correlationId "
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/YOUR_AWS_SECRET_KEY_HERE-crh4CVcH1uT2PHuUQg/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1O0ewqwJerpjv6h8Zq5jrA4NC-crh4CVcH1uT2PHuUQg",
          "cachedResultUrl": "https://docs.google.com/YOUR_AWS_SECRET_KEY_HERE-crh4CVcH1uT2PHuUQg/edit?usp=drivesdk",
          "cachedResultName": "Linkedin Post Idea"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.7,
      "alwaysOutputData": true
    },
    {
      "id": "e22c031e-2559-4c29-af11-67fe606a259c",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        356
      ],
      "parameters": {
        "color": 5,
        "width": 192,
        "height": 320,
        "content": "### 10. Get Row(s) in Sheet  \nFetches stored row by correlationId."
      },
      "typeVersion": 1
    },
    {
      "id": "686e770c-ea46-4b41-aca6-a705fa093dbf",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        336
      ],
      "parameters": {
        "color": 6,
        "height": 464,
        "content": "### 11. Switch  \nRoutes flow: **ideas \u2192 drafts \u2192 publish**."
      },
      "typeVersion": 1
    },
    {
      "id": "62331774-9639-4eb2-a8bf-1fcf50971901",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        256
      ],
      "parameters": {
        "content": "### 12. Code2 (Match Selected Idea)  \nFinds the chosen idea & extracts topic."
      },
      "typeVersion": 1
    },
    {
      "id": "576bbe0f-f7fe-4de3-9fd7-fe19f7844e38",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        656,
        128
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 320,
        "content": "### 13. AI Agent1 (Draft Generator)  \nGenerates **3 drafts** (120\u2013200 words each)."
      },
      "typeVersion": 1
    },
    {
      "id": "9d83589b-207f-40ec-b74a-16506a070b98",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        464
      ],
      "parameters": {
        "color": 3,
        "width": 304,
        "height": 112,
        "content": "### 14. Google Gemini Chat Model1  \nBackend for AI Agent1."
      },
      "typeVersion": 1
    },
    {
      "id": "39933d7c-28dc-4d6e-88a4-7142174ba3fe",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        976,
        144
      ],
      "parameters": {
        "height": 256,
        "content": "### 15. Code3 (Parse Drafts)  \nParses drafts JSON, builds email body."
      },
      "typeVersion": 1
    },
    {
      "id": "796a69f9-2900-4f83-8d48-c254eeede8c3",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1232,
        128
      ],
      "parameters": {
        "color": 5,
        "height": 288,
        "content": "### 16. Update Row in Sheet  \nUpdates stage to *drafts*, logs drafts JSON."
      },
      "typeVersion": 1
    },
    {
      "id": "6d2bb7da-ea48-46f7-a684-29fb4da0bad4",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1504,
        96
      ],
      "parameters": {
        "color": 7,
        "height": 320,
        "content": "### 17. Send a Message1 (Gmail)  \nEmails you the 3 drafts for approval."
      },
      "typeVersion": 1
    },
    {
      "id": "72eb365d-0a75-4568-bcc9-5c9e837a150c",
      "name": "Sticky Note18",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        560
      ],
      "parameters": {
        "content": "### 18. Code4 (Match Selected Draft)  \nExtracts final draft based on reply number."
      },
      "typeVersion": 1
    },
    {
      "id": "2441751d-9a55-426d-995b-0c63313a41bc",
      "name": "Sticky Note19",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        656,
        624
      ],
      "parameters": {
        "color": 6,
        "content": "### 19. Create a Post (LinkedIn)  \nPublishes final post to LinkedIn."
      },
      "typeVersion": 1
    },
    {
      "id": "13eedb37-8e92-4fad-994a-40948c2bccb5",
      "name": "Sticky Note20",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        608
      ],
      "parameters": {
        "color": 5,
        "height": 256,
        "content": "### 20. Update Row in Sheet1  \nUpdates sheet stage to *Posted* with LinkedIn URN."
      },
      "typeVersion": 1
    },
    {
      "id": "fd76390c-8832-4ba6-a8c2-44e8d7913dd4",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        592
      ],
      "parameters": {
        "color": 7,
        "height": 256,
        "content": "### 21. Send a Message2 (Gmail)  \nSends final confirmation email with preview."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "timezone": "Asia/Kolkata",
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": "fDLwldlY6FV3fqJ2",
    "executionOrder": "v1"
  },
  "versionId": "b50605e2-db09-447a-b131-1d982ed9c3ff",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code2": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code3": {
      "main": [
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code4": {
      "main": [
        [
          {
            "node": "Create a post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Code2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code4",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Code3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a post": {
      "main": [
        [
          {
            "node": "Update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message1": {
      "main": [
        []
      ]
    },
    "Append row in sheet": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet1": {
      "main": [
        [
          {
            "node": "Send a message2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}