{
  "name": "Gmail Inbox Classifier",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {},
        "options": {}
      },
      "id": "d8fa37f4-510a-4ab4-92fa-96ddd07c917f",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        0
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "RECONNECT_GMAIL_CREDENTIAL"
        }
      }
    },
    {
      "parameters": {
        "text": "={{ $json.text }}",
        "attributes": {
          "attributes": [
            {
              "name": "senderName",
              "description": "Extract the sender's name from this email. Return an empty string if there is no name."
            }
          ]
        },
        "options": {
          "systemPromptTemplate": "You are an expert extraction algorithm.\nOnly extract relevant information from the text.\nIf you do not know the value of an attribute asked to extract, you may omit the attribute's value."
        }
      },
      "id": "b110c0f3-2839-4ccc-8509-4d196f95750c",
      "name": "Information Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        208,
        0
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "40023931-2123-43cf-86ec-6bbe0f0dd3b5",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        144,
        208
      ],
      "credentials": {
        "openAiApi": {
          "id": null,
          "name": "",
          "__aiGatewayManaged": true
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "604fb3e2-d9a0-4e24-8b6b-285b8c2dfcce",
              "leftValue": "={{ $json.output.senderName }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "575afa98-b764-448e-bc3c-03705d66d0d6",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        560,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6b4ca93a-714c-4d3b-8328-f7ca187e67b7",
              "name": "intro",
              "value": "={{ $json.output.senderName }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "67d4d25d-de39-436d-8776-67b78232ee5f",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        768,
        -96
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6b4ca93a-714c-4d3b-8328-f7ca187e67b7",
              "name": "intro",
              "value": "=Hi,",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "ebe260fe-6768-4cf1-9cb1-fb2b99711cac",
      "name": "EDIT(If not)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        768,
        80
      ]
    },
    {
      "parameters": {},
      "id": "35b0af93-14e5-4699-8c8f-e7c20cbaa76d",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        992,
        -80
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "aa97af25-23c5-4615-a89f-f150c668f257",
              "name": "messageid",
              "value": "={{ $('Gmail Trigger').item.json.id }}",
              "type": "string"
            },
            {
              "id": "be8fadf4-6844-4cec-8bff-3d8f282a0e93",
              "name": "intro",
              "value": "={{ $json.intro }}",
              "type": "string"
            },
            {
              "id": "214e51fc-f7c3-400b-bbf3-dacc6746838c",
              "name": "threadId",
              "value": "={{ $('Gmail Trigger').item.json.threadId }}",
              "type": "string"
            },
            {
              "id": "0c113142-bac9-4eb5-a389-69e3b4db5500",
              "name": "text",
              "value": "={{ $('Gmail Trigger').item.json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "fbce19d8-9177-45a9-bdf6-3fb3602a50b8",
      "name": "Clean data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        1200,
        -80
      ]
    },
    {
      "parameters": {
        "inputText": "={{ $json.text }}",
        "categories": {
          "categories": [
            {
              "category": "Service Requests",
              "description": "Questions about services offered, rates or availability."
            },
            {
              "category": "Payments",
              "description": "Questions about Invoices, payments or refunds."
            },
            {
              "category": "Consultation Requests",
              "description": "Scheduling initial consultations or follow-up meetings."
            },
            {
              "category": "Others",
              "description": "Emails that don't clearly fit into any category."
            }
          ]
        },
        "options": {
          "systemPromptTemplate": "Please classify the text provided by the user into one of the following categories: {categories}, and use the provided formatting instructions below. Don't explain, and only output the json."
        }
      },
      "id": "73c27f40-45b8-40c0-9bc1-51de0155f50c",
      "name": "Text Classifier",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "typeVersion": 1.1,
      "position": [
        1408,
        -112
      ],
      "retryOnFail": true,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "438e805d-ef6b-4101-8ca3-97ffaee044df",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        1312,
        128
      ],
      "credentials": {
        "openAiApi": {
          "id": null,
          "name": "",
          "__aiGatewayManaged": true
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "labelIds": [
          "RECONNECT_SERVICE_REQUEST_LABEL"
        ]
      },
      "id": "a9d10da5-929c-4dc6-8486-ac2f251b9b54",
      "name": "ServiceReq Label",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1824,
        -352
      ],
      "webhookId": "RECONNECT_GMAIL_LABEL_NODE",
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "RECONNECT_GMAIL_CREDENTIAL"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "labelIds": [
          "RECONNECT_PAYMENTS_LABEL"
        ]
      },
      "id": "7ba183d9-514a-458c-8373-1216407b4c49",
      "name": "Payments Label",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1824,
        -176
      ],
      "webhookId": "RECONNECT_GMAIL_LABEL_NODE",
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "RECONNECT_GMAIL_CREDENTIAL"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "labelIds": [
          "RECONNECT_CONSULTATION_LABEL"
        ]
      },
      "id": "f6d621b0-61a6-4ada-8521-5ee5b7b36ac3",
      "name": "ConsultationReq Label",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1824,
        0
      ],
      "webhookId": "RECONNECT_GMAIL_LABEL_NODE",
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "RECONNECT_GMAIL_CREDENTIAL"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "labelIds": [
          "RECONNECT_OTHER_LABEL"
        ]
      },
      "id": "adb87612-6581-4805-812c-3a0a4925eac6",
      "name": "Others Label",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1824,
        208
      ],
      "webhookId": "RECONNECT_GMAIL_LABEL_NODE",
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "RECONNECT_GMAIL_CREDENTIAL"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "EDIT(If not)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EDIT(If not)": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Clean data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean data": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "ServiceReq Label",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Payments Label",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ConsultationReq Label",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Others Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "cbe3269a-acc5-4af6-bcec-448b2ee7fcfa",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": ""
  },
  "nodeGroups": [],
  "id": "QQSlRHMQKTFifi4J",
  "tags": []
}
