{
  "name": "Automatic Gmail message categorization with GPT-4 content analysis & labels",
  "nodes": [
    {
      "id": "7697a77b-7dc8-40e7-b8e2-859c724ed6d5",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2380,
        40
      ],
      "parameters": {
        "width": 452.48413953150185,
        "height": 347.0476323933831,
        "content": "### Aggregate labels and update to message\nCreate array of label IDs and add to the desired email message in Gmail."
      }
    },
    {
      "id": "013c142d-eb86-4d62-bab3-9dc77fba7b3b",
      "name": "Gmail trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        720,
        200
      ]
    },
    {
      "id": "78cf0980-b4ec-4ed0-9b49-014e4d5d63d3",
      "name": "Get message content",
      "type": "n8n-nodes-base.gmail",
      "position": [
        980,
        200
      ]
    },
    {
      "id": "1f07bb8a-0e12-47fd-bf4f-751befeea37c",
      "name": "Assign labels for message",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1240,
        200
      ]
    },
    {
      "id": "c0f1e702-25b5-4887-b112-7d0d1c239ea1",
      "name": "JSON Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1460,
        420
      ]
    },
    {
      "id": "979aad50-8e34-471e-9016-c412e470c81b",
      "name": "Set label values",
      "type": "n8n-nodes-base.set",
      "position": [
        1620,
        200
      ]
    },
    {
      "id": "48e80f97-1679-40a5-860d-124d32c82316",
      "name": "Get all labels",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1840,
        80
      ]
    },
    {
      "id": "e29e712a-7940-4ca3-9a82-525ac7d5f7bf",
      "name": "Split out assigned labels",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1840,
        280
      ]
    },
    {
      "id": "95886e13-3412-4c27-8510-873bbaced52b",
      "name": "Merge corresponding labels",
      "type": "n8n-nodes-base.merge",
      "position": [
        2180,
        140
      ]
    },
    {
      "id": "329cf5ff-7933-4c5e-bb63-cbb77689a194",
      "name": "Aggregate label IDs",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2440,
        140
      ]
    },
    {
      "id": "952aad99-6ae7-4639-8132-f51b1065468e",
      "name": "Add labels to message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2640,
        140
      ]
    },
    {
      "id": "11244a40-d6df-475b-b900-bf8d386077d6",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -140
      ],
      "parameters": {
        "width": 580,
        "height": 1041,
        "content": "## Intelligent Gmail Labeling: Categorize Emails by Content Intent Using OpenAI\n\n## Who is this for?\n\nThis workflow is ideal for Gmail users and teams who receive a high volume of emails and want to s"
      }
    },
    {
      "id": "1eca85f0-bfa4-431e-90e2-0ffe25844bdd",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        20
      ],
      "parameters": {
        "width": 238,
        "height": 349,
        "content": "### Gmail Trigger\nGet new incoming message from Gmail. \n\n⚠️ Set up the time (polling) interval based on your needs."
      }
    },
    {
      "id": "a5dd9b23-0fd8-42a8-a334-2a0640750c52",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1400,
        400
      ],
      "parameters": {
        "width": 241.53974014153226,
        "height": 319.3323098457962,
        "content": "###\n\n\n\n\n\n\n\n\n\n\n### JSON schema\nEdit JSON schema and label names according to your needs.\n\n⚠️ **Label names in system prompt and JSON schema should be the same.**"
      }
    },
    {
      "id": "c6a7af89-e307-4363-8d96-83c0f7c0e7b8",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2120,
        40
      ],
      "parameters": {
        "width": 226.14233872620645,
        "height": 347.0476323933831,
        "content": "### Merge labels\nCombine labels retrieved from Gmail account and assigned by AI together."
      }
    },
    {
      "id": "afb1a124-f880-4d6c-987e-dabf2c3fb882",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        20
      ],
      "parameters": {
        "width": 238.4602598584674,
        "height": 348.5873725349161,
        "content": "### Get message content\nBased on Gmail message ID retrieve body content of the email and pass it to AI chain."
      }
    },
    {
      "id": "44b4c579-538f-45fe-9cde-627ac7364013",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1180,
        20
      ],
      "parameters": {
        "width": 378.57661273793565,
        "height": 348.5873725349161,
        "content": "### Assign labels\nLet the AI decide which labels suit the best content of the message.\n\n⚠️ **Remember to edit system prompt** - modify label names and instructions according to your needs."
      }
    },
    {
      "id": "e866b876-20a4-4a19-bd07-56c69eed82af",
      "name": "OpenAI GPT-4 Based",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1220,
        420
      ]
    }
  ],
  "connections": {
    "JSON Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Assign labels for message",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Gmail trigger": {
      "main": [
        [
          {
            "node": "Get message content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get all labels": {
      "main": [
        [
          {
            "node": "Merge corresponding labels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set label values": {
      "main": [
        [
          {
            "node": "Split out assigned labels",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get all labels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4 Based": {
      "ai_languageModel": [
        [
          {
            "node": "Assign labels for message",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate label IDs": {
      "main": [
        [
          {
            "node": "Add labels to message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get message content": {
      "main": [
        [
          {
            "node": "Assign labels for message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assign labels for message": {
      "main": [
        [
          {
            "node": "Set label values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split out assigned labels": {
      "main": [
        [
          {
            "node": "Merge corresponding labels",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge corresponding labels": {
      "main": [
        [
          {
            "node": "Aggregate label IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}