{
  "name": "Email to Task Extractor",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [{ "mode": "everyMinute" }]
        },
        "filters": {
          "readStatus": "unread",
          "labelIds": ["INBOX"]
        },
        "options": {}
      },
      "id": "gtet0001-0001-4000-8000-000000000001",
      "name": "Watch Inbox for Tasks",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a productivity assistant. Read this email and extract any action items or tasks. Return JSON array: [{\"task\": \"...\", \"assignee\": \"...\", \"dueDate\": \"YYYY-MM-DD or null\", \"priority\": \"low|medium|high\"}]. If no tasks found return empty array []."
            },
            {
              "role": "user",
              "content": "From: {{ $json.from }}\\nSubject: {{ $json.subject }}\\n\\n{{ $json.text }}"
            }
          ]
        },
        "options": {
          "temperature": 0.1,
          "maxTokens": 600
        }
      },
      "id": "gtet0001-0002-4000-8000-000000000002",
      "name": "Extract Tasks with GPT",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [460, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "field1",
              "name": "tasks",
              "value": "={{ JSON.parse($json.message.content) }}",
              "type": "array"
            },
            {
              "id": "field2",
              "name": "emailFrom",
              "value": "={{ $('Watch Inbox for Tasks').item.json.from }}",
              "type": "string"
            },
            {
              "id": "field3",
              "name": "emailSubject",
              "value": "={{ $('Watch Inbox for Tasks').item.json.subject }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "gtet0001-0003-4000-8000-000000000003",
      "name": "Parse Task List",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [680, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": false, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "id": "cond1",
              "leftValue": "={{ $json.tasks.length }}",
              "rightValue": 0,
              "operator": { "type": "number", "operation": "gt" }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "gtet0001-0004-4000-8000-000000000004",
      "name": "Has Tasks?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [900, 300]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": { "__rl": true, "mode": "id", "value": "={{ $env.TASKS_SHEET_ID }}" },
        "sheetName": { "__rl": true, "mode": "name", "value": "Tasks" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Source Email": "={{ $json.emailSubject }}",
            "From": "={{ $json.emailFrom }}",
            "Tasks JSON": "={{ JSON.stringify($json.tasks) }}",
            "Extracted At": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "gtet0001-0005-4000-8000-000000000005",
      "name": "Log Tasks to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [1120, 200]
    }
  ],
  "connections": {
    "Watch Inbox for Tasks": {
      "main": [[{ "node": "Extract Tasks with GPT", "type": "main", "index": 0 }]]
    },
    "Extract Tasks with GPT": {
      "main": [[{ "node": "Parse Task List", "type": "main", "index": 0 }]]
    },
    "Parse Task List": {
      "main": [[{ "node": "Has Tasks?", "type": "main", "index": 0 }]]
    },
    "Has Tasks?": {
      "main": [
        [{ "node": "Log Tasks to Sheets", "type": "main", "index": 0 }],
        []
      ]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
