{
  "name": "Send AI-generated Gmail auto replies with GPT-4o-mini and Google Sheets",
  "nodes": [
    {
      "id": "893a885d-8c20-4a31-9a2e-06c844f69cdc",
      "name": "Config - Rules & Thresholds",
      "type": "n8n-nodes-base.set",
      "position": [
        208,
        0
      ]
    },
    {
      "id": "acabf18f-19f9-4040-a7fc-05221afdc25b",
      "name": "Gmail Trigger - New Emails",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -32,
        0
      ]
    },
    {
      "id": "0b4cc9ec-addd-4126-a80c-ecbe61e9415b",
      "name": "Normalize - Email Payload",
      "type": "n8n-nodes-base.set",
      "position": [
        416,
        0
      ]
    },
    {
      "id": "42341e74-8229-46c6-b555-6116b9622d55",
      "name": "IF - Ignore Filter",
      "type": "n8n-nodes-base.if",
      "position": [
        704,
        0
      ]
    },
    {
      "id": "c8d00799-0002-435d-8a85-fc9d9beed94c",
      "name": "Code - Extract Sender Email",
      "type": "n8n-nodes-base.code",
      "position": [
        1072,
        0
      ]
    },
    {
      "id": "3aeda011-622c-43bd-9fbe-962c886c95a5",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1280,
        0
      ]
    },
    {
      "id": "d6280885-198d-4a07-af2d-bc5052c5749e",
      "name": "IF - Found in Reply History?",
      "type": "n8n-nodes-base.if",
      "position": [
        1504,
        0
      ]
    },
    {
      "id": "ae24178d-8250-4e58-a8e4-7c5373575ddd",
      "name": "Gmail - Search Sent to Sender",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1776,
        0
      ]
    },
    {
      "id": "a34766da-013a-44b8-b451-13c167b0208a",
      "name": "IF - Sent history exists?",
      "type": "n8n-nodes-base.if",
      "position": [
        1984,
        0
      ]
    },
    {
      "id": "206ef0f7-568b-4de5-b3ba-f534d0ac89f7",
      "name": "Reply to a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2592,
        0
      ]
    },
    {
      "id": "026d4ffd-62b8-404b-bc74-49c4bb8629c1",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2272,
        0
      ]
    },
    {
      "id": "9e2685f7-3bc9-4101-ac77-1cee9a52e6bf",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        -320
      ],
      "parameters": {
        "width": 528,
        "height": null,
        "content": "## Overview – Workflow Purpose\nThis workflow automatically replies to important incoming Gmail messages.\nIt avoids duplicate replies by checking both a Google Sheet reply history\nand recent sent email"
      }
    },
    {
      "id": "e761d851-fb8a-4f0a-a824-7aff61ffa6b7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        -128
      ],
      "parameters": {
        "width": 656,
        "height": 320,
        "content": "## Step 1 – Email Intake & Normalization\nReceive new Gmail emails, load global rules and thresholds,\nand normalize email data into a consistent structure\nfor stable downstream processing.\n"
      }
    },
    {
      "id": "9aa34137-388d-4534-9ce7-1b64ac058be1",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        -128
      ],
      "parameters": {
        "width": 400,
        "height": 320,
        "content": "## Step 2 – Ignore Unwanted Emails\nFilter out newsletters, promotions, and irrelevant emails.\nMessages that match ignore rules are stopped immediately."
      }
    },
    {
      "id": "5b8def90-a228-4cb4-9880-2bef56e1848b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        -128
      ],
      "parameters": {
        "width": 688,
        "height": 320,
        "content": "## Step 3 – Reply History Check (Google Sheet)\nExtract the sender’s email address and check\nwhether it already exists in the Google Sheet reply history.\nIf found, no reply is sent."
      }
    },
    {
      "id": "c2c19b15-0ed4-46e9-b096-ca2337f36de9",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1696,
        -128
      ],
      "parameters": {
        "width": 496,
        "height": 320,
        "content": "## Step 4 – Recent Sent Email Check (Gmail)\nSearch Gmail for recently sent messages to the same sender.\nIf a recent reply exists within the defined time window,\nthe workflow stops to prevent duplicate"
      }
    },
    {
      "id": "84b668cb-d1cf-47f7-8a25-92bf5fe39024",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2208,
        -128
      ],
      "parameters": {
        "width": 576,
        "height": 320,
        "content": "## Step 5 – AI Reply Generation & Sending\nGenerate a clear English reply using AI\nand send it as a reply to the original Gmail message.\nThis step runs only when no duplicate reply is detected."
      }
    }
  ],
  "connections": {
    "Message a model": {
      "main": [
        [
          {
            "node": "Reply to a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF - Ignore Filter": {
      "main": [
        [],
        [
          {
            "node": "Code - Extract Sender Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "IF - Found in Reply History?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF - Sent history exists?": {
      "main": [
        [],
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize - Email Payload": {
      "main": [
        [
          {
            "node": "IF - Ignore Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger - New Emails": {
      "main": [
        [
          {
            "node": "Config - Rules & Thresholds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Extract Sender Email": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Rules & Thresholds": {
      "main": [
        [
          {
            "node": "Normalize - Email Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF - Found in Reply History?": {
      "main": [
        [],
        [
          {
            "node": "Gmail - Search Sent to Sender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail - Search Sent to Sender": {
      "main": [
        [
          {
            "node": "IF - Sent history exists?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}