{
  "name": "Query personal finance data in Notion via Telegram and WhatsApp",
  "nodes": [
    {
      "id": "1dc32a36-fbd0-42f3-ac17-4793146b433b",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        624,
        256
      ],
      "parameters": {
        "sessionKey": "1",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "953a2f07-2e7f-456e-8482-ed574652f5a3",
      "name": "Send message",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        1248,
        -64
      ],
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "689568790917776",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ \"recipent phone number\" }}"
      },
      "typeVersion": 1
    },
    {
      "id": "96364ebf-57cc-4586-a4f4-b915f4143e34",
      "name": "Accountant Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        688,
        32
      ],
      "parameters": {
        "text": "=Query: {{ $json.message.text}}\nCurrent Date {{ $now }}",
        "options": {
          "systemMessage": "=# Overview\nYou are a Accountant Agent who can retrieve and summarize information from all my notion databases relating to my personal finance using the 3 tools.\n\n# Tools\n1) Get Databases Tool - Get list of all databases with name and id.\n2) Get Notion Database Properties Tool - Get all the properties from a database based on database id.\n3) Query Notion Database Pages Tool - Get the list of rows based on database id and filters created based on input\n\n# Instructions\n1) Use the \"Get Databases Tool\" to get the list of databases from you notion account and return the database id based on selected database based on name similarity with input.\n2) Use the \"Get Notion Database Properties Tool\" to get the properties of the databases based on databaseId selected\n3) Based on the properties obtained from previous step and user input create a notion filter json.\n4) Use the \"Query Notion Database Pages Tool\", with the notion filter json on the database id obtained before to get the data you requested from notion database.\n\n# Examples\n\n1) Always use the **Financial Transactions** database when user input mentions expenses or transactions.  \n   - `Amount` → property for the money value  \n   - `Date` → property for the transaction date  \n   - `Type` (or similar) → filter where value = \"Expense\"\n\n2) When the user asks “this month”, build a Notion filter JSON:\n```json\n{\n  \"and\": [\n    { \"property\": \"Type\", \"select\": { \"equals\": \"Expense\" } },\n    { \"property\": \"Date\", \"date\": { \"on_or_after\": \"YYYY-MM-01\" } },\n    { \"property\": \"Date\", \"date\": { \"on_or_before\": \"YYYY-MM-31\" } }\n  ]\n}\n```\n\n3) Sum all the `Amount` values from the filtered rows and return the total.\n\n# Notes\n- Expenses → **Financial Transaction Database**  \n- Budget → **Budget Database**  \n- Funds (yearly plan to spend on big things or irregular expenditure) → **Funds Database**\n- Income -> **Income Database**\n- Assets and Liabilities -> **Assets and Liabilities**",
          "returnIntermediateSteps": true
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "faafeeeb-939b-409c-8bf4-b30a145bf058",
      "name": "Get Databases Tool",
      "type": "n8n-nodes-base.notionTool",
      "position": [
        752,
        256
      ],
      "parameters": {
        "resource": "database",
        "operation": "getAll",
        "returnAll": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "863b4560-b048-4d80-8ac7-98d083615b22",
      "name": "Query Notion Database Pages Tool",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        896,
        256
      ],
      "parameters": {
        "url": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('URL', \"Notion api url to get database rows with database id like - `https://api.notion.com/v1/databases/{database_id}/query`\", 'string') }}",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('JSON', ``, 'json') }}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "toolDescription": "Get rows from Notion Database based on database id and filters                                             ",
        "nodeCredentialType": "notionApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "49a583b8-6fa2-46b7-a098-526952d48ad2",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        304,
        32
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "877008f0-db36-4689-a06b-ad15465f88f6",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1248,
        128
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{\"chat_id\"}}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "cdddeed2-10bf-4a8c-b333-56b86dd4b168",
      "name": "Get Notion Database Properties Tool",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        1056,
        256
      ],
      "parameters": {
        "url": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('URL', \"Notion api to get database properties with database id like - `https://api.notion.com/v1/databases/{database_id}`\", 'string') }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "toolDescription": "Get Properties of notion database",
        "nodeCredentialType": "notionApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "1b1a008b-322e-4a79-9d03-d9c2bfcad942",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        -144
      ],
      "parameters": {
        "width": 704,
        "height": 528,
        "content": "## Step 2 - Agent\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "02e7fb48-5f2d-4e82-9736-e0187b1f184a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -144
      ],
      "parameters": {
        "color": 4,
        "width": 208,
        "height": 528,
        "content": "## Step 1 - Trigger\n"
      },
      "typeVersion": 1
    },
    {
      "id": "66ac405f-9fe2-4702-959d-5f7a38a0ddd0",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        -144
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 528,
        "content": "## Step 3 - Send Message\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "dce6393b-994d-421c-ae76-4a9561ebe388",
      "name": "claude-3.5-sonnet",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        496,
        256
      ],
      "parameters": {
        "model": "anthropic/claude-3.5-sonnet",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "bacc7b49-798d-4b2d-91cc-843b4d94c1fb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        384
      ],
      "parameters": {
        "color": 5,
        "width": 1200,
        "height": 1408,
        "content": "## 📝 Query personal finance data in Notion via Telegram and WhatsApp\n\n#### This workflow acts as an **Accountant Agent** to automatically answer questions about your personal finances by retrieving and summarizing data from your Notion databases.\n\n### **Step 1 – Trigger**\n\n* The workflow starts when you send a query (for example: *“Total expenses for August 2025”*) via **Telegram** or **WhatsApp**.\n* The message is captured by the **Telegram Trigger** node.\n* Example input:\n\n  * `Total expenses for August 2025`\n\n### **Step 2 – Accountant Agent**\n\n* The query is passed to the **Accountant Agent** (powered by GPT-4o via OpenRouter).\n* The Agent uses **Simple Memory** to maintain conversation context.\n* The Agent has access to three Notion tools:\n\n  1. **Get Databases Tool** → Fetches all databases (e.g., Financial Transactions, Budget, Income).\n  2. **Get Notion Database Properties Tool** → Reads the schema of the selected database.\n  3. **Query Notion Database Pages Tool** → Pulls rows based on filters created from your query.\n\n### **How the Agent Works**\n\n1. **Identifies the right database**:\n\n   * Expenses/Transactions → **Financial Transactions** database\n   * Income → **Income Database**\n   * Assets/Liabilities → **Assets & Liabilities** database\n   * Budget → **Budget Database**\n\n2. **Creates the Notion filter JSON** based on your query.\n   Example for *“Total expenses this month”*:\n\n   ```json\n   {\n     \"and\": [\n       { \"property\": \"Type\", \"select\": { \"equals\": \"Expense\" } },\n       { \"property\": \"Date\", \"date\": { \"on_or_after\": \"2025-08-01\" } },\n       { \"property\": \"Date\", \"date\": { \"on_or_before\": \"2025-08-31\" } }\n     ]\n   }\n   ```\n\n3. **Runs the query**, fetches all matching rows, and sums the `Amount` field.\n\n### **Step 3 – Response**\n\n* The summarized result (like total expenses or income) is sent back to you via:\n\n  * **Telegram** (chat message)\n  * **WhatsApp** (text message)\n\n* Example output:\n\n  * *“Your total expenses for August 2025 are ₹42,350.”*\n\n✅ With this setup, you just type queries in natural language, and the bot automatically talks to Notion, runs the calculations, and sends answers back to your phone instantly.\n "
      },
      "typeVersion": 1
    },
    {
      "id": "4ed7acf4-7d71-4aa5-ab1f-274bbce5cace",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 1200,
        "height": 3824,
        "content": "## Create Account and Get Credentials for the below Tools\n\n* **Telegram**: Bot Token, **Chat ID** (or a recent **Message ID** for testing)\n* **OpenRouter**: API Key\n* **Notion**: Integration Token\n* **WhatsApp (Meta)**: Phone Number ID, WhatsApp Business Account ID, **Permanent Access Token**\n\n## 1) Telegram — Create Bot & Get IDs\n\n### 1.1 Create a bot with **@BotFather**\n\n1. Open Telegram → search **BotFather** → Start.\n2. Send: `/newbot`\n3. Give it a **name** (e.g., `Accountant AI`), then a **username** ending in `bot` (e.g., `accountant_ai_helper_bot`).\n4. BotFather returns a **HTTP API Token** → **save it** (this is your **Bot Token**).\n\n### 1.2 Get your **Chat ID** (two quick methods)\n\n**Method A — via n8n trigger (easiest):**\n\n1. In n8n, add **Telegram Trigger** node and connect your bot token in credentials.\n2. Start the workflow → send any message to your bot.\n3. Run once / listen → inspect the incoming message in the node output → copy `chat.id`.\n\n**Method B — via Telegram API (curl):**\n\n1. First, send a message to your bot so there is at least one update.\n2. Run:\n\n```bash\ncurl -s \"https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates\" | jq\n```\n\n3. Find `result[0].message.chat.id` → that’s your **Chat ID**.\n\n> You can also grab a **Message ID** from `result[0].message.message_id` for testing.\n\n### 1.3 Plug into n8n\n\n* **Telegram Trigger**: use your Bot Token.\n* **Telegram node (Send Message)**: set `chatId = <YOUR_CHAT_ID>` (or pass from previous node JSON).\n\n**Suggested env vars**\n\n```bash\nTELEGRAM_BOT_TOKEN=XXX:YYYY\nTELEGRAM_CHAT_ID=123456789\n```\n\n## 2) OpenRouter — API Key\n\n1. Sign up / log in to **OpenRouter**.\n2. Create a new **API Key**.\n3. In n8n → **Credentials** → choose your OpenRouter credential type → paste the key.\n4. In your LLM node, set the **model** you plan to use (e.g., `anthropic/claude-3.5-sonnet`).\n\n\n## 3) Notion — Duplicate Template & Get Credentials\n\n### 3.1 Duplicate your Notion template\n\n1. Open [Personal Finance System Notion template link](https://www.notion.so/templates/personal-finance-system) ( → click **Duplicate** (top-right) to add it to your workspace.\n\n### 3.2 Create a Notion **Integration** (Internal)\n\n1. Go to **Notion → Settings & members → Connections → Develop or Manage integrations**.\n2. Create **New integration** → give it a name (e.g., `Accountant AI`), select your workspace.\n3. Copy the **Internal Integration Token** (bearer token).\n4. In the Integrations sidebar tab, click on the integration 'Accountant AI', select \"Access\" Tab, click on \"Edit access\" tab, and in the Teamspaces Pages, find \"Personal Finance System\" Page, check it and Update the Access.\n\n### 3.3 Plug into n8n\n\n* Use the built-in **Notion** credentials (paste `NOTION_TOKEN`).\n* For custom HTTP Request Tool nodes, target endpoints like:\n\n  * `POST https://api.notion.com/v1/databases/{database_id}/query`\n  * `GET  https://api.notion.com/v1/databases/{database_id}` (for properties)\n* Required headers:\n\n```http\nAuthorization: Bearer <NOTION_TOKEN>\nNotion-Version: 2022-06-28\nContent-Type: application/json\n```\n\n\n## 4) WhatsApp (Meta) — Business Setup & Credentials\n\n### 4.1 Prereqs\n\n* **Facebook Business Manager** account\n* **Meta App** (in **Developers**)\n* A **phone number** for WhatsApp Business (can be a fresh number)\n\n### 4.2 Create a WhatsApp Business app\n\n1. Go to **developers.facebook.com** → **My Apps** → **Create App** → choose **Business** (or **Other** with WhatsApp product).\n2. Add the **WhatsApp** product to your app.\n3. In **WhatsApp → Getting Started**, link a **WhatsApp Business Account (WABA)**.\n\nYou’ll need to note:\n\n* **WhatsApp Business Account ID (WABA ID)**\n* **Phone Number ID**\n* **Access Token** (start with a **temporary** one for testing)\n\n### 4.3 Generate a **Permanent Access Token** (recommended)\n\n* In **Business Settings → System Users**: create a **System User** → assign **WhatsApp** permissions → **Generate Token** for that user with **never expires** option. Store **App ID/Secret** too.\n\n**Env vars**\n\n```bash\nMETA_WABA_ID=1234567890\nMETA_PHONE_NUMBER_ID=111222333444555\nMETA_ACCESS_TOKEN=EAAG... (long string)\n```\n\n### 4.4 Send a message via Graph API\n\n**Curl test**\n\n```bash\ncurl -X POST \\\n  https://graph.facebook.com/v20.0/${META_PHONE_NUMBER_ID}/messages \\\n  -H \"Authorization: Bearer ${META_ACCESS_TOKEN}\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"messaging_product\": \"whatsapp\",\n    \"recipient_type\": \"individual\",\n    \"to\": \"<E164_PHONE_NUMBER>\",\n    \"type\": \"text\",\n    \"text\": { \"preview_url\": false, \"body\": \"Hello from n8n!\" }\n  }'\n```\n\n**In n8n**\n\n* Use the **WhatsApp node** (or **HTTP Request** node) with the same endpoint.\n* Required fields: `phoneNumberId`, `to`, and a `text` or template payload.\n\n**Templates (optional, recommended for outbound)**\n\n* In **WABA → Message Templates**, create and **submit for approval** (e.g., `finance_update`).\n* Once approved, you can send templated notifications without prior user messages.\n\n---\n\n## 5) Recommended Credential Names in n8n\n\n* **Telegram API**: `Accountant AI` (Bot Token)\n* **OpenRouter**: `OpenRouter account`\n* **Notion API**: `Notion account`\n* **WhatsApp API**: `Accountant AI` (WABA credentials)\n\nMatch these names in your existing nodes so you don’t have to rewire connections.\n\n---\n\n## 6) Minimal sanity checks\n\n* **Telegram**: `getUpdates` returns your sent message → Chat ID correct\n* **OpenRouter**: Call a trivial prompt node → no 401\n* **Notion**: `GET /v1/databases/{id}` works → Integration has access\n* **WhatsApp**: `POST /{PHONE_NUMBER_ID}/messages` returns `messages[0].id` → token/ID valid\n\n---\n\n## 7) Quick reference — Headers & Endpoints\n\n**Notion**\n\n```http\nBase: https://api.notion.com/v1\nAuth: Authorization: Bearer <NOTION_TOKEN>\nVer:  Notion-Version: 2022-06-28\n```\n\n* Query DB: `POST /databases/{id}/query`\n* Get DB:  `GET  /databases/{id}`\n\n**Telegram**\n\n* `GET https://api.telegram.org/bot<BOT_TOKEN>/getUpdates`\n* `POST https://api.telegram.org/bot<BOT_TOKEN>/sendMessage`\n\n**WhatsApp (Graph API)**\n\n* `POST https://graph.facebook.com/v20.0/{PHONE_NUMBER_ID}/messages`\n* Webhooks: App dashboard → WhatsApp → **Configure Webhooks**\n\n---\n\n## 8) Security tips\n\n* Never commit tokens to Git. Use n8n **Credentials** or environment variables.\n* Rotate long‑lived tokens periodically.\n* Scope the Notion integration to **read‑only** unless you plan to write back.\n* Restrict who can message your Telegram bot (check chat IDs in workflow).\n\n---\n\n## 9) Plug into your existing workflow\n\n* Update the **Telegram Trigger** and **Telegram Send** nodes with the new **Telegram credential** + `messageId`.\n* Confirm the **LLM node** uses the **OpenRouter** credential and desired model.\n* Ensure the **Notion** HTTP Tool nodes use the **Notion** credential.\n* For **WhatsApp**, point your **Send message** node to the correct `phoneNumberId` and ensure the access token is valid (permanent if possible).\n\n> Once these are in, your Personal Finance workflow can answer “Total expenses this month?” via Telegram without manual lookups. 🚀\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Accountant Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Accountant Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Accountant Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "claude-3.5-sonnet": {
      "ai_languageModel": [
        [
          {
            "node": "Accountant Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Databases Tool": {
      "ai_tool": [
        [
          {
            "node": "Accountant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message": {
      "main": [
        []
      ]
    },
    "Query Notion Database Pages Tool": {
      "ai_tool": [
        [
          {
            "node": "Accountant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Notion Database Properties Tool": {
      "ai_tool": [
        [
          {
            "node": "Accountant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
