{
  "name": "Automatic Gmail categorization and labeling with AI",
  "nodes": [
    {
      "id": "9f0e4edb-32cc-45bf-96d8-91d76506b9e7",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -816,
        0
      ]
    },
    {
      "id": "90c625c4-8b88-40a0-8ff1-293b5950aa85",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -592,
        0
      ]
    },
    {
      "id": "75af6c6b-9706-42ed-985a-a763ea3e3473",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -336,
        224
      ]
    },
    {
      "id": "d6d8026a-1b11-40e4-8d30-94d4a7287848",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1264,
        0
      ]
    },
    {
      "id": "464eae52-c683-43ff-8a4f-25d3acba5a93",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -592,
        224
      ]
    },
    {
      "id": "954ce5bb-495c-459c-981c-3bcdb0066308",
      "name": "Get All Unread Messages",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1040,
        0
      ]
    },
    {
      "id": "f71f88be-77aa-4dbb-bbdc-607ebfc3ddc7",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -128,
        -32
      ]
    },
    {
      "id": "16c60f51-2387-4f43-92d5-ada08840b97e",
      "name": "OpenAI Fall Back Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -464,
        224
      ]
    },
    {
      "id": "29f90ac4-d629-493c-a825-98c72bd77399",
      "name": "Delete email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        96,
        288
      ]
    },
    {
      "id": "90629ef6-75ba-499b-a27d-b47bde3deadb",
      "name": "Mark email as read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        -64
      ]
    },
    {
      "id": "8ed659e1-293c-49d2-ad24-0bb8d0fe30ec",
      "name": "Add label \"Receipt\" to email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        96,
        96
      ]
    },
    {
      "id": "42fa8db1-b003-415b-bf06-9f18b9823faa",
      "name": "Add label \"Action\" to email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        96,
        -288
      ]
    },
    {
      "id": "690d7e73-c97e-467b-aafe-e4acb552f188",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1320,
        -144
      ],
      "parameters": {
        "width": 208,
        "height": 304,
        "content": "### 💡 Schedule Trigger\nThis runs every hour. You can change the interval here depending on how often you want your Gmail to be processed."
      }
    },
    {
      "id": "967d2796-e9ce-4dfa-90cb-948d1b573185",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1312,
        256
      ],
      "parameters": {
        "width": 304,
        "height": 224,
        "content": "### ⚠️ Setup Required\n- Connect your Gmail account using OAuth2. \n- Add your OpenAI API Key under “API Credentials”.\n- Create these labels in your Gmail: Action, Informational, Spam and Receipt"
      }
    },
    {
      "id": "06f7f246-155b-4b2d-86c0-0ecb86e84d3c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -160
      ],
      "parameters": {
        "width": 432,
        "height": 320,
        "content": "### 💡 Customize Classification Logic\nYou can change the prompt to match your context. For example, tell the AI to detect more labels like `Meeting`, `Newsletter`, etc."
      }
    },
    {
      "id": "61d814b5-f734-43a1-a588-c4722a0fd60c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -200,
        -160
      ],
      "parameters": {
        "width": null,
        "height": 352,
        "content": "### 💡 Add More Labels\nWant to detect  `Meeting`, `Newsletter`, etc?\nAdd more conditions here and route them to different Gmail actions."
      }
    },
    {
      "id": "011af85b-feb4-495d-8382-c42fdc5ff7c4",
      "name": "Add label \"Informational\" to email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        96,
        -96
      ]
    }
  ],
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Add label \"Action\" to email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add label \"Informational\" to email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add label \"Receipt\" to email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete email": {
      "main": [
        []
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get All Unread Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Fall Back Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 1
          }
        ]
      ]
    },
    "Get All Unread Messages": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Add label \"Action\" to email": {
      "main": [
        [
          {
            "node": "Mark email as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add label \"Receipt\" to email": {
      "main": [
        [
          {
            "node": "Mark email as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add label \"Informational\" to email": {
      "main": [
        [
          {
            "node": "Mark email as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}