{
  "name": "Track expenses automatically with Telegram Bot using GPT-4o, OCR and voice recognition",
  "nodes": [
    {
      "id": "b591a5c7-e6f3-4a29-b73f-93ebee2c031a",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1968,
        912
      ],
      "parameters": {
        "width": 208,
        "height": 304,
        "content": "## Message Trigger"
      }
    },
    {
      "id": "e5edd200-825e-4da0-b807-6f153acfed6c",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2448,
        480
      ],
      "parameters": {
        "width": 688,
        "height": 1472,
        "content": "# Personal Expense Tracker \n## Quick Start Guide\n## 1. Setup Telegram\n### 1.1 Create Telegram Bot\n - https://blog.n8n.io/create-telegram-bot/\n### 1.2 Setup Telegram Credentials for each Telegram Node:"
      }
    },
    {
      "id": "40ad1d9c-484a-44f5-9428-80696c6f65a1",
      "name": "Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1920,
        1024
      ]
    },
    {
      "id": "7501af4e-cb14-47b8-ba5b-f91389a0c6a2",
      "name": "JsonStorageMcp",
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "position": [
        96,
        1744
      ]
    },
    {
      "id": "ff3d434c-68ec-4ff6-a790-34cbc65ee2c4",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        352,
        1744
      ]
    },
    {
      "id": "fc175bad-072b-4740-b463-08ee226383f7",
      "name": "ExpenseAssistant",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        -80,
        1520
      ]
    },
    {
      "id": "b0269ed8-4f74-4a09-ac95-ecbec2c4fd91",
      "name": "Gpt4o",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        -160,
        1248
      ]
    },
    {
      "id": "c2aad759-3504-48e4-833a-771398ff586a",
      "name": "Think",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        224,
        1744
      ]
    },
    {
      "id": "89a37291-a019-488c-9ada-604f5460d638",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        912
      ],
      "parameters": {
        "width": 960,
        "height": 400,
        "content": "## Get Chat Message / Audio Text\nDetect message type (/start, text, photo, file, audio) and route to the correct handler. \nText and audio messages are passed to the AI agent as-is.\n"
      }
    },
    {
      "id": "c245ce07-5c27-4096-8f16-85c3766a285d",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1136,
        1024
      ]
    },
    {
      "id": "197310fd-2237-414a-84a0-ec7e2fada7b3",
      "name": "TextOutput",
      "type": "n8n-nodes-base.set",
      "position": [
        -592,
        976
      ]
    },
    {
      "id": "ab6e3624-de0d-4043-ba72-3e62ee120d01",
      "name": "WelcomeMessage",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -544,
        736
      ]
    },
    {
      "id": "7c9b6743-39ec-4195-8792-dff233a859b1",
      "name": "AudioOutput",
      "type": "n8n-nodes-base.set",
      "position": [
        -592,
        1136
      ]
    },
    {
      "id": "35cd08cb-7dc2-4a5c-9454-47a9f9ce8dac",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        912
      ],
      "parameters": {
        "width": 288,
        "height": 480,
        "content": "## Result / Reply Message\nSends reply to the user"
      }
    },
    {
      "id": "c2ce80fa-f214-4dcc-a9bc-e182000d5125",
      "name": "AgentInput",
      "type": "n8n-nodes-base.set",
      "position": [
        -352,
        1056
      ]
    },
    {
      "id": "3db36880-18d1-408b-bcbf-a3578e471535",
      "name": "NotAuthorizedMessage",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1392,
        1248
      ]
    },
    {
      "id": "a4f01f8a-1317-4b4c-b447-e398702c6abf",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1760,
        912
      ],
      "parameters": {
        "width": 576,
        "height": 496,
        "content": "## Ensure Bot Privacy\nOn first use, the bot stores the user ID and locks access to that user. Any other user will receive an “unauthorized” message.\n"
      }
    },
    {
      "id": "17330fc2-6492-4e95-a07c-f7c6778ec66a",
      "name": "IfAccessAllowed",
      "type": "n8n-nodes-base.if",
      "position": [
        -1376,
        1024
      ]
    },
    {
      "id": "4ef7ad67-59c1-4dce-87e5-098da8cbdccc",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -624,
        656
      ],
      "parameters": {
        "width": 400,
        "height": 256,
        "content": "## Start Message Reply\nSend user welcome message (first use)"
      }
    },
    {
      "id": "f883ad91-ce2b-4cca-a90d-901633cbba0f",
      "name": "IfFirstRun",
      "type": "n8n-nodes-base.if",
      "position": [
        -1712,
        1504
      ]
    },
    {
      "id": "7de993d2-81c0-4543-93b2-4d8453c608d1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1760,
        1408
      ],
      "parameters": {
        "width": 576,
        "height": 288,
        "content": "## First Run - Save Config\nOn first use remember user chat_id to enable authorization check in future"
      }
    },
    {
      "id": "7a9d43ec-7b81-4c8e-9222-6dd190645516",
      "name": "ReplyText",
      "type": "n8n-nodes-base.telegram",
      "position": [
        288,
        1056
      ]
    },
    {
      "id": "eaf63cad-d3a8-4e15-afcf-9a77e52b0b76",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        1312
      ],
      "parameters": {
        "width": 960,
        "height": 384,
        "content": "## Get Document / Photo Text\nFor photo / file upload get file content and forward to agent with appropriate prefix to make it clear that content is coming from attached file.\n"
      }
    },
    {
      "id": "99cd1c7f-0e34-47f5-8245-91410420cf6a",
      "name": "FileOutput",
      "type": "n8n-nodes-base.set",
      "position": [
        -592,
        1408
      ]
    },
    {
      "id": "a8d8281f-20d8-4039-9977-240372e8af46",
      "name": "GetAudioFile",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -880,
        1136
      ]
    },
    {
      "id": "ab30a917-2a51-4683-889a-dcb83b99e47d",
      "name": "ExtractFileText",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -736,
        1408
      ]
    },
    {
      "id": "b7f8abf7-8a0a-4737-8ebf-bed1493b4cb1",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        912
      ],
      "parameters": {
        "width": 448,
        "height": 480,
        "content": "## Root Agent Processing\nMain agent responsible to forward messages to expense assistant, validate response, reject irrelevant topics, in future can be extended with more assistant connections"
      }
    },
    {
      "id": "a8a31b8b-09fc-4757-90ca-050d6ce6b90d",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        1392
      ],
      "parameters": {
        "width": 736,
        "height": 560,
        "content": "## Expense Assistant\nExpense assistant - handles the core logic about expenses, uses storage, calculator tools to process request"
      }
    },
    {
      "id": "3dd328b8-b601-4ff8-a3ee-aa09295aa872",
      "name": "AssitantMemory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -48,
        1744
      ]
    },
    {
      "id": "0a183256-83ac-4e0c-9173-0affc14a6368",
      "name": "SimpleMemory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -64,
        1248
      ]
    },
    {
      "id": "a304ae46-8c14-423b-8ebd-3ef4ad1156d6",
      "name": "AIAgent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -160,
        1056
      ]
    },
    {
      "id": "528c64fe-cb38-40c0-b847-149ec391e413",
      "name": "TranscribeAudio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -736,
        1136
      ]
    },
    {
      "id": "529f8d23-31c2-41d6-a721-a8a2760003c6",
      "name": "Input",
      "type": "n8n-nodes-base.set",
      "position": [
        -1728,
        1024
      ]
    },
    {
      "id": "f7a90943-7f8e-45e5-917c-0d2a8c5acc74",
      "name": "GetAttachedFile",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -880,
        1408
      ]
    },
    {
      "id": "af85b4d7-23ee-44e8-9ae1-77c443808701",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        656
      ],
      "parameters": {
        "width": 560,
        "height": 256,
        "content": "## Add processing started message\nNotify user about processing start (with message ... )"
      }
    },
    {
      "id": "3472eaa5-12ef-41c6-9562-2c430ebb0332",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        1696
      ],
      "parameters": {
        "width": 656,
        "height": 256,
        "content": "## Remove processing message\nAfter processing is complete, this part deletes temporary \"processing\" (\"...\") message"
      }
    },
    {
      "id": "3be5a7aa-b70e-4143-af04-cf0b3984ba36",
      "name": "IfStateExist",
      "type": "n8n-nodes-base.if",
      "position": [
        -624,
        1792
      ]
    },
    {
      "id": "96232073-4006-42f3-b19b-9ce30853f1f9",
      "name": "DeleteProcessing",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -384,
        1792
      ]
    },
    {
      "id": "8d890581-cfe2-4b0e-b6ee-732978b0d697",
      "name": "Think1",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        48,
        1248
      ]
    },
    {
      "id": "aef6541d-fcde-49e8-80af-63f23509bdbe",
      "name": "Cleanup",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1696,
        1792
      ]
    },
    {
      "id": "f57b4394-872c-44a0-96e9-c2990ec22447",
      "name": "ForEachCategory",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1504,
        1792
      ]
    },
    {
      "id": "0077379d-2fda-451e-8b6c-1d8045d8c2db",
      "name": "ForEachCategoryItem",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1296,
        1792
      ]
    },
    {
      "id": "e09b5aa4-e64d-415b-8e18-f08aa005a98c",
      "name": "DeleteItem",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1072,
        1792
      ]
    },
    {
      "id": "73a49d7e-ae53-4dfb-863a-e696b1c95485",
      "name": "GetAttachedPhoto",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -880,
        1536
      ]
    },
    {
      "id": "a1fc3d64-ddf8-402c-b60f-a9e022f2f17d",
      "name": "ImageOutput",
      "type": "n8n-nodes-base.set",
      "position": [
        -592,
        1536
      ]
    },
    {
      "id": "9e7fa633-a3d5-4de1-b8b7-f056090069bf",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1760,
        1696
      ],
      "parameters": {
        "width": 880,
        "height": 256,
        "content": "## Cleanup / Reset\nThis is **MANUAL** trigger to full data cleanup. **Warning - this will DELETE ALL DATA** stored in your **Ainoflow** account"
      }
    },
    {
      "id": "424964de-61df-4f24-97a4-ae6f5d74b478",
      "name": "ExtractImageText",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -736,
        1536
      ]
    },
    {
      "id": "8272ec82-344c-4769-91ac-ccebce125777",
      "name": "SendProcessing",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1104,
        752
      ]
    },
    {
      "id": "90dc3683-4e85-4c79-a44d-52f04e2d6e39",
      "name": "GetExecutionState",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -816,
        1792
      ]
    },
    {
      "id": "bf8eec4b-64b7-4580-840b-f2d910e949b7",
      "name": "Sonnet45",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        -176,
        1744
      ]
    },
    {
      "id": "9cd45908-6cb1-499a-9e8c-95f4cc69e4e5",
      "name": "GetAppSettings",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1552,
        1024
      ]
    },
    {
      "id": "a5ed9d9e-8fb1-4fba-8537-d4fe91932517",
      "name": "SaveAppSettings",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1488,
        1488
      ]
    },
    {
      "id": "e6b007bf-589a-46b4-ae5e-0f0ae88bcd17",
      "name": "SaveExecutionState",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -912,
        752
      ]
    }
  ],
  "connections": {
    "Gpt4o": {
      "ai_languageModel": [
        [
          {
            "node": "AIAgent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Input": {
      "main": [
        [
          {
            "node": "GetAppSettings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Think": {
      "ai_tool": [
        [
          {
            "node": "ExpenseAssistant",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "WelcomeMessage",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "TextOutput",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "GetAudioFile",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "GetAttachedFile",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "GetAttachedPhoto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Think1": {
      "ai_tool": [
        [
          {
            "node": "AIAgent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AIAgent": {
      "main": [
        [
          {
            "node": "ReplyText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cleanup": {
      "main": [
        [
          {
            "node": "ForEachCategory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger": {
      "main": [
        [
          {
            "node": "Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sonnet45": {
      "ai_languageModel": [
        [
          {
            "node": "ExpenseAssistant",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AgentInput": {
      "main": [
        [
          {
            "node": "AIAgent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "ExpenseAssistant",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "FileOutput": {
      "main": [
        [
          {
            "node": "AgentInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IfFirstRun": {
      "main": [
        [
          {
            "node": "SaveAppSettings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TextOutput": {
      "main": [
        [
          {
            "node": "AgentInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AudioOutput": {
      "main": [
        [
          {
            "node": "AgentInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ImageOutput": {
      "main": [
        [
          {
            "node": "AgentInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetAudioFile": {
      "main": [
        [
          {
            "node": "TranscribeAudio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IfStateExist": {
      "main": [
        [
          {
            "node": "DeleteProcessing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SimpleMemory": {
      "ai_memory": [
        [
          {
            "node": "AIAgent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AssitantMemory": {
      "ai_memory": [
        [
          {
            "node": "ExpenseAssistant",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "GetAppSettings": {
      "main": [
        [
          {
            "node": "IfFirstRun",
            "type": "main",
            "index": 0
          },
          {
            "node": "IfAccessAllowed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "JsonStorageMcp": {
      "ai_tool": [
        [
          {
            "node": "ExpenseAssistant",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "SendProcessing": {
      "main": [
        [
          {
            "node": "SaveExecutionState",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ExtractFileText": {
      "main": [
        [
          {
            "node": "FileOutput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ForEachCategory": {
      "main": [
        [
          {
            "node": "ForEachCategoryItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetAttachedFile": {
      "main": [
        [
          {
            "node": "ExtractFileText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IfAccessAllowed": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          },
          {
            "node": "SendProcessing",
            "type": "main",
            "index": 0
          },
          {
            "node": "GetExecutionState",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NotAuthorizedMessage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TranscribeAudio": {
      "main": [
        [
          {
            "node": "AudioOutput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ExpenseAssistant": {
      "ai_tool": [
        [
          {
            "node": "AIAgent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "ExtractImageText": {
      "main": [
        [
          {
            "node": "ImageOutput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetAttachedPhoto": {
      "main": [
        [
          {
            "node": "ExtractImageText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetExecutionState": {
      "main": [
        [
          {
            "node": "IfStateExist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ForEachCategoryItem": {
      "main": [
        [
          {
            "node": "DeleteItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}