{
  "nodes": [
    {
      "id": "8093dfbb-4bd3-4061-b658-9cac48c21979",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -704,
        -128
      ],
      "parameters": {
        "width": 540,
        "height": 532,
        "content": "## AI support ticket router\n\nAutomatically categorize, prioritize, and route incoming support emails to the right Notion database with AI-powered analysis.\n\n### How it works\n1. A Gmail trigger watches for new emails with a specific label or to a support address.\n2. Gemini AI analyzes the email content to determine category, priority, and suggested response.\n3. A new page is created in your Notion support database with all extracted fields.\n4. High-priority tickets trigger an immediate Slack notification to the on-call team.\n5. A summary of all new tickets is sent to Slack at the end of each batch.\n\n### Setup steps\n1. Add your **Gmail OAuth2** credential and configure the label or filter.\n2. Add a **Google Gemini API** credential for email analysis.\n3. Add a **Notion API** credential and set up a database with columns: Title, Category, Priority, Status, Summary, Suggested Response.\n4. Add a **Slack OAuth2** credential and set your alerts channel.\n5. Activate the workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "1282fa8f-cebe-4279-a7fd-b24a6834d5ed",
      "name": "Intake section note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 316,
        "content": "## Email intake\nFetches new support emails and extracts the message body and metadata."
      },
      "typeVersion": 1
    },
    {
      "id": "b8ed4673-f05f-46a0-a296-293f4d3546ac",
      "name": "AI section note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        352,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 428,
        "height": 524,
        "content": "## AI analysis\nGemini classifies the ticket by category, priority, and drafts a response."
      },
      "typeVersion": 1
    },
    {
      "id": "ef547c95-755f-4255-9cdb-eb4f1c5700f4",
      "name": "Route section note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 696,
        "height": 524,
        "content": "## Route and notify\nCreates a Notion page and alerts the team on Slack for urgent issues."
      },
      "typeVersion": 1
    },
    {
      "id": "d7809ff2-d976-43a5-927a-43df001e3101",
      "name": "Watch for support emails",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -80,
        32
      ],
      "parameters": {
        "filters": {
          "includeSpamTrash": false
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ef5d2905-ab55-4ce0-a711-5b65e84135c1",
      "name": "Extract email fields",
      "type": "n8n-nodes-base.set",
      "position": [
        144,
        32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "emailFrom",
              "type": "string",
              "value": "={{ $json.from.text }}"
            },
            {
              "id": "2",
              "name": "emailSubject",
              "type": "string",
              "value": "={{ $json.subject }}"
            },
            {
              "id": "3",
              "name": "emailBody",
              "type": "string",
              "value": "={{ $json.text || $json.snippet }}"
            },
            {
              "id": "4",
              "name": "emailDate",
              "type": "string",
              "value": "={{ $json.date }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6132733a-0a44-4013-8bfc-36ed5361947d",
      "name": "Classify ticket with AI",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        416,
        32
      ],
      "parameters": {
        "text": "=Analyze this support email and classify it.\n\nFrom: {{ $json.emailFrom }}\nSubject: {{ $json.emailSubject }}\nBody: {{ $json.emailBody }}\n\nProvide:\n1. Category: billing / technical / feature-request / general\n2. Priority: critical / high / medium / low\n3. Summary: 1-2 sentence summary\n4. Suggested response: A brief professional reply draft\n\nOutput as JSON with keys: category, priority, summary, suggestedResponse",
        "promptType": "define"
      },
      "typeVersion": 1.4
    },
    {
      "id": "da296250-9e63-4b63-9b1c-34eeb1c2bffc",
      "name": "Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        416,
        272
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "typeVersion": 1
    },
    {
      "id": "5a7b7b21-d6ed-440e-9ef8-869141d989e1",
      "name": "Parse AI classification",
      "type": "n8n-nodes-base.code",
      "position": [
        672,
        32
      ],
      "parameters": {
        "jsCode": "// Parse AI classification\nvar response = $input.first().json.response || $input.first().json.text || '{}';\nvar email = $('Extract email fields').first().json;\nvar parsed;\ntry { parsed = JSON.parse(response); } catch(e) { parsed = {category:'general',priority:'medium',summary:response.substring(0,200),suggestedResponse:''}; }\nreturn { json: Object.assign({}, email, parsed) };"
      },
      "typeVersion": 2
    },
    {
      "id": "1f22c3f4-dbdb-4713-a085-fc09ed65b738",
      "name": "Create ticket in Notion",
      "type": "n8n-nodes-base.notion",
      "position": [
        864,
        32
      ],
      "parameters": {
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "938e99c2-cf13-47e8-b3d1-cbcfe5018ced",
      "name": "Is critical priority",
      "type": "n8n-nodes-base.if",
      "position": [
        1088,
        32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.priority }}",
              "rightValue": "critical"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "71bc2550-301c-4d52-a47f-5bc1278e0c72",
      "name": "Alert team on Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1296,
        -48
      ],
      "parameters": {
        "text": "=:rotating_light: *CRITICAL TICKET*\n*From:* {{ $json.emailFrom }}\n*Subject:* {{ $json.emailSubject }}\n*Summary:* {{ $json.summary }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "otherOptions": {}
      },
      "typeVersion": 2.3
    },
    {
      "id": "758e1533-8d1e-458b-ac87-0d7dae8eb45f",
      "name": "Post ticket summary to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1296,
        176
      ],
      "parameters": {
        "text": "=New ticket logged: *{{ $json.emailSubject }}* ({{ $json.priority }})",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "otherOptions": {}
      },
      "typeVersion": 2.3
    }
  ],
  "connections": {
    "Google Gemini": {
      "ai_languageModel": [
        [
          {
            "node": "Classify ticket with AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Extract email fields": {
      "main": [
        [
          {
            "node": "Classify ticket with AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is critical priority": {
      "main": [
        [
          {
            "node": "Alert team on Slack",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Post ticket summary to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify ticket with AI": {
      "main": [
        [
          {
            "node": "Parse AI classification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create ticket in Notion": {
      "main": [
        [
          {
            "node": "Is critical priority",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI classification": {
      "main": [
        [
          {
            "node": "Create ticket in Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Watch for support emails": {
      "main": [
        [
          {
            "node": "Extract email fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}