{
  "id": "AWrjo9rRQdLaH6oQ",
  "meta": {
    "instanceId": "558d88703fb65b2d0e44613bc35916258b0f0bf983c5d4730c00c424b77ca36a",
    "templateCredsSetupCompleted": true
  },
  "name": "Logging invoice/transaction records in Notion directly from your gmail accounts",
  "tags": [],
  "nodes": [
    {
      "id": "0cedf57b-fd46-4aa1-8f1b-6ffa36a79e96",
      "name": "forwarding",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        1600,
        80
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "credential-id",
          "name": "gmailOAuth2 Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8a483cc2-9ec3-4b3c-9713-4968b9e956ef",
      "name": "Classify",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        2080,
        224
      ],
      "parameters": {
        "options": {},
        "inputText": "=Subject: {{ $json.Subject }}\n\n{{ $json.snippet }}\n",
        "categories": {
          "categories": [
            {
              "category": "Debit Invoice",
              "description": "=If it is an invoice of future payment or a pre debit notification and not a debit transaction"
            },
            {
              "category": "Debit Transaction",
              "description": "=If some amount has been debited from your account"
            },
            {
              "category": "Credit Transaction",
              "description": "=If some amount has been credited to your account"
            },
            {
              "category": "Credit Invoice",
              "description": "=If it is an invoice of future receival of funds to your account and not a credit transaction to your bank account"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "cb53694f-f9ce-441e-a7ef-ca6639d0b7a7",
      "name": "support@bayesian-labs",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        1600,
        464
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "credential-id",
          "name": "gmailOAuth2 Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "32f75b58-2b41-4cfc-b06b-7d6e24a221f7",
      "name": "anoop.karnik@bayesian-labs",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        1600,
        272
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "credential-id",
          "name": "gmailOAuth2 Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4cd774d6-960d-4598-91bb-4af218121049",
      "name": "Send Message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2976,
        96
      ],
      "webhookId": "e1631e8e-558e-4e77-b7d5-1f16ca5834a0",
      "parameters": {
        "text": "=This transaction email is from {{ $('Set Email Data').item.json.From }} to {{ $('Set Email Data').item.json.To }}\n\nSubject: {{ $('Set Email Data').item.json.Subject }}\n\n{{ $('Set Email Data').item.json.snippet }}",
        "chatId": "={{chat_id}}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "credential-id",
          "name": "telegramApi Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3374d3d1-f916-4dfd-827e-4678b697830e",
      "name": "Create Invoice Tool",
      "type": "n8n-nodes-base.notionTool",
      "position": [
        2704,
        256
      ],
      "parameters": {
        "title": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Title', ``, 'string') }}",
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "82d3a838-5c66-4efe-97f6-c415dd0c62ef",
          "cachedResultUrl": "https://www.notion.so/82d3a8385c664efe97f6c415dd0c62ef",
          "cachedResultName": "Financial Transaction"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Type|select",
              "selectValue": "={{ \"Invoice\" }}"
            },
            {
              "key": "Cost|number",
              "numberValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues1_Number', ``, 'number') }}"
            },
            {
              "key": "Transaction Description|rich_text",
              "textContent": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues2_Text', ``, 'string') }}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "credential-id",
          "name": "notionApi Credential"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4f3acda7-3c4e-4f36-9044-cff3f405e510",
      "name": "Accountant Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2560,
        32
      ],
      "parameters": {
        "text": "=Subject: {{ $json.Subject }}\n\nMessage: {{ $json.snippet }}",
        "options": {
          "systemMessage": "=You are a Accountant Agent.\n\nFor every incoming email, use the subject and message to determine if it describes a invoice for a debit transaction for the future\n\n    Create a notion database page using the “Create Invoice Tool” tool.\n\n    If the amount is in dollars (USD), automatically convert it to rupees (INR) using the latest available exchange rate (or ₹88/USD if none given).\n\n    For every created invoice, add a clear title, the INR cost, and a concise description based on the email’s subject and message."
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "2190e9fd-0caa-45d2-ba62-79aec69058a0",
      "name": "Accountant Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2560,
        432
      ],
      "parameters": {
        "text": "=Subject: {{ $json.Subject }}\n\nMessage: {{ $json.snippet }}",
        "options": {
          "systemMessage": "=You are a Accountant Agent.\n\nFor every incoming email, use the subject and message to determine if it describes a debit transaction.\n\n    Create a notion database page using the “Create Transaction Tool” tool.\n\n    If the amount is in dollars (USD), automatically convert it to rupees (INR) using the latest available exchange rate (or ₹88/USD if none given).\n\n    For every created debit transaction, add a clear title, the INR cost, and a concise description based on the email’s subject and message."
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "208f9201-fb04-4789-b5f0-e0b19a8e1812",
      "name": "Accountant Agent2",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2560,
        832
      ],
      "parameters": {
        "text": "=Subject: {{ $json.Subject }}\n\nMessage: {{ $json.snippet }}",
        "options": {
          "systemMessage": "=You are a Accountant Agent.\n\nFor every incoming email, use the subject and message to determine if it describes a credit to your account or credit transaction.\n\n    Create a notion database page using the “Create Income Tool” tool.\n\n    If the amount is in dollars (USD), automatically convert it to rupees (INR) using the latest available exchange rate (or ₹88/USD if none given).\n\n    For every created credit transaction, add a clear title, the INR cost, and a concise description based on the email’s subject and message."
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "257d35a6-d0d6-4f94-85e4-26e617139512",
      "name": "Create Transction Tool",
      "type": "n8n-nodes-base.notionTool",
      "position": [
        2656,
        656
      ],
      "parameters": {
        "title": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Title', ``, 'string') }}",
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "82d3a838-5c66-4efe-97f6-c415dd0c62ef",
          "cachedResultUrl": "https://www.notion.so/82d3a8385c664efe97f6c415dd0c62ef",
          "cachedResultName": "Financial Transaction"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Type|select",
              "selectValue": "={{ \"Debit\" }}"
            },
            {
              "key": "Cost|number",
              "numberValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues1_Number', ``, 'number') }}"
            },
            {
              "key": "Transaction Description|rich_text",
              "textContent": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues2_Text', ``, 'string') }}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "credential-id",
          "name": "notionApi Credential"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "dce36af5-9b57-42c0-b4a3-272a9b88a5e9",
      "name": "Create Income Tool",
      "type": "n8n-nodes-base.notionTool",
      "position": [
        2640,
        1056
      ],
      "parameters": {
        "title": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Title', ``, 'string') }}",
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "2501d3fa-a0a0-80c5-b74e-d64686678b0f",
          "cachedResultUrl": "https://www.notion.so/2501d3faa0a080c5b74ed64686678b0f",
          "cachedResultName": "Income"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Received Amount|number",
              "numberValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues1_Number', ``, 'number') }}"
            },
            {
              "key": "Description|rich_text",
              "textContent": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues2_Text', ``, 'string') }}"
            },
            {
              "key": "Type|select",
              "selectValue": "={{ \"Credit\" }}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "credential-id",
          "name": "notionApi Credential"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e0378b46-f792-4727-9b15-40e0f9e5e50d",
      "name": "Set Email Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1904,
        256
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fffd75f0-e629-4e35-8ec6-0949df5ac639",
              "name": "snippet",
              "type": "string",
              "value": "={{ $json.snippet }}"
            },
            {
              "id": "bf222711-42a2-4dd9-be79-5e72631e9a61",
              "name": "To",
              "type": "string",
              "value": "={{ $json.To }}"
            },
            {
              "id": "40d42775-cf86-4d5d-93a2-79dac83c79b6",
              "name": "From",
              "type": "string",
              "value": "={{ $json.From }}"
            },
            {
              "id": "1d4e0cd9-d13e-45f1-911e-2762c98140f5",
              "name": "Subject",
              "type": "string",
              "value": "={{ $json.Subject }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c0a1d0e4-b8d1-406d-bbad-c9a950d667a1",
      "name": "Accountant Agent3",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2560,
        1344
      ],
      "parameters": {
        "text": "=Subject: {{ $json.Subject }}\n\nMessage: {{ $json.snippet }}",
        "options": {
          "systemMessage": "=You are a Accountant Agent.\n\nFor every incoming email, use the subject and message to determine if it describes a credit invoice.\n\n    Create a notion database page using the “Create Income Tool 1” tool.\n\n    If the amount is in dollars (USD), automatically convert it to rupees (INR) using the latest available exchange rate (or ₹88/USD if none given).\n\n    For every created credit transaction, add a clear title, the INR cost, and a concise description based on the email’s subject and message."
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "1dae2491-a946-4294-a1bf-d06453d5bddf",
      "name": "Create Income Tool1",
      "type": "n8n-nodes-base.notionTool",
      "position": [
        2640,
        1568
      ],
      "parameters": {
        "title": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Title', ``, 'string') }}",
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "2501d3fa-a0a0-80c5-b74e-d64686678b0f",
          "cachedResultUrl": "https://www.notion.so/2501d3faa0a080c5b74ed64686678b0f",
          "cachedResultName": "Income"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Received Amount|number",
              "numberValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues1_Number', ``, 'number') }}"
            },
            {
              "key": "Description|rich_text",
              "textContent": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('propertyValues2_Text', ``, 'string') }}"
            },
            {
              "key": "Type|select",
              "selectValue": "={{ \"Invoice\" }}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "credential-id",
          "name": "notionApi Credential"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "cb1b70b9-41ef-4707-a151-77c4395e45e8",
      "name": "gpt-5",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        2576,
        256
      ],
      "parameters": {
        "model": "openai/gpt-5",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "id": "credential-id",
          "name": "openRouterApi Credential"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f0ce6083-37cb-4997-a2d2-17a8878aff55",
      "name": "gpt-5-nano",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        2064,
        480
      ],
      "parameters": {
        "model": "openai/gpt-5-nano",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "id": "credential-id",
          "name": "openRouterApi Credential"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f1153d7e-4b76-49cc-a809-de1a19c55177",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -48
      ],
      "parameters": {
        "width": 1200,
        "height": 896,
        "content": "# Logging invoice/transaction records in Notion directly from your gmail accounts\n\n### How it works\nThe workflow acts as an **AI-powered Accountant Agent** that reads incoming Gmail messages and decides whether each email represents a **Debit Transaction, Credit Transaction, Debit Invoice, or Credit Invoice**.  \n\n- The **Gmail Trigger** watches your selected inboxes (like `forwarding@bayesian-labs.com`, `support@bayesian-labs`, `anoop.karnik@bayesian-labs`).  \n- The **Classifier (GPT-5-nano)** determines the correct transaction type.  \n- The appropriate **Agent (GPT-5)** then extracts amount, currency, and description details.  \n- The Agent uses Notion API tools to log structured data into your **Personal Finance System** Notion template (Financial Transactions & Income databases).  \n- Finally, a **Telegram notification** is sent summarizing the entry (From, To, Subject, Snippet).  \n\nIn short: every time your bank emails you — Notion gets updated, and you get notified.\n\n### How to set up\n1. **Duplicate the [Personal Finance System Notion template](https://www.notion.so/templates/personal-finance-system)** into your workspace.  \n2. Create a **Telegram Bot** with BotFather → copy the bot token and your chat ID.  \n3. Generate an **OpenRouter API key** for GPT-5 / GPT-5-nano.  \n4. Create a **Notion Integration Token** and connect it to your duplicated finance databases.  \n5. Add your **Gmail accounts** (`forwarding@`, `support@`, and/or personal Gmail) under **Gmail OAuth2 credentials** in n8n.  \n6. Import the workflow JSON into n8n → fill in the credential names as listed below:  \n   - `n8n_cloud_regular_usage` → OpenRouter  \n   - `Notion account` → Notion API  \n   - `Accountant AI` → Telegram Bot  \n   - Gmail OAuth2 for each inbox trigger  \n\nOnce active, n8n polls Gmail every minute, classifies emails, updates Notion, and sends Telegram updates.\n\n### Customization\nYou can extend this workflow to:  \n- Track **credit card statements**, **subscriptions**, or **payroll notifications**.  \n- Add **Slack or WhatsApp** alerts alongside Telegram.  \n- Include **live FX rates** for USD→INR conversion using an API node.  \n- Connect **Google Sheets** as a backup ledger or export target.  \n- Add **error-handling branches** to mark Gmail messages as processed or label them “Logged to Notion”."
      },
      "typeVersion": 1
    },
    {
      "id": "7b761225-99d9-43f5-be3d-223b504aa415",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        -32
      ],
      "parameters": {
        "color": 7,
        "height": 656,
        "content": "## Step 1 - Trigger"
      },
      "typeVersion": 1
    },
    {
      "id": "28a922f0-a013-49ec-9a0d-a496cccee865",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1840,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 688,
        "content": "## Step 2 - Classification"
      },
      "typeVersion": 1
    },
    {
      "id": "4896bc94-9960-4ecf-be5d-9813dcf6d47d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2464,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 368,
        "height": 1776,
        "content": "## Step 3 - Agent"
      },
      "typeVersion": 1
    },
    {
      "id": "0fe5c44e-f02d-4458-94ef-aead2890bcc6",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2912,
        -32
      ],
      "parameters": {
        "color": 7,
        "height": 352,
        "content": "## Step 4 - Send Message"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {
    "forwarding": [
      {
        "json": {
          "To": "<DANOOPKARNIK@gmail.com>",
          "id": "198b48bb3364e387",
          "From": "Axis Bank Alerts <alerts@axisbank.com>",
          "labels": [
            {
              "id": "INBOX",
              "name": "INBOX"
            },
            {
              "id": "CATEGORY_UPDATES",
              "name": "CATEGORY_UPDATES"
            },
            {
              "id": "UNREAD",
              "name": "UNREAD"
            }
          ],
          "Subject": "INR 636.00 was debited from your A/c no. XX4424.",
          "payload": {
            "mimeType": "multipart/alternative"
          },
          "snippet": "17-08-2025 Dear Dasika Anoop Karnik, Here&#39;s the summary of your transaction: Amount Debited: INR 636.00 Account Number: XX4424 Date &amp; Time: 17-08-25, 01:51:47 IST Transaction Info: UPI/P2M/",
          "threadId": "198b48bb3364e387",
          "historyId": "16621",
          "internalDate": "1755375708000",
          "sizeEstimate": 131574
        }
      }
    ],
    "Set Email Data": [
      {
        "json": {
          "To": "<DANOOPKARNIK@gmail.com>",
          "From": "Axis Bank Alerts <alerts@axisbank.com>",
          "Subject": "INR 636.00 was debited from your A/c no. XX4424.",
          "snippet": "17-08-2025 Dear Dasika Anoop Karnik, Here&#39;s the summary of your transaction: Amount Debited: INR 636.00 Account Number: XX4424 Date &amp; Time: 17-08-25, 01:51:47 IST Transaction Info: UPI/P2M/"
        }
      }
    ],
    "Accountant Agent1": [
      {
        "json": {
          "output": "A transaction has been recorded with the title \"Debit of INR 636.00\". The amount of INR 636.00 was debited from account number XX4424 via UPI on 17-08-2025 at 01:51:47 IST. You can view the transaction details in the [notion database](https://www.notion.so/Debit-of-INR-636-00-2511d3faa0a08166b2b9d0d352542cd5)."
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c517f750-d802-48ee-bc9d-d0b6f6d770d0",
  "connections": {
    "gpt-5": {
      "ai_languageModel": [
        [
          {
            "node": "Accountant Agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Accountant Agent1",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Accountant Agent2",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Accountant Agent3",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Classify": {
      "main": [
        [
          {
            "node": "Accountant Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Accountant Agent1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Accountant Agent2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Accountant Agent3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "forwarding": {
      "main": [
        [
          {
            "node": "Set Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gpt-5-nano": {
      "ai_languageModel": [
        [
          {
            "node": "Classify",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Email Data": {
      "main": [
        [
          {
            "node": "Classify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Accountant Agent": {
      "main": [
        [
          {
            "node": "Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Accountant Agent1": {
      "main": [
        [
          {
            "node": "Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Accountant Agent2": {
      "main": [
        [
          {
            "node": "Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Accountant Agent3": {
      "main": [
        [
          {
            "node": "Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Income Tool": {
      "ai_tool": [
        [
          {
            "node": "Accountant Agent2",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create Income Tool1": {
      "ai_tool": [
        [
          {
            "node": "Accountant Agent3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create Invoice Tool": {
      "ai_tool": [
        [
          {
            "node": "Accountant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "support@bayesian-labs": {
      "main": [
        [
          {
            "node": "Set Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Transction Tool": {
      "ai_tool": [
        [
          {
            "node": "Accountant Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "anoop.karnik@bayesian-labs": {
      "main": [
        [
          {
            "node": "Set Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}