{
  "name": "Inbox triage: sort, label and route the shared inbox",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "labelIds": [
            "INBOX"
          ]
        },
        "options": {}
      },
      "id": "6e2da496-e790-5350-91a8-4f6e7ff33306",
      "name": "New email in shared inbox",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "Gmail (shared inbox)"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.anthropic.com/v1/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'claude-haiku-5-5', max_tokens: 600, system: \"You sort a company's shared inbox. Reply with JSON only: {\\\"category\\\": \\\"sales|support|invoice|newsletter|spam\\\", \\\"priority\\\": \\\"high|normal|low\\\", \\\"summary\\\": \\\"one sentence\\\"}.\", messages: [{ role: 'user', content: `From: ${$json.from?.text ?? ''}\\nSubject: ${$json.subject ?? ''}\\n\\n${($json.text ?? '').slice(0, 4000)}` }] }) }}",
        "options": {
          "timeout": 60000
        }
      },
      "id": "4da3fdba-764d-518e-ab86-59e7106b0dd8",
      "name": "Classify with Claude",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Anthropic API key (header x-api-key)"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Claude replies with JSON text; turn it into fields and keep the original input alongside.\nreturn $input.all().map((item) => {\n  const text = item.json.content?.[0]?.text ?? '{}';\n  const match = text.match(/\\{[\\s\\S]*\\}/);\n  let parsed = {};\n  try { parsed = JSON.parse(match ? match[0] : text); } catch { parsed = { parse_error: true, raw: text }; }\n  return { json: { ...parsed } }; // category, priority, summary\n});"
      },
      "id": "aba38f0b-7899-5166-81a5-c5d1d3d0b98d",
      "name": "Read the category",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('New email in shared inbox').item.json.id }}",
        "labelIds": "={{ ['Triage/' + $json.category] }}"
      },
      "id": "13ec9c76-c0e4-5a69-9d4d-bd149157481a",
      "name": "Label it in Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        660,
        0
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "Gmail (shared inbox)"
        }
      },
      "notes": "Create the Triage/sales, Triage/support, Triage/invoice... labels once in Gmail.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "749e1fc2-504e-5f24-aa22-b454a65aa24c",
              "leftValue": "={{ $('Read the category').item.json.priority }}",
              "rightValue": "high",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "33cce837-bf13-5702-8f45-de188f018ed1",
      "name": "Urgent?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#inbox",
          "mode": "name"
        },
        "text": "=:envelope: {{ $('Read the category').item.json.category }} needs a reply today: {{ $('New email in shared inbox').item.json.subject }}\n{{ $('Read the category').item.json.summary }}",
        "otherOptions": {}
      },
      "id": "815e69a2-22f0-5e2b-9e0b-e8bd1e0c5a22",
      "name": "Ping the team",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1100,
        -100
      ],
      "credentials": {
        "slackApi": {
          "id": "",
          "name": "Slack"
        }
      }
    },
    {
      "parameters": {},
      "id": "b63efe84-f91a-583d-852e-5f75c66d03a8",
      "name": "Done",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1100,
        100
      ]
    }
  ],
  "connections": {
    "New email in shared inbox": {
      "main": [
        [
          {
            "node": "Classify with Claude",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify with Claude": {
      "main": [
        [
          {
            "node": "Read the category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the category": {
      "main": [
        [
          {
            "node": "Label it in Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label it in Gmail": {
      "main": [
        [
          {
            "node": "Urgent?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Urgent?": {
      "main": [
        [
          {
            "node": "Ping the team",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "adev": {
      "slug": "inbox-triage",
      "service": "ai-automation",
      "needs": [
        "n8n",
        "Anthropic API key",
        "Gmail or Google Workspace",
        "Slack"
      ],
      "summary": "Each email in the shared inbox is classified, labelled and, if it's urgent, flagged to the team. Nobody spends the morning sorting."
    }
  },
  "tags": [
    {
      "name": "adev.build"
    }
  ]
}