{
  "name": "M6 Inbox triage (solution)",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "q": "subject:\"[S6 test]\""
        },
        "options": {}
      },
      "id": "8bb2ccfc-33c1-4066-8018-2fd8b8ae32ff",
      "name": "New email",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You classify incoming customer emails for a small software company.\nRead the email below and reply with exactly one word from this list:\nbilling, technical, sales, unsure\nRules:\n- billing: invoices, payments, refunds, subscription changes\n- technical: errors, login problems, how-to questions about the product\n- sales: pricing, demos, new licences, partnerships\n- unsure: anything else, or if two labels fit equally well\n- unsure: also when the email mixes a personal or unrelated request (slides, a talk, an event) with a business question\nReply with the single word only. No punctuation, no explanation.\nEmail subject: {{ $json.subject }}\nEmail body: {{ $json.text }}",
        "batching": {}
      },
      "id": "5023a069-17df-4304-ac3c-15fd1ff5c4df",
      "name": "Classify email",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.5-flash",
        "options": {
          "temperature": 0
        }
      },
      "id": "3ec70c62-5b9e-431c-93f0-9347bbf8360f",
      "name": "Gemini (flash)",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        240,
        200
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "78dc8e9e-6cc2-422c-a7f8-0be4d4cab96f",
              "name": "label",
              "value": "={{ $json.text.trim().toLowerCase() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "71d90505-2ef2-4304-bb10-5203c1de3506",
      "name": "Clean label",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "e7a8515c-e4ab-4a27-a6c6-6b49eda0e905",
                    "leftValue": "={{ $json.label }}",
                    "rightValue": "billing",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "billing"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "623913c8-b1c9-4af8-b6ef-a92d346d86a9",
                    "leftValue": "={{ $json.label }}",
                    "rightValue": "technical",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "technical"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "6f0224ab-ec69-49b3-b344-f22d4a5583ef",
                    "leftValue": "={{ $json.label }}",
                    "rightValue": "sales",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "sales"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "unsure"
        }
      },
      "id": "7224a946-5246-4df0-bfc0-c16a3ff18ae9",
      "name": "Route by label",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        720,
        0
      ]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "PICK-LABEL-billing"
        ]
      },
      "id": "52bec31a-934d-42eb-92d0-58dcf2650d77",
      "name": "Label billing",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        980,
        -260
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "PICK-LABEL-technical"
        ]
      },
      "id": "dbdd1254-6bfc-4dc1-b74a-98eb4dc5f92d",
      "name": "Label technical",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        980,
        -80
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email').item.json.id }}",
        "labelIds": [
          "PICK-LABEL-sales"
        ]
      },
      "id": "7171b962-6711-409a-aac0-392ba483db41",
      "name": "Label sales",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        980,
        100
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "PASTE-YOUR-GOOGLE-SHEET-URL-HERE"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Triage review"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "value": {
            "date": "={{ $('New email').item.json.date }}",
            "from": "={{ $('New email').item.json.from.text }}",
            "subject": "={{ $('New email').item.json.subject }}",
            "snippet": "={{ ($('New email').item.json.text || '').replace(/\\s+/g, ' ').slice(0, 160) }}",
            "link": "=https://mail.google.com/mail/u/0/#all/{{ $('New email').item.json.id }}"
          },
          "schema": [
            {
              "id": "date",
              "displayName": "date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "from",
              "displayName": "from",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "displayName": "subject",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "snippet",
              "displayName": "snippet",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "link",
              "displayName": "link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "fa956d3b-7cb4-4ca2-988b-6620ee909da1",
      "name": "Add to Triage review",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        980,
        300
      ]
    },
    {
      "parameters": {
        "content": "## M6 Inbox triage\nGmail Trigger -> **AI step (classify)** -> clean the label -> Switch -> label the three known classes; **unsure goes to a person** (Triage review sheet).\n\nAfter import: connect Gmail, Google Sheets and Gemini; paste your sheet URL; in each Label node pick your label from the list.\n\nThe trigger only reads e-mails whose subject contains **[S6 test]** (cheap filter before the paid step).",
        "width": 470,
        "height": 260,
        "color": 4
      },
      "id": "e10889e8-3930-460d-a534-dd2119bd023e",
      "name": "Note bf8d",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -300,
        240
      ]
    }
  ],
  "connections": {
    "New email": {
      "main": [
        [
          {
            "node": "Classify email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini (flash)": {
      "ai_languageModel": [
        [
          {
            "node": "Classify email",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Classify email": {
      "main": [
        [
          {
            "node": "Clean label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean label": {
      "main": [
        [
          {
            "node": "Route by label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by label": {
      "main": [
        [
          {
            "node": "Label billing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label technical",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label sales",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add to Triage review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {}
}