{
  "name": "Track Telegram expenses with GPT-4 and Google Sheets (self-learning categories)",
  "nodes": [
    {
      "id": "9f0e8a05-1820-4372-b4c7-1e1902bd93c2",
      "name": "Telegram - Receive Message",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -3472,
        272
      ]
    },
    {
      "id": "951ab95a-9e41-4634-ac6b-571ddb7eb3ce",
      "name": "Security — Allow Approved Chat IDs",
      "type": "n8n-nodes-base.if",
      "position": [
        -3232,
        272
      ]
    },
    {
      "id": "6ce435ca-7ee5-4b6f-9b17-68eaa70b344e",
      "name": "AI — Detect Expense Message",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -2256,
        256
      ]
    },
    {
      "id": "2a9ec1ab-070b-4317-9992-154b1aa8ee1b",
      "name": "Parse — Expense Detection Output",
      "type": "n8n-nodes-base.set",
      "position": [
        -1968,
        256
      ]
    },
    {
      "id": "aa04206a-f3d1-4470-98e4-4e76a833d093",
      "name": "Filter — Only Continue If Expense",
      "type": "n8n-nodes-base.if",
      "position": [
        -1776,
        256
      ]
    },
    {
      "id": "1251654a-de72-4bcd-a548-6416280cfb55",
      "name": "Sheets — Load Existing Categories",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -784,
        240
      ]
    },
    {
      "id": "5f1bda9e-fbdd-46e6-ace5-e6afac19c0ca",
      "name": "Format — Build Category Prompt",
      "type": "n8n-nodes-base.code",
      "position": [
        -544,
        240
      ]
    },
    {
      "id": "a5f1180a-966f-487e-a303-ddc574085a42",
      "name": "AI — Classify Expense Category",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -320,
        240
      ]
    },
    {
      "id": "b2ea33a5-d737-4f38-8e71-8cf4cebfe70b",
      "name": "Parse — Category Classification Output",
      "type": "n8n-nodes-base.set",
      "position": [
        32,
        240
      ]
    },
    {
      "id": "81ffab19-c6eb-4e75-bc26-2001085d2f9c",
      "name": "Decision — Category Exists?",
      "type": "n8n-nodes-base.if",
      "position": [
        240,
        240
      ]
    },
    {
      "id": "e9b20118-56f8-415e-92e0-4d2aba77d3ed",
      "name": "Telegram — Ask To Create New Category",
      "type": "n8n-nodes-base.telegram",
      "position": [
        416,
        32
      ]
    },
    {
      "id": "28e02ea5-9ef6-4597-a281-752219d2f38a",
      "name": "Decision — Category Approved?",
      "type": "n8n-nodes-base.if",
      "position": [
        640,
        32
      ]
    },
    {
      "id": "481ec102-a6dc-426c-85c9-75b76b4f27cc",
      "name": "Telegram — Edit New Category Form",
      "type": "n8n-nodes-base.telegram",
      "position": [
        912,
        128
      ]
    },
    {
      "id": "4d6dd679-b641-41cf-9af7-2841831575c4",
      "name": "Sheets — Add Suggested Category",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        912,
        -64
      ]
    },
    {
      "id": "b8c7f4df-4750-4de1-b1fc-e943a659ee71",
      "name": "Sheets — Add Edited Category",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1104,
        128
      ]
    },
    {
      "id": "a45d1f24-7cd8-4891-8836-be67cb5260f4",
      "name": "Pass Through — Category Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1600,
        80
      ]
    },
    {
      "id": "956a4aff-8c37-4e4e-9630-38c40184b92b",
      "name": "Prepare — Category Fields (Form)",
      "type": "n8n-nodes-base.set",
      "position": [
        1280,
        128
      ]
    },
    {
      "id": "c317d6df-12aa-4f3e-a031-7de112c5a37a",
      "name": "Prepare — Category Fields (Auto)",
      "type": "n8n-nodes-base.set",
      "position": [
        1264,
        -64
      ]
    },
    {
      "id": "b945c2cc-3749-4976-aadb-3f23cb22773d",
      "name": "Telegram — Category Created Confirmation",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1888,
        80
      ]
    },
    {
      "id": "b5171992-70c9-4801-8971-e28efdaabe3a",
      "name": "Prepare — Updated Categories",
      "type": "n8n-nodes-base.set",
      "position": [
        2144,
        80
      ]
    },
    {
      "id": "14787bc4-6242-4527-8244-781c6ecb9982",
      "name": "Format — Rebuild Category Prompt",
      "type": "n8n-nodes-base.code",
      "position": [
        2432,
        80
      ]
    },
    {
      "id": "06bdd6d2-5edf-49b3-809a-e38d93ddc6fd",
      "name": "Prepare — Category Prompt Payload",
      "type": "n8n-nodes-base.set",
      "position": [
        1424,
        256
      ]
    },
    {
      "id": "2d4df9a7-1811-420d-b910-55dd092de1ed",
      "name": "Merge — Expense + Categories",
      "type": "n8n-nodes-base.code",
      "position": [
        2672,
        256
      ]
    },
    {
      "id": "63e73043-7814-4e07-9084-3a8a45e5dfaf",
      "name": "AI — Extract Structured Expense Data",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        3552,
        256
      ]
    },
    {
      "id": "1355837d-9b0a-4eed-997f-1ea3ae165acf",
      "name": "Parse — Expense Extraction Output",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        256
      ]
    },
    {
      "id": "d83c533d-1cf8-4fa4-83fa-f6fa16a64bf9",
      "name": "Telegram — Confirm Expense Before Save",
      "type": "n8n-nodes-base.telegram",
      "position": [
        5200,
        256
      ]
    },
    {
      "id": "d4d8ec37-2ffa-4d14-a66b-96cc97dacbb7",
      "name": "Prepare — Add Person Name",
      "type": "n8n-nodes-base.set",
      "position": [
        5392,
        256
      ]
    },
    {
      "id": "2db75d68-4c1d-4050-a8ba-f9762c63f393",
      "name": "Filter — Only Approved Expenses",
      "type": "n8n-nodes-base.filter",
      "position": [
        5600,
        256
      ]
    },
    {
      "id": "f880bafe-d5ff-43f3-a1b1-be47c2d4adea",
      "name": "Sheets — Save Expense",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        5792,
        256
      ]
    },
    {
      "id": "575b4efd-f1f0-4a8f-b13d-cdcbd65bec72",
      "name": "Telegram — Expense Saved Confirmation",
      "type": "n8n-nodes-base.telegram",
      "position": [
        5984,
        256
      ]
    },
    {
      "id": "6dd3ad87-9410-4d23-aad6-afbe14d233be",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4560,
        -928
      ],
      "parameters": {
        "width": 736,
        "height": 1424,
        "content": "## HOW IT WORKS — AI TELEGRAM EXPENSE TRACKER\n\nThis workflow automatically converts Telegram messages into structured expenses using AI.\n\nInstead of filling out forms, simply send a natural message li"
      }
    },
    {
      "id": "59d9a681-502e-489e-a931-1b314eddb7a4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3568,
        -80
      ],
      "parameters": {
        "width": 704,
        "height": 576,
        "content": "## INPUT\nWhen a new Telegram message is received, the workflow first performs a **security validation**.\nOnly messages from approved Telegram users are allowed to continue.\n\nThis prevents unauthorized"
      }
    },
    {
      "id": "3445cc94-ae89-486c-9a86-9fe37e1ba310",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2736,
        -80
      ],
      "parameters": {
        "width": 1136,
        "height": 576,
        "content": "## AI DETECTION LAYER\nThis section uses AI to determine whether an incoming Telegram message actually contains an expense.\n\nInstead of processing every message, the workflow first performs a lightweig"
      }
    },
    {
      "id": "7504dec5-0779-4f08-bb40-359d1e5a9ba3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1552,
        -80
      ],
      "parameters": {
        "width": 4496,
        "height": 576,
        "content": "## CATEGORY INTELLIGENCE - Smart Category Handling\nThis section ensures that every expense is assigned to the correct category.\n\nFirst, the workflow loads your existing categories from Google Sheets a"
      }
    },
    {
      "id": "f154793b-d1e9-42c5-8f13-21edb177b88e",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3136,
        -80
      ],
      "parameters": {
        "width": 1008,
        "height": 576,
        "content": "## EXPENSE EXTRACTION\nIn this section, the workflow uses AI to transform the detected expense message into structured data.\n\nThe AI receives the original chat message together with the current categor"
      }
    },
    {
      "id": "54a789a8-ea82-4833-a0c2-1127fd2459e2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4592,
        -80
      ],
      "parameters": {
        "width": 1584,
        "height": 576,
        "content": "## APPROVAL & SAVE\n\nBefore saving the expense, the workflow asks the user for final confirmation via Telegram.\nThis ensures that extracted data is correct and prevents incorrect entries from being sto"
      }
    }
  ],
  "connections": {
    "Sheets — Save Expense": {
      "main": [
        [
          {
            "node": "Telegram — Expense Saved Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram - Receive Message": {
      "main": [
        [
          {
            "node": "Security — Allow Approved Chat IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare — Add Person Name": {
      "main": [
        [
          {
            "node": "Filter — Only Approved Expenses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI — Detect Expense Message": {
      "main": [
        [
          {
            "node": "Parse — Expense Detection Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decision — Category Exists?": {
      "main": [
        [
          {
            "node": "Telegram — Ask To Create New Category",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare — Category Prompt Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge — Expense + Categories": {
      "main": [
        [
          {
            "node": "AI — Extract Structured Expense Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pass Through — Category Data": {
      "main": [
        [
          {
            "node": "Telegram — Category Created Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare — Updated Categories": {
      "main": [
        [
          {
            "node": "Format — Rebuild Category Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheets — Add Edited Category": {
      "main": [
        [
          {
            "node": "Prepare — Category Fields (Form)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decision — Category Approved?": {
      "main": [
        [
          {
            "node": "Sheets — Add Suggested Category",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram — Edit New Category Form",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI — Classify Expense Category": {
      "main": [
        [
          {
            "node": "Parse — Category Classification Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format — Build Category Prompt": {
      "main": [
        [
          {
            "node": "AI — Classify Expense Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter — Only Approved Expenses": {
      "main": [
        [
          {
            "node": "Sheets — Save Expense",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheets — Add Suggested Category": {
      "main": [
        [
          {
            "node": "Prepare — Category Fields (Auto)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format — Rebuild Category Prompt": {
      "main": [
        [
          {
            "node": "Merge — Expense + Categories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse — Expense Detection Output": {
      "main": [
        [
          {
            "node": "Filter — Only Continue If Expense",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare — Category Fields (Auto)": {
      "main": [
        [
          {
            "node": "Pass Through — Category Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare — Category Fields (Form)": {
      "main": [
        [
          {
            "node": "Pass Through — Category Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter — Only Continue If Expense": {
      "main": [
        [
          {
            "node": "Sheets — Load Existing Categories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse — Expense Extraction Output": {
      "main": [
        [
          {
            "node": "Telegram — Confirm Expense Before Save",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare — Category Prompt Payload": {
      "main": [
        [
          {
            "node": "Merge — Expense + Categories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheets — Load Existing Categories": {
      "main": [
        [
          {
            "node": "Format — Build Category Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram — Edit New Category Form": {
      "main": [
        [
          {
            "node": "Sheets — Add Edited Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Security — Allow Approved Chat IDs": {
      "main": [
        [
          {
            "node": "AI — Detect Expense Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI — Extract Structured Expense Data": {
      "main": [
        [
          {
            "node": "Parse — Expense Extraction Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram — Ask To Create New Category": {
      "main": [
        [
          {
            "node": "Decision — Category Approved?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse — Category Classification Output": {
      "main": [
        [
          {
            "node": "Decision — Category Exists?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram — Confirm Expense Before Save": {
      "main": [
        [
          {
            "node": "Prepare — Add Person Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram — Category Created Confirmation": {
      "main": [
        [
          {
            "node": "Prepare — Updated Categories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}