{
  "name": "AI-powered email support router with Gmail, ChatGPT-4o, and Slack",
  "nodes": [
    {
      "id": "254da1f8-b8e6-44fb-b526-fa8f4181e3fd",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1248,
        144
      ]
    },
    {
      "id": "a6929e80-8db0-4c8a-83b1-345f68b5d2bc",
      "name": "Send a message",
      "type": "n8n-nodes-base.slack",
      "position": [
        0,
        0
      ]
    },
    {
      "id": "5e546936-0738-4260-9d7a-cabdf09869bf",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -560,
        160
      ]
    },
    {
      "id": "bcbca08b-7d32-4f62-b543-bfb4c15e260c",
      "name": "Create a row",
      "type": "n8n-nodes-base.supabase",
      "position": [
        256,
        160
      ]
    },
    {
      "id": "a3a48ec5-5578-43f7-ae99-3c6785f090f7",
      "name": "Get a row",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1040,
        144
      ]
    },
    {
      "id": "fcae3538-c417-4f84-ac3b-f95bcc7fb4e5",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -832,
        144
      ]
    },
    {
      "id": "6c8fbfa6-e0e1-461f-8c53-c2741e36090b",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -208,
        160
      ]
    },
    {
      "id": "34441930-fdd6-49dd-8b04-f43f9f6831c9",
      "name": "Mark a message as read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        464,
        160
      ]
    },
    {
      "id": "92d379d7-81e2-41d5-a927-1a8d3ad314ab",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        -80
      ],
      "parameters": {
        "width": 224,
        "height": 192,
        "content": "## 1. Gmail Trigger\n📬 Triggers whenever a new unread email arrives in the connected Gmail inbox.\n\n➡️ Sends email data (From, Subject, Snippet, Thread ID, etc.) to the next node."
      }
    },
    {
      "id": "14d334bf-cc9d-414a-a026-833ad0e00bd1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        -48
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "## 2. Get a row (Supabase) \n🔍 Checks Supabase table “threads” to see if this email thread already exists."
      }
    },
    {
      "id": "d941485f-c582-450d-a55e-364dbeda6127",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        -48
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "## 3. IF Node\n❓Decision point:\n\t•\tIf thread exists, stop (no duplicate processing).\n\t•\tIf thread does not exist, continue workflow."
      }
    },
    {
      "id": "ad5020dc-fe2a-46b1-b179-4f5dd0f20668",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        -80
      ],
      "parameters": {
        "width": 256,
        "height": 192,
        "content": "## 4. Message a Model (OpenAI)\n🧠 Sends the email subject and snippet to ChatGPT (4o) to classify the email into a category:\nsupport | new-request | enquiry | general | spam | other"
      }
    },
    {
      "id": "4cf815f4-70ca-4bd9-a2ee-af021df944a6",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -80
      ],
      "parameters": {
        "width": null,
        "height": 192,
        "content": "## 5. Switch\n🔀 Routes the email based on the category returned by ChatGPT:\n\t•\tIf “support” → send to #support channel.\n\t•\tIf “new-request” → send to #new-requests channel.\n"
      }
    },
    {
      "id": "b8f9c6ea-61a9-4be2-a4a0-29d90caa8cf6",
      "name": "Send a message 2",
      "type": "n8n-nodes-base.slack",
      "position": [
        0,
        256
      ]
    },
    {
      "id": "3fe1a77a-3feb-49a6-8941-1ab666bf6cc5",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -240
      ],
      "parameters": {
        "width": null,
        "height": 208,
        "content": "## 6. Send a Message (Slack)\n💬 Posts formatted message in the #support Slack channel:\n\n“New support request received from [email]. Subject: […]. Content: […]”"
      }
    },
    {
      "id": "3f4a8b97-9b38-4de8-8a51-e023b43a493f",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        416
      ],
      "parameters": {
        "width": 256,
        "height": 208,
        "content": "## 7. Send a Message 2 (Slack)\n💬 Posts formatted message in the #new-requests Slack channel:\n\n“New request received from [email]. Subject: […]. Content: […]”"
      }
    },
    {
      "id": "5a3324e6-ab62-465d-8854-54c2cf59098d",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -64
      ],
      "parameters": {
        "width": null,
        "height": 192,
        "content": "## 8. Create a Row (Supabase)\n🗃️ Adds a new record in the “threads” table:\nStores thread_id, first_message_id, from_addr, subject for future deduplication."
      }
    },
    {
      "id": "665325de-a9fb-4440-95b0-a1c197d79053",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        -32
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "## 9. Mark a Message as Read (Gmail)\n✅ Marks the email as read in Gmail once it’s processed and saved."
      }
    }
  ],
  "connections": {
    "If": {
      "main": [
        [],
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a message 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a row": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a row": {
      "main": [
        [
          {
            "node": "Mark a message as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Get a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        [
          {
            "node": "Create a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message 2": {
      "main": [
        [
          {
            "node": "Create a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}