{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "453c01a0-07fe-4600-bd60-aee0a280a5ec",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        192,
        192
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ee2275f1-e698-4b18-b10c-50b6fe7535b9",
      "name": "Read Business Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        416,
        192
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1789639419,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JIupfRSPFV1PW1Dp4Q1jmdcnmOALlgQjr6MBrmuiPzs/edit#gid=1789639419",
          "cachedResultName": "Sheet (All info)"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1JIupfRSPFV1PW1Dp4Q1jmdcnmOALlgQjr6MBrmuiPzs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JIupfRSPFV1PW1Dp4Q1jmdcnmOALlgQjr6MBrmuiPzs/edit?usp=drivesdk",
          "cachedResultName": "ColdEmail"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c5473567-81d4-48b4-8583-990606c1c245",
      "name": "Filter Unsent Emails",
      "type": "n8n-nodes-base.if",
      "position": [
        640,
        192
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"email_sent\"]}}",
              "value2": "yes",
              "operation": "notEqual"
            },
            {
              "value1": "={{$json[\"email\"]}}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7a91c4fc-cc55-4553-af95-03a07955f541",
      "name": "Prepare Sheet Update",
      "type": "n8n-nodes-base.set",
      "position": [
        1760,
        192
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "e7b61a8c-4733-41bc-a130-809ecd8b3779",
      "name": "Update Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1984,
        96
      ],
      "parameters": {
        "columns": {
          "value": {
            "city": "={{ $('Prepare Email Draft').item.json.city }}",
            "email": "={{ $('Prepare Email Draft').item.json.email }}",
            "date_sent": "={{$now.format(\"dd/MM/yyyy\")}}",
            "email_sent": "={{ $('Prepare Email Draft').item.json.email_body }}",
            "row_number": 0,
            "contact_name": "={{ $('Prepare Email Draft').item.json.contact_name }}",
            "subject_used": "={{ $('Merge Subject and Body').item.json.choices[0].message.content }}",
            "business_name": "={{ $('Prepare Email Draft').item.json.business_name }}",
            "business_type": "={{ $('Prepare Email Draft').item.json.business_type }}"
          },
          "schema": [
            {
              "id": "business_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "business_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "contact_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "contact_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "city",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "city",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "business_type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "business_type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email_sent",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email_sent",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date_sent",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "date_sent",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject_used",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "subject_used",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "business_name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1789639419,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JIupfRSPFV1PW1Dp4Q1jmdcnmOALlgQjr6MBrmuiPzs/edit#gid=1789639419",
          "cachedResultName": "Sheet (All info)"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1JIupfRSPFV1PW1Dp4Q1jmdcnmOALlgQjr6MBrmuiPzs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JIupfRSPFV1PW1Dp4Q1jmdcnmOALlgQjr6MBrmuiPzs/edit?usp=drivesdk",
          "cachedResultName": "ColdEmail"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "aed9100b-9cce-422c-8ed9-077e9717180a",
      "name": "Rate Limit Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        1984,
        288
      ],
      "parameters": {
        "unit": "seconds",
        "amount": 3
      },
      "typeVersion": 1
    },
    {
      "id": "4f545b68-2162-4491-8127-6f1baa66166e",
      "name": "Personalize Email (ChatGPT)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        96
      ],
      "parameters": {
        "url": "=https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"You are writing a simple, direct cold email as an AI automation service provider providing your services to businesses. Your services fall under the following categories: Lead generation systems (Cold Email, Speed to Lead, Ad + User Generated Content automation, Lead scraping, Go-to-market automation, AI-content generation), Sales systems (CRM automations, Proposal generators, Lead qualifying systems, Asset generators) and conversion-optimization systems (Personalized follow-up & nurture, Automatic lead scoring). You choose which ones to recommend to the business owners based on the prompt below. Keep it under 100 words, professional but conversational.\\n\\nBusiness Details:\\n- Name: {{$json[\"business_name\"]}}\\n- Contact: {{$json[\"contact_name\"]}}\\n- City: {{$json[\"city\"]}}\\n- Type: {{$json[\"business_type\"]}}\\n\\nWrite a personalized version of this template:\\n\\n'Hi [Contact],\\n\\nI help [business type plural] in [city] automate their repetitive tasks using AI, saving them 10+ hours weekly.\\n\\nFor your company, this could mean:\\n\u2022 Reduced time spent on repetitive tasks, freeing up your team for higher-value work\\n\u2022 Increased operational efficiency and productivity across your processes\\n\u2022 Improved revenue potential through smarter, faster decision-making\\n\\nSo, what do you think?\\n\\nWorth a quick 15-minute chat to see if this could work for you?\\n\\nBest,\\nAyis\\n+306947839876nMake the benefits specific and compelling. Keep the tone confident but not pushy. Output only the email body, no explanations.\"\n    }\n  ],\n  \"temperature\": 0.7,\n  \"max_tokens\": 400,\n  \"top_p\": 0.9\n}\n",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "openAiApi"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        },
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.1
    },
    {
      "id": "959f7d3f-d91a-4c6e-8ae1-4f0a8ac03d14",
      "name": "Generate Subject (ChatGPT)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        288
      ],
      "parameters": {
        "url": "=https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are an assistant that generates compelling subject lines for cold outreach emails.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Generate a compelling email subject line for a AI automation service provider cold outreaching to other businesses through email.\\n\\nBusiness: {{$json[\"business_name\"]}}\\nType: {{$json[\"business_type\"]}}\\nCity: {{$json[\"city\"]}}\\n\\nCreate 1 subject line that:\\n- Is specific to their business\\n- Creates curiosity\\n- Is under 50 characters\\n- Doesn't use spam words like 'free' or excessive punctuation\\n\\nExamples of good subject lines:\\n- 'Quick question about [Business Name]'s workflow'\\n- '15 min to save [Business Name] 10 hours/week?'\\n- 'How [competitor/other business type] cut admin time 40%'\\n- '[Business Name] - automating [specific task]'\\n\\nOutput only the subject line, nothing else.\"\n    }\n  ],\n  \"temperature\": 0.6,\n  \"max_tokens\": 50,\n  \"top_p\": 0.9\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "openAiApi"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        },
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.1
    },
    {
      "id": "5d8e3519-744f-4b61-8681-e87c746b4e20",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -512,
        -656
      ],
      "parameters": {
        "width": 672,
        "height": 944,
        "content": "## How It Works\n1. Starts with a Manual Trigger\n\n2. Reads lead list from Google Sheet\n\n3. Filter rows where email wasn\u2019t sent\n\n4. Generate personalized email body (AI)\n\n5. Generate email subject line (AI)\n\n6. Merge AI outputs with original row data\n\n7. Create Gmail draft\n\n8. Update Google Sheet with email content and date\n\n9. Wait 3 seconds between updates to avoid API limits\n\n## Setup Steps\n- Connect Google Sheets, Gmail, and OpenAI credentials\n- Check sheet column names (business_name, email, contact_name, city, business_type, email_sent)\n- Run Manual Trigger to test one row\n- Adjust AI prompts if needed\n\n## Customization\n- Add unique ID column to match rows if needed\n- Change AI prompts to adjust email style\n- Increase wait time to avoid rate limits\n\n## Use Cases\n- Draft cold emails for review before sending\n- Automate lead outreach while keeping human oversight\n- Generate personalized emails and subject lines quickly\n\n## Troubleshooting Tips\n- Draft not created \u2192 check Gmail credentials and scopes\n- Sheet not updating \u2192 check matching column exists\n- AI outputs empty \u2192 increase tokens or check response path"
      },
      "typeVersion": 1
    },
    {
      "id": "78c99319-eb37-4add-b2a8-abe70aa47d49",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        -16
      ],
      "parameters": {
        "color": 7,
        "width": 560,
        "height": 368,
        "content": "## Phase 1:\nManually trigger the worklfow, read business data from a google sheet and filter the emails which have not already been sent\n# ->"
      },
      "typeVersion": 1
    },
    {
      "id": "925dfa2b-ff58-45ac-ac2a-d35b0b454828",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 512,
        "content": "## Phase 2:\nCreate email subject and body using an http request to OpenAI's ChatGPT 4o-mini\n# ->"
      },
      "typeVersion": 1
    },
    {
      "id": "ac4ced8a-b8b6-4403-8ab6-e7cdaa727846",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 400,
        "content": "## Phase 3\nPrepare fields and create the draft email\n# ->"
      },
      "typeVersion": 1
    },
    {
      "id": "2d821218-7e6e-46f5-8376-af267ec0dd14",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1696,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 480,
        "content": "## Phase 4\nPrepare the fields (Set) and update google sheet.\n(Wait node is for API usage limit management)"
      },
      "typeVersion": 1
    },
    {
      "id": "b0fa3264-5cdd-45c8-8ca7-0c79a04ace73",
      "name": "Prepare Email Draft",
      "type": "n8n-nodes-base.set",
      "position": [
        1312,
        192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7bbcbe0c-4fa4-4d95-9d4a-ebb02d9a6a76",
              "name": "email_subject",
              "type": "string",
              "value": "={{ $('Generate Subject (ChatGPT)').item.json.choices[0].message.content }}"
            },
            {
              "id": "8d602dfc-3dbb-4e3d-9974-ac68f5ac12e8",
              "name": "=email_body",
              "type": "string",
              "value": "={{ $('Personalize Email (ChatGPT)').item.json.choices[0].message.content }}"
            },
            {
              "id": "91da7a5c-2bb1-43ba-98e0-c652518800ea",
              "name": "business_name",
              "type": "string",
              "value": "={{ $('Filter Unsent Emails').item.json.business_name }}"
            },
            {
              "id": "a622f1fc-e2c1-49a6-b8c4-012eedf8c468",
              "name": "email",
              "type": "string",
              "value": "={{ $('Filter Unsent Emails').item.json.email }}"
            },
            {
              "id": "ddea1bce-4f41-462f-a602-a923561e3030",
              "name": "contact_name",
              "type": "string",
              "value": "={{ $('Filter Unsent Emails').item.json.contact_name }}"
            },
            {
              "id": "3cfaaecf-4139-4be8-b404-90bb68ca3f9d",
              "name": "city",
              "type": "string",
              "value": "={{ $('Filter Unsent Emails').item.json.city }}"
            },
            {
              "id": "c6dac679-380c-4a0f-85fc-f6510cfb6abb",
              "name": "business_type",
              "type": "string",
              "value": "={{ $('Filter Unsent Emails').item.json.business_type }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "fc1a66a3-555d-4711-8b37-e75422b3c5d2",
      "name": "Create Email Draft",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1536,
        192
      ],
      "parameters": {
        "message": "={{$json[\"email_body\"].replace(/\\n/g, '<br>')}}",
        "options": {},
        "subject": "={{ $('Generate Subject (ChatGPT)').item.json.choices[0].message.content }}",
        "resource": "draft",
        "emailType": "html"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "e19bd5b5-7c68-4b1d-9026-36ff868af095",
      "name": "Merge Subject and Body",
      "type": "n8n-nodes-base.merge",
      "position": [
        1088,
        192
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Read Business Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Email Draft": {
      "main": [
        [
          {
            "node": "Prepare Sheet Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Business Data": {
      "main": [
        [
          {
            "node": "Filter Unsent Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Draft": {
      "main": [
        [
          {
            "node": "Create Email Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Unsent Emails": {
      "main": [
        [
          {
            "node": "Personalize Email (ChatGPT)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Generate Subject (ChatGPT)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Sheet Update": {
      "main": [
        [
          {
            "node": "Update Google Sheet",
            "type": "main",
            "index": 0
          },
          {
            "node": "Rate Limit Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Subject and Body": {
      "main": [
        [
          {
            "node": "Prepare Email Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Subject (ChatGPT)": {
      "main": [
        [
          {
            "node": "Merge Subject and Body",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Personalize Email (ChatGPT)": {
      "main": [
        [
          {
            "node": "Merge Subject and Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}