{
  "name": "AI email triage: classify Gmail, label it and alert Slack for urgent mail",
  "nodes": [
    {
      "parameters": {
        "content": "## AI email triage\nEvery new email is classified by an AI model into: sales, support, billing, urgent, other.\nUrgent mail is posted to Slack.\n1. Connect Gmail, OpenAI and Slack\n2. Create Gmail labels with the same names\n\nBuilt by SixSol Technologies · sixsol.co.uk",
        "height": 300,
        "width": 420
      },
      "id": "e0a9bd34-eb16-5371-a55c-69a415ff9a46",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        -280
      ]
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": true,
        "filters": {
          "readStatus": "unread"
        },
        "options": {}
      },
      "id": "73fcf7d2-0055-5084-884d-d52a5d2f01a7",
      "name": "New email",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        80
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "temperature": 0
        }
      },
      "id": "3370b6bf-c30c-5929-9e18-fbc40b545b77",
      "name": "OpenAI model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        220,
        280
      ]
    },
    {
      "parameters": {
        "inputText": "=Subject: {{ $json.Subject }}\nFrom: {{ $json.From }}\n\n{{ $json.snippet }}",
        "categories": {
          "categories": [
            {
              "category": "sales",
              "description": "New business enquiries, quotes, partnerships"
            },
            {
              "category": "support",
              "description": "Existing customers asking for help"
            },
            {
              "category": "billing",
              "description": "Invoices, payments, refunds"
            },
            {
              "category": "urgent",
              "description": "Outages, legal notices, anything needing action today"
            },
            {
              "category": "other",
              "description": "Newsletters and everything else"
            }
          ]
        },
        "options": {}
      },
      "id": "1ea482cd-c25a-57f7-8a80-97f833cb553c",
      "name": "Classify email",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "typeVersion": 1,
      "position": [
        220,
        80
      ]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "sales"
        ]
      },
      "id": "2fd3b5cf-6935-5550-94fe-6e41e917dc80",
      "name": "Label sales",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        560,
        -120
      ]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "support"
        ]
      },
      "id": "1c98f83e-fc75-59c0-82b3-03a85e32912f",
      "name": "Label support",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        560,
        -20
      ]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "billing"
        ]
      },
      "id": "28d460d6-0ce3-5818-bd06-04f7db471537",
      "name": "Label billing",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        560,
        80
      ]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "urgent"
        ]
      },
      "id": "b0e55e47-163d-5b7d-97e0-bfcc76b032c3",
      "name": "Label urgent",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        560,
        180
      ]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "other"
        ]
      },
      "id": "52f89003-ca26-507d-bdd5-c03b28aa48c5",
      "name": "Label other",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        560,
        280
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#urgent"
        },
        "text": "=:rotating_light: Urgent email from {{ $('New email').item.json.From }}: {{ $('New email').item.json.Subject }}",
        "otherOptions": {}
      },
      "id": "c4f69f56-08ad-5efe-bba3-675fe3ace63d",
      "name": "Alert Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        780,
        80
      ]
    }
  ],
  "connections": {
    "New email": {
      "main": [
        [
          {
            "node": "Classify email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label urgent": {
      "main": [
        [
          {
            "node": "Alert Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI model": {
      "ai_languageModel": [
        [
          {
            "node": "Classify email",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Classify email": {
      "main": [
        [
          {
            "node": "Label sales",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label support",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label billing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label urgent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label other",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "templateBy": "SixSol Technologies · https://www.sixsol.co.uk/n8n-templates/"
  },
  "tags": []
}