{
  "name": "Track expenses via chat with Claude Haiku and Google Sheets",
  "nodes": [
    {
      "id": "ff5c621a-0deb-4067-864d-04bd59b6c2e5",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        6480,
        4560
      ]
    },
    {
      "id": "9806596c-ad71-48dc-a7b4-e4ffbc992dbd",
      "name": "Detect Intent",
      "type": "n8n-nodes-base.code",
      "position": [
        6704,
        4560
      ]
    },
    {
      "id": "9387f59f-2ce3-4d22-b8a8-7e48032f3ca2",
      "name": "Intent Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        6928,
        4544
      ]
    },
    {
      "id": "57ea0ffb-1a76-4f6c-8e60-0e7619c7f4a7",
      "name": "Read All Expenses",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        7152,
        4368
      ]
    },
    {
      "id": "b9f18554-7c19-4969-86de-0a81be8c53d2",
      "name": "Prepare Data",
      "type": "n8n-nodes-base.code",
      "position": [
        7376,
        4368
      ]
    },
    {
      "id": "a433bab2-5943-49d2-a770-b75ecd7baa62",
      "name": "AI Parse Expense",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        7600,
        4368
      ]
    },
    {
      "id": "627fd6e3-2232-4f76-bafe-a4b01fbc0e51",
      "name": "Claude Haiku",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        7744,
        4544
      ]
    },
    {
      "id": "218d3c40-8eb1-4dd8-b1b9-8dc01fa525b0",
      "name": "Parse & Total",
      "type": "n8n-nodes-base.code",
      "position": [
        7952,
        4368
      ]
    },
    {
      "id": "2a720602-ff73-44f5-9669-986e57be1d4d",
      "name": "Is Valid Expense?",
      "type": "n8n-nodes-base.if",
      "position": [
        8176,
        4368
      ]
    },
    {
      "id": "52bdb900-a6c1-4676-83fb-c34f63ea9434",
      "name": "Save Expense to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        8400,
        4272
      ]
    },
    {
      "id": "de6afe46-3c00-459c-85e4-8cb613e5714b",
      "name": "Reply Saved",
      "type": "n8n-nodes-base.code",
      "position": [
        8624,
        4272
      ]
    },
    {
      "id": "7d347763-8d31-48c4-aba7-f7ed6f332b6d",
      "name": "Reply Invalid",
      "type": "n8n-nodes-base.code",
      "position": [
        8400,
        4464
      ]
    },
    {
      "id": "e8261ff4-b303-47fd-a0f6-997f27f7b037",
      "name": "Read for Summary",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        7264,
        4736
      ]
    },
    {
      "id": "5da81e46-54f5-434c-bd13-21e6c8d1c00a",
      "name": "Build Summary",
      "type": "n8n-nodes-base.code",
      "position": [
        7472,
        4736
      ]
    },
    {
      "id": "885991be-8d6f-49f5-b742-c57e3da0aaa3",
      "name": "Send Help",
      "type": "n8n-nodes-base.code",
      "position": [
        7152,
        4976
      ]
    },
    {
      "id": "fcb94238-8ccf-4b7f-9dff-c6813d5eecb7",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6128,
        3968
      ],
      "parameters": {
        "width": 476,
        "height": 508,
        "content": "## 💰 AI Expense Tracker\nTrack expenses by chatting naturally.\n\n**Just type your expense:**\n_\"spent 500 on lunch\"_\n_\"uber 150\"_\n_\"1200 electricity bill\"_\n\n**Commands:**\n• `SUMMARY` — current month repo"
      }
    },
    {
      "id": "fc55f4ca-d4d0-4f3d-aed3-4cf071cd0919",
      "name": "Trigger Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6192,
        4512
      ],
      "parameters": {
        "width": 424,
        "height": 196,
        "content": "## 1️⃣ Entry Point\nReceives every chat message.\nPasses `chatInput` to next node."
      }
    },
    {
      "id": "fd4f6cce-59fc-4a26-8976-fb13377c9798",
      "name": "Intent Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6624,
        4288
      ],
      "parameters": {
        "width": null,
        "height": 424,
        "content": "## 2️⃣ Detect Intent\nReads the message and classifies:\n• **expense** — anything with an amount\n• **summary** — report/total/breakdown\n• **help** — help/?"
      }
    },
    {
      "id": "452c8436-94d9-4e03-91a7-50e2406911db",
      "name": "Switch Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6880,
        4288
      ],
      "parameters": {
        "width": 220,
        "height": 430,
        "content": "## 3️⃣ Routes to 3 paths\n**Output 0** → Expense flow\n**Output 1** → Summary flow\n**Output 2** → Help message"
      }
    },
    {
      "id": "29e8945f-d2ce-40c9-9730-8e63edd4a359",
      "name": "Read Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7104,
        4080
      ],
      "parameters": {
        "width": 204,
        "height": 456,
        "content": "## 4️⃣ Read Sheet\nLoads all existing rows.\n`alwaysOutputData: true` ensures\nflow continues even if sheet is empty."
      }
    },
    {
      "id": "fbf91c41-741b-49c3-865b-471c296d0737",
      "name": "Prepare Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7312,
        4080
      ],
      "parameters": {
        "width": 220,
        "height": 450,
        "content": "## 5️⃣ Prepare Data\nComputes running month total\nfrom existing rows.\nAlways outputs 1 item → flow\nnever stops on empty sheet."
      }
    },
    {
      "id": "fe8321dd-c9c0-4733-a70c-ad759db0bf8f",
      "name": "AI Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7552,
        4080
      ],
      "parameters": {
        "width": 300,
        "height": 454,
        "content": "## 6️⃣ AI Parse\nClaude Haiku reads the message\nand extracts:\n• amount · description\n• category · currency · date\n• is_expense (true/false)\n\nReturns clean JSON only."
      }
    },
    {
      "id": "740ca285-5709-4730-a206-0572bdb160ff",
      "name": "Parse Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7872,
        4080
      ],
      "parameters": {
        "width": 230,
        "height": 450,
        "content": "## 7️⃣ Parse & Total\nValidates AI response.\nDerives Month from parsed date\n(not today — handles past entries).\nCalculates running monthly total."
      }
    },
    {
      "id": "00edd05c-dcd0-437f-9c4a-c5c1a994680e",
      "name": "Valid Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        8112,
        4080
      ],
      "parameters": {
        "width": 212,
        "height": 452,
        "content": "## 8️⃣ Valid?\n✅ TRUE → Save to sheet\n❌ FALSE → Ask user\nto add an amount"
      }
    },
    {
      "id": "decba3df-1e53-4a14-9c87-bdc3a9303fca",
      "name": "Save Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        8352,
        4064
      ],
      "parameters": {
        "width": 492,
        "height": 536,
        "content": "## 9️⃣ Save + Reply\nAppends new row to sheet.\nReplies with confirmation:\n✅ Category · Amount · Date\n📊 Running month total"
      }
    },
    {
      "id": "9ad784c3-e3f3-41eb-85a7-72f6d3c475a0",
      "name": "Summary Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7104,
        4560
      ],
      "parameters": {
        "width": 596,
        "height": 358,
        "content": "## 📊 SUMMARY FLOW\nReads all rows → filters by month.\nDetects specific month from message\n_(e.g. \"summary february 2026\")_\nDefaults to current month.\nShows total, breakdown, daily avg."
      }
    },
    {
      "id": "a1a82af4-5888-4681-8c82-1465c2eff8b0",
      "name": "Sheet Columns",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6144,
        4288
      ],
      "parameters": {
        "width": 200,
        "height": 180,
        "content": "## 📋 Sheet Columns\nA: Date\nB: Amount\nC: Category\nD: Description\nE: Currency\nF: Month\nG: Raw Message\nH: Total _(running monthly)_"
      }
    }
  ],
  "connections": {
    "Claude Haiku": {
      "ai_languageModel": [
        [
          {
            "node": "AI Parse Expense",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Data": {
      "main": [
        [
          {
            "node": "AI Parse Expense",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Intent": {
      "main": [
        [
          {
            "node": "Intent Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Intent Switch": {
      "main": [
        [
          {
            "node": "Read All Expenses",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Read for Summary",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Help",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse & Total": {
      "main": [
        [
          {
            "node": "Is Valid Expense?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Parse Expense": {
      "main": [
        [
          {
            "node": "Parse & Total",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read for Summary": {
      "main": [
        [
          {
            "node": "Build Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Valid Expense?": {
      "main": [
        [
          {
            "node": "Save Expense to Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply Invalid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read All Expenses": {
      "main": [
        [
          {
            "node": "Prepare Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Expense to Sheet": {
      "main": [
        [
          {
            "node": "Reply Saved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Detect Intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}