{
  "name": "AI Email Classifier with Labels",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [{"mode": "everyMinute"}]
        },
        "filters": {
          "readStatus": "unread"
        },
        "simple": true
      },
      "id": "b6c7d8e9-f0a1-2345-bcde-456789013bc9",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.1,
      "position": [250, 300]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "Classify the following email into exactly one category: URGENT, SALES, SUPPORT, NEWSLETTER, SPAM. Reply with only the category name, nothing else."
            },
            {
              "role": "user",
              "content": "=From: {{ $json.from }}\nSubject: {{ $json.subject }}\nBody: {{ $json.snippet }}"
            }
          ]
        },
        "options": {
          "maxTokens": 20,
          "temperature": 0
        }
      },
      "id": "c7d8e9f0-a1b2-3456-cdef-567890124cd0",
      "name": "OpenAI Classify",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.2,
      "position": [500, 300]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.choices[0].message.content.trim() }}",
              "operation": "equals",
              "value2": "URGENT"
            }
          ]
        }
      },
      "id": "d8e9f0a1-b2c3-4567-defa-678901235de1",
      "name": "Is Urgent",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [750, 300]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "labelIds": ["IMPORTANT"]
      },
      "id": "e9f0a1b2-c3d4-5678-efab-789012346ef2",
      "name": "Label as Urgent",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1000, 200]
    },
    {
      "parameters": {
        "chatId": "your-chat-id",
        "text": "=🚨 *Urgent Email Received*\n\nFrom: {{ $('Gmail Trigger').item.json.from }}\nSubject: {{ $('Gmail Trigger').item.json.subject }}\n\nClassification: {{ $('OpenAI Classify').item.json.choices[0].message.content }}",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "f0a1b2c3-d4e5-6789-fabc-890123457fa3",
      "name": "Telegram Alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [1250, 200]
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [[{"node": "OpenAI Classify", "type": "main", "index": 0}]]
    },
    "OpenAI Classify": {
      "main": [[{"node": "Is Urgent", "type": "main", "index": 0}]]
    },
    "Is Urgent": {
      "main": [
        [{"node": "Label as Urgent", "type": "main", "index": 0}],
        []
      ]
    },
    "Label as Urgent": {
      "main": [[{"node": "Telegram Alert", "type": "main", "index": 0}]]
    }
  },
  "settings": {"executionOrder": "v1"},
  "staticData": null,
  "tags": []
}
