{
  "name": "Email Classifier",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        },
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        -2576,
        -272
      ],
      "id": "20b300ea-32d7-4434-8e6c-3348f5fe867e",
      "name": "Gmail Trigger",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "text": "={{ $json.from.value[0].name }}",
        "attributes": {
          "attributes": [
            {
              "name": "senderName",
              "description": "Extract the sender's name from the email. If the name is not available, return an empty string.",
              "required": true
            }
          ]
        },
        "options": {
          "systemPromptTemplate": "You are an information extraction expert. Your task is to extract only the values of the defined attributes from the provided email text. \n\nFollow these strict rules:\n\n1. Output only the requested attributes.\n2. If an attribute cannot be confidently extracted, return an empty string \"\".\n3. Ignore greetings, signatures, disclaimers, and quoted replies.\n4. Normalize spacing and capitalization when applicable.\n5. Do not include commentary, formatting, or metadata.\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1,
      "position": [
        -2320,
        -272
      ],
      "id": "68e6e644-9a54-48e0-a712-b183f03d1c1c",
      "name": "Information Extractor"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d374039-a5c3-4047-b19c-4d05f485cceb",
              "name": "introduction",
              "value": "={{ $json.senderName ? 'Hi ' + $json.senderName + ',' : 'Hi,' }}",
              "type": "string"
            },
            {
              "id": "eafcf4be-81e1-42af-83e7-1407680585fc",
              "name": "emailBody",
              "value": "={{ $('Gmail Trigger').item.json.text || $('Gmail Trigger').item.json.html }}",
              "type": "string"
            },
            {
              "id": "0f9e0296-2c71-47d9-a526-b29ca30a41d2",
              "name": "messageId",
              "value": "={{ $('Gmail Trigger').item.json.id }}",
              "type": "string"
            },
            {
              "id": "ea2e0681-abb6-49ae-92f5-aa08f6c1cb79",
              "name": "threadId",
              "value": "={{ $('Gmail Trigger').item.json.threadId }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2000,
        -272
      ],
      "id": "3681230f-adde-4fea-9d11-d53402ef734c",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "inputText": "={{ $json.emailBody }}",
        "categories": {
          "categories": [
            {
              "category": "Promo Requests",
              "description": "Includes inquiries about services, pricing, availability, or related details."
            },
            {
              "category": "Consultation Requests",
              "description": "Includes scheduling for consultations or follow-up appointments."
            },
            {
              "category": "Paid Partnerships",
              "description": "Inquiries about paid collab, or payments."
            },
            {
              "category": "Miscellaneous",
              "description": "Emails that don't fall into any of the predefined categories."
            }
          ]
        },
        "options": {
          "systemPromptTemplate": "Please classify the email into one of the following categories: {categories}. Return only the category name without explanations."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "typeVersion": 1,
      "position": [
        -1792,
        -288
      ],
      "id": "5dc901fe-5f0a-4cd7-a850-f0a299339276",
      "name": "Text Classifier"
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $json.messageId }}",
        "labelIds": [
          "Label_7858554699367144904"
        ]
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1232,
        -608
      ],
      "id": "a00d34e9-3246-4a33-b47b-6274d6adf88b",
      "name": "Gmail - Promo Requests",
      "webhookId": "154a7a70-0134-4540-a301-8c3fecdb8c24",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $json.messageId }}",
        "labelIds": [
          "Label_110022967880251869"
        ]
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1232,
        -416
      ],
      "id": "39d89713-17c8-4408-900a-4b5f09f85594",
      "name": "Gmail - Consultation Requests",
      "webhookId": "d322d556-21b0-43f8-b5e0-7a396ac42bbb",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $json.messageId }}",
        "labelIds": [
          "Label_8334621015717235015"
        ]
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1232,
        -240
      ],
      "id": "20f58715-8e24-4cbf-9e9e-839fc587f795",
      "name": "Gmail - Paid Partnerships",
      "webhookId": "eb375802-3bdc-487e-997b-d3c0ccb73cf0",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $json.messageId }}",
        "labelIds": [
          "Label_1825873107401641000"
        ]
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1232,
        -48
      ],
      "id": "591d8fb2-9d90-42e1-b372-83a2376c7990",
      "name": "Gmail - Miscellaneous",
      "webhookId": "c115b16f-710f-4249-9b02-748ce708a06c",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "operation": "reply",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "emailType": "text",
        "message": "={{ $('Edit Fields').item.json.introduction }}\n\nThanks for reaching out! Got your message and I'm checking the details. I'll get back to you within 24 hours with more info.\n\nIf you want to get a better idea of what I do, feel free to look through my work or just ping me directly on WhatsApp.\n\nTalk soon,  \nArthur Duboks",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1008,
        -608
      ],
      "id": "097d0a0b-0479-4782-90e0-80554293a671",
      "name": "Gmail Reply - Promo",
      "webhookId": "f87f9624-5f94-4713-86cb-eb0aa301e97b",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "operation": "reply",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "emailType": "text",
        "message": "={{ $('Edit Fields').item.json.introduction }}\n\nAppreciate you getting in touch. To lock in a quick consultation, just reply with a date and time that works for you.\n\nOnce I get that, I'll confirm or send over a few other options. If there's anything specific you want to cover, mention it in your reply so I can prep.\n\nCatch you soon,  \nArthur Duboks",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1008,
        -416
      ],
      "id": "aa669c38-6997-4005-9b27-4c4899125b12",
      "name": "Gmail Reply - Consultation",
      "webhookId": "10b1e65b-e032-4434-a6b8-5e9acde9adbb",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "operation": "reply",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "emailType": "text",
        "message": "={{ $('Edit Fields').item.json.introduction }}\n\nGot your message about the collab or billing. I'll follow up within the next couple of days with the info you need.\n\nIf it's urgent, text or call me directly.\n\nThanks for the patience,  \nArthur Duboks",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1008,
        -240
      ],
      "id": "79784553-7b0a-4ab2-b40e-3080ce6d66ef",
      "name": "Gmail Reply - Partnership",
      "webhookId": "79b3172b-d844-4bdc-8a2b-b9f354da348a",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1712,
        -48
      ],
      "id": "1f6482cd-7cb5-4486-88be-b2606ae3934b",
      "name": "Classifier Model",
      "credentials": {
        "openAiApi": {
          "id": "k5U1eg8rX3bZ3NQs",
          "name": "Openai n8n v2(new)"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -2464,
        -80
      ],
      "id": "a0d78852-5134-437b-bc3f-e2bf637ffa82",
      "name": "Extractor Model",
      "credentials": {
        "openAiApi": {
          "id": "k5U1eg8rX3bZ3NQs",
          "name": "Openai n8n v2(new)"
        }
      }
    },
    {
      "parameters": {},
      "id": "7af2947c-0b77-4452-a58d-d5740dbcbf14",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -1232,
        144
      ]
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "sendTo": "admin@example.com",
        "subject": "Email Classifier Error",
        "message": "=An error occurred in the Email Classifier workflow:\n\n{{ $json.execution.error.message }}\n\nWorkflow: {{ $json.execution.workflowName }}\nNode: {{ $json.execution.error.node }}\nTime: {{ $json.execution.error.timestamp }}",
        "options": {}
      },
      "id": "423cc506-c0b8-4f54-945b-ddff8e108784",
      "name": "Error Notification",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -1008,
        -48
      ],
      "webhookId": "d4b8a647-598a-4894-91fc-1a97a99536c3",
      "credentials": {
        "gmailOAuth2": {
          "id": "ZXQ8cZ47OjoEE0yX",
          "name": "Arthur's Gmail New"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "Gmail - Promo Requests",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gmail - Consultation Requests",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gmail - Paid Partnerships",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gmail - Miscellaneous",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail - Promo Requests": {
      "main": [
        [
          {
            "node": "Gmail Reply - Promo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail - Consultation Requests": {
      "main": [
        [
          {
            "node": "Gmail Reply - Consultation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail - Paid Partnerships": {
      "main": [
        [
          {
            "node": "Gmail Reply - Partnership",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classifier Model": {
      "ai_languageModel": [
        [
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Extractor Model": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Error Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "73427e16-d72b-44eb-a90f-172bdeff57c1",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "38edd013683a72cdea94ebb838f500db805b82fc90433e51c371cee8ce15281b"
  },
  "id": "Xgi0oPdcrfB78rUr",
  "tags": [
    {
      "updatedAt": "2025-07-08T17:25:50.659Z",
      "createdAt": "2025-07-08T17:25:50.659Z",
      "id": "U5gWkGVtR70dqQ83",
      "name": "Arthur's Content"
    }
  ]
}