{
  "name": "Keep Notes - Email to Note",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {
          "hasReadStatus": true,
          "readStatus": "unread"
        }
      },
      "id": "email-trigger",
      "name": "Email Trigger",
      "type": "n8n-nodes-base.emailTrigger",
      "typeVersion": 1.1,
      "position": [250, 300],
      "description": "Trigger when new email received"
    },
    {
      "parameters": {
        "jsCode": "// Extract relevant information from email\nconst email = $input.item.json;\n\n// Get email subject and body\nconst subject = email.subject || 'Untitled Email';\nconst body = email.text || email.html || '';\nconst from = email.from?.value?.[0]?.address || 'unknown';\n\n// Create structured note data\nreturn {\n  json: {\n    title: `Email: ${subject}`,\n    content: `From: ${from}\\n\\n${body}`,\n    labels: ['email', 'inbox'],\n    color: 'blue',\n    type: 'text',\n    isPinned: false,\n    isArchived: false,\n    metadata: {\n      originalEmailId: email.messageId,\n      from: from,\n      date: email.date,\n      attachments: email.attachments?.length || 0\n    }\n  }\n};"
      },
      "id": "extract-email-1",
      "name": "Extract Email Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [500, 300]
    },
    {
      "parameters": {
        "modelId": "openai/gpt-4",
        "prompt": "Analyze this email and:\n1. Extract the main topic/theme (2-3 words max)\n2. Identify if it's urgent (important meeting, deadline, etc.)\n3. Suggest appropriate labels from: work, personal, finance, shopping, meeting, task, archive\n\nEmail subject: {{ $json.title }}\nEmail content: {{ $json.content }}\n\nReturn JSON:\n{\n  \"topic\": \"main topic\",\n  \"isUrgent\": true/false,\n  \"labels\": [\"label1\", \"label2\"],\n  \"notebook\": \"work/personal/ideas\"\n}"
      },
      "id": "ai-classify-email",
      "name": "AI Classify Email",
      "type": "n8n-nodes-langchain.agent",
      "typeVersion": 1.1,
      "position": [750, 300],
      "continueOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "urgent-check",
              "leftValue": "={{ $json.isUrgent }}",
              "rightValue": "true",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "check-urgent",
      "name": "Check if Urgent",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.1,
      "position": [1000, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "isPinned",
              "value": true,
              "type": "boolean"
            },
            {
              "name": "color",
              "value": "red",
              "type": "string"
            }
          ],
          "options": {}
        }
      },
      "id": "set-urgent-flags",
      "name": "Set Urgent Flags",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1250, 200]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "isPinned",
              "value": false,
              "type": "boolean"
            },
            {
              "name": "color",
              "value": "default",
              "type": "string"
            }
          ],
          "options": {}
        }
      },
      "id": "set-normal-flags",
      "name": "Set Normal Flags",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1250, 400]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "multiplex",
        "options": {}
      },
      "id": "merge-email-data",
      "name": "Merge Email Data",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [1500, 300]
    },
    {
      "parameters": {
        "resource": "note",
        "operation": "create",
        "url": "http://localhost:3000/api/notes",
        "method": "POST",
        "bodyParameters": {
          "parameters": [
            {
              "name": "title",
              "value": "={{ $json.title }}"
            },
            {
              "name": "content",
              "value": "={{ $json.content }}"
            },
            {
              "name": "color",
              "value": "={{ $json.color }}"
            },
            {
              "name": "isPinned",
              "value": "={{ $json.isPinned }}"
            },
            {
              "name": "labels",
              "value": "={{ $json.labels }}"
            }
          ]
        }
      },
      "id": "create-note-from-email",
      "name": "Create Note in Keep Notes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1750, 300],
      "sendHeaders": true,
      "headerParameters": {
        "parameters": [
          {
            "name": "Content-Type",
            "value": "application/json"
          }
        ]
      }
    },
    {
      "parameters": {
        "channel": "keep-notes-sync",
        "text": "📧 New email saved to Keep Notes:\n\n**{{ $json.title }}**\n\nLabels: {{ $json.labels.join(', ') }}\nColor: {{ $json.color }}\n\nView: http://localhost:3000"
      },
      "id": "notify-slack",
      "name": "Notify Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [2000, 300],
      "continueOnFail": true
    }
  ],
  "connections": {
    "Email Trigger": {
      "main": [
        [
          {
            "node": "Extract Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Email Data": {
      "main": [
        [
          {
            "node": "AI Classify Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Classify Email": {
      "main": [
        [
          {
            "node": "Check if Urgent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Urgent": {
      "main": [
        [
          {
            "node": "Set Urgent Flags",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Normal Flags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Urgent Flags": {
      "main": [
        [
          {
            "node": "Merge Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Normal Flags": {
      "main": [
        [
          {
            "node": "Merge Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Email Data": {
      "main": [
        [
          {
            "node": "Create Note in Keep Notes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Note in Keep Notes": {
      "main": [
        [
          {
            "node": "Notify Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "createdAt": "2026-01-18T00:00:00.000Z",
      "id": "keep-notes-integrations",
      "name": "Keep Notes Integrations"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2026-01-18T00:00:00.000Z",
  "versionId": "1"
}
