{
 "id": "emailtriageagent",
 "name": "AutomateRecipes \u2013 email-triage-agent",
 "nodes": [
  {
   "parameters": {},
   "name": "Manual Trigger",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    0
   ],
   "id": "433e20ec-9206-4ed6-9cae-cb3c82308f03"
  },
  {
   "parameters": {
    "jsCode": "return [{json:{id:'m1',from:'a@x.test',subject:'Invoice 1001 wrong amount',body:'Please fix the invoice'}},{json:{id:'m2',from:'b@y.test',subject:'Price for 20 units?',body:'Can I get a quote'}},{json:{id:'m3',from:'c@z.test',subject:'App not loading',body:'It crashes'}}];"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S1",
   "position": [
    220,
    0
   ],
   "id": "d4748b4f-f29d-41b2-8f28-084a5f19472a"
  },
  {
   "parameters": {
    "jsCode": "return $input.all().map(i=>({json:{...i.json,service:'openai/v1/chat/completions',payload:{model:'gpt-4o-mini',messages:[{role:'user',content:'Classify as sales, support, billing: '+i.json.subject+' '+i.json.body}]}}}));"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "AIPREP",
   "position": [
    440,
    0
   ],
   "id": "133f50dd-cdf0-40fa-9f9c-64f1b40a49f7"
  },
  {
   "parameters": {
    "method": "POST",
    "url": "=http://127.0.0.1:9000/{{ $json.service }}",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify($json.payload) }}",
    "options": {}
   },
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "name": "S3 POST mock (AI)",
   "position": [
    660,
    0
   ],
   "id": "80ed2f64-2d2a-4aff-9a21-a7916c728d86"
  },
  {
   "parameters": {
    "jsCode": "const src=$('AIPREP').all();return $input.all().map((r,i)=>({json:{...src[i].json,ai:r.json.choices[0].message.content}}));"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S4",
   "position": [
    880,
    0
   ],
   "id": "a4d9ec47-9b5a-4c76-96b4-5f72fae1a314"
  },
  {
   "parameters": {
    "jsCode": "return $input.all().map(i=>{const label=i.json.ai.replace('[mock AI] ','');return {json:{service:label==='support'?'gmail/drafts':'gmail/labels',payload:{messageId:i.json.id,label,draft:label==='support'?'Hi, sorry about that - we are looking into it.':undefined}}}});"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S5",
   "position": [
    1100,
    0
   ],
   "id": "68628d39-4dd9-4129-ac6f-08db93b23d60"
  },
  {
   "parameters": {
    "method": "POST",
    "url": "=http://127.0.0.1:9000/{{ $json.service }}",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify($json.payload) }}",
    "options": {}
   },
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "name": "S6 POST mock (send)",
   "position": [
    1320,
    0
   ],
   "id": "b9a87e29-5f80-4c25-8ca2-1476543f6cd9"
  }
 ],
 "connections": {
  "Manual Trigger": {
   "main": [
    [
     {
      "node": "S1",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S1": {
   "main": [
    [
     {
      "node": "AIPREP",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "AIPREP": {
   "main": [
    [
     {
      "node": "S3 POST mock (AI)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S3 POST mock (AI)": {
   "main": [
    [
     {
      "node": "S4",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S4": {
   "main": [
    [
     {
      "node": "S5",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S5": {
   "main": [
    [
     {
      "node": "S6 POST mock (send)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {},
 "active": false,
 "pinData": {},
 "meta": {
  "note": "Tested on n8n 1.70.3 with local mocks for: Gmail trigger/labels/drafts, OpenAI. Replace 'POST mock'/'GET mock' HTTP nodes with the real app nodes + credentials before production."
 }
}