{
  "name": "AI Email Classifier & Slack Router",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {}
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        -464,
        -144
      ],
      "id": "44fe1021-58fc-498f-806a-f0553d9eb17f",
      "name": "Gmail Trigger",
      "credentials": {
        "gmailOAuth2": {
          "id": "LBIbVskaBzVhN0SE",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You are an email classification engine.  \nYour job is to read any incoming email content and classify it into ONE of the following categories:\n\n1. Support  \n2. Sales  \n3. Service  \n4. General Inquiry  \n5. Billing  \n6. HR / Careers  \n\nRules:\n- Always return ONLY the category name (e.g., \"Support\").\n- Do not provide explanations.\n- If the email fits multiple categories, choose the most dominant intent.\n- If no clear category matches, default to \"General Inquiry\".\n\nOutput Format:\n{\n  \"category\":\"\"\n}\n\nHere is Email Content:\n{{ $json.snippet }}",
        "hasOutputParser": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        -240,
        -144
      ],
      "id": "53b97268-03ff-4086-bd57-7e16c3afd79b",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        -240,
        80
      ],
      "id": "e7d130d8-554d-47c9-84ea-845169eb63af",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "UFoXLJTyZlrIERe4",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"category\":\"\"\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        -96,
        80
      ],
      "id": "5774701b-d9ad-4d2e-8ddc-84f76d9f50eb",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "General Inquiry",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "5d7b0091-04ce-4652-b3fb-84d0f7799d3c"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "General Inquiry"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "e7b740a2-6bab-40a0-808c-9a21ac0d5901",
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "Support",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Support"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "cbee5cfa-1527-45fd-9181-757abac705ed",
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "Sales",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Sales"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "d6e6b958-f833-4507-ae8f-b014e710974c",
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "Service",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Service"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "9b823d44-7696-4267-9c43-b2e727dcfb0f",
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "Billing",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Billing"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "5554c6c8-550e-4c4c-9001-2752eca45536",
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "HR / Careers",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "HR / Careers"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        32,
        -208
      ],
      "id": "4854134d-a275-4c3a-b427-91ff5b9b3975",
      "name": "Switch"
    },
    {
      "parameters": {
        "select": "user",
        "user": {
          "__rl": true,
          "value": "U08Q8UGPSAJ",
          "mode": "list",
          "cachedResultName": "forgent_systems"
        },
        "text": "=A General Inquiry email has been received from {{ $('Gmail Trigger').item.json.From }}. Message preview: '{{ $('Gmail Trigger').item.json.snippet }}'",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        304,
        -384
      ],
      "id": "d94822e9-c141-4ebf-bc9f-b93226291b2c",
      "name": "General Inquiry",
      "webhookId": "b2a72746-26d0-45e1-9852-fa8c5cb2bced",
      "credentials": {
        "slackApi": {
          "id": "R4nnpqtlL26ynf4r",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "select": "user",
        "user": {
          "__rl": true,
          "value": "U08Q8UGPSAJ",
          "mode": "list",
          "cachedResultName": "forgent_systems"
        },
        "text": "=You have received a new Support email from {{ $('Gmail Trigger').item.json.From }}. Please review the message: '{{ $('Gmail Trigger').item.json.snippet }}'.",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        576,
        -304
      ],
      "id": "168610ed-3d87-4437-816b-c0b4064eb7fa",
      "name": "Support",
      "webhookId": "b2a72746-26d0-45e1-9852-fa8c5cb2bced",
      "credentials": {
        "slackApi": {
          "id": "R4nnpqtlL26ynf4r",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "select": "user",
        "user": {
          "__rl": true,
          "value": "U08Q8UGPSAJ",
          "mode": "list",
          "cachedResultName": "forgent_systems"
        },
        "text": "=You have received a new Sales inquiry from {{ $('Gmail Trigger').item.json.From }}. Message preview: '{{ $('Gmail Trigger').item.json.snippet }}'.",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        720,
        -192
      ],
      "id": "08a85f1a-0324-43e2-8149-7ce3533e01b3",
      "name": "Sales",
      "webhookId": "b2a72746-26d0-45e1-9852-fa8c5cb2bced",
      "credentials": {
        "slackApi": {
          "id": "R4nnpqtlL26ynf4r",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "select": "user",
        "user": {
          "__rl": true,
          "value": "U08Q8UGPSAJ",
          "mode": "list",
          "cachedResultName": "forgent_systems"
        },
        "text": "=You have received a new Service request from {{ $('Gmail Trigger').item.json.From }}. Please check the details: '{{ $('Gmail Trigger').item.json.snippet }}'.",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        704,
        -32
      ],
      "id": "65f86bf9-49dc-45b9-8c83-962cf39ae66f",
      "name": "Service",
      "webhookId": "b2a72746-26d0-45e1-9852-fa8c5cb2bced",
      "credentials": {
        "slackApi": {
          "id": "R4nnpqtlL26ynf4r",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "select": "user",
        "user": {
          "__rl": true,
          "value": "U08Q8UGPSAJ",
          "mode": "list",
          "cachedResultName": "forgent_systems"
        },
        "text": "=You have received a new Billing-related email from {{ $('Gmail Trigger').item.json.From }}. \nDetails: '{{ $('Gmail Trigger').item.json.snippet }}'.",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        464,
        64
      ],
      "id": "2f4a3481-17ed-4416-aab6-282b4de92cc7",
      "name": "Billing",
      "webhookId": "b2a72746-26d0-45e1-9852-fa8c5cb2bced",
      "credentials": {
        "slackApi": {
          "id": "R4nnpqtlL26ynf4r",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "select": "user",
        "user": {
          "__rl": true,
          "value": "U08Q8UGPSAJ",
          "mode": "list",
          "cachedResultName": "forgent_systems"
        },
        "text": "=A new HR / Careers email has been received from {{ $('Gmail Trigger').item.json.From }}. \nPlease review: '{{ $('Gmail Trigger').item.json.snippet }}'.",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        304,
        160
      ],
      "id": "ac3513f2-790e-44cc-860d-ae5ef7a9b485",
      "name": "HR / Careers",
      "webhookId": "b2a72746-26d0-45e1-9852-fa8c5cb2bced",
      "credentials": {
        "slackApi": {
          "id": "R4nnpqtlL26ynf4r",
          "name": "Slack account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "General Inquiry",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Support",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sales",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Service",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Billing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HR / Careers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "494d4f90-1eb5-4968-a655-cfecd6cbb00c",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "f1c26778ec36097a9722a22c47c5e9c01f00b8862dadd0121ec118026a370fa6"
  },
  "id": "B2TnQw2anmLm71XZ",
  "tags": []
}