Back to Templates
  • +10

Automated Financial Tracker: Telegram Invoices to Notion with Gemini AI Reports

Last update

Last update 22 days ago

Categories
Share

Automated Financial Tracker: Telegram Invoices to Notion with AI Summaries & Reports


Tired of manually logging every expense? Streamline your financial tracking with this powerful n8n workflow!

Snap a photo of your invoice in Telegram, and let AI (powered by Google Gemini) automatically extract the details, record them in your Notion database, and even send you a quick summary. Plus, get scheduled weekly reports with charts to visualize your spending. Automate your finances, save time, and gain better insights with this easy-to-use template!

Transform your expense tracking from a chore into an automated breeze. Try it out!


Overview:

This workflow revolutionizes how you track your finances by automating the entire process from invoice capture to reporting. Simply send a photo of an invoice or receipt to a designated Telegram chat, and this workflow will:

  1. Extract Data with AI: Utilize Google Gemini's capabilities to perform OCR on the image, understand the content, and extract key details like item name, quantity, price, total, date, and even attempt to categorize the expense.
  2. Store in Notion: Automatically log each extracted transaction into a structured Notion database.
  3. Instant Feedback: Send a summary of the processed transaction back to your Telegram chat.
  4. Scheduled Reporting: Generate and send a visual summary of your expenses (e.g., weekly spending by category) as a chart to your preferred Telegram chat or group.

This workflow is perfect for individuals, freelancers, or small teams looking to effortlessly manage their expenses without manual data entry.

Key Features & Benefits:

  • Effortless Expense Logging: Just send a picture – no more typing!
  • AI-Powered Data Extraction: Leverages Google Gemini for intelligent invoice processing.
  • Centralized Data in Notion: Keep all your financial records neatly organized in a Notion database.
  • Automated Categorization: AI helps in categorizing your expenses (e.g., Food & Beverage, Transportation).
  • Instant Summaries: Get immediate confirmation and a summary of what was recorded.
  • Visual Reporting: Receive scheduled charts (e.g., bar charts of spending by category) directly in Telegram.
  • Customizable: Easily adapt the workflow to your specific needs, categories, and reporting preferences.
  • Time-Saving: Drastically reduces the time spent on manual financial administration.

How It Works (Workflow Breakdown):

The workflow is divided into two main parts:

Part 1: Real-time Invoice Processing & Logging (## Auto Notes Transaction with Telegram and Notion database)

  1. Telegram Trigger (Telegram Trigger | When recive photo): Activates when a new photo is sent to the configured Telegram chat.
  2. Get Photo Info (Get Info Photo from telegram chat): Retrieves the details of the received photo.
  3. Get Image Info (Get Image Info): Prepares the image data.
  4. AI Data Extraction (Google Gemini Chat Model & Basic LLM Chain):
    • The image data is sent to the Google Gemini Chat Model.
    • A specific prompt instructs the AI to extract details (date, ID, name, quantity, price, total, category, tax) in a JSON array format and provide a summary message. The categories include Food & Beverage, Transportation, Utilities, Shopping, Healthcare, Entertainment, Housing, and Education.
  5. Parse AI Output (Parse To your object | Table): Structures the AI's JSON output for easier handling.
  6. Split Transactions (Split Out | data transaction): If an invoice contains multiple items, this node splits them into individual records.
  7. Record to Notion (Record To Notion Database): Each transaction item is added as a new page/entry in your specified Notion database, mapping fields like Name, Quantity, Price, Total, Category, Date, and Tax.
  8. Send Telegram Summary (Sendback to chat and give summarize text): The summary message generated by the AI is sent back to the original Telegram chat.

Part 2: Scheduled Financial Reporting (## Schedule report to send on chanel or private message)

  1. Schedule Trigger (Schedule Trigger | for send chart report): Runs at a predefined interval (e.g., every week) to generate reports.
  2. Get Recent Data from Notion (Get Recent Data from Notions): Fetches transaction data from the Notion database for a specific period (e.g., the past week).
  3. Summarize Data (Summarize Transaction Data): Aggregates the data, for example, by summing up the 'total' amount for each 'category'.
  4. Prepare Chart Data (Convert Data to JSON chart payload): Transforms the summarized data into a JSON format suitable for generating a chart (e.g., labels for categories, data for spending amounts).
  5. Generate Chart (Generate Chart): Uses the QuickChart node to create a visual chart (e.g., a bar chart) from the prepared data.
  6. Send Chart to Telegram (Send Chart Image to Group or Private Chat): Sends the generated chart image to a specified Telegram chat ID or group.

Nodes Used (Key Nodes):

  • Telegram Trigger & Telegram Node: For receiving images and sending messages/images.
  • Google Gemini Chat Model (Langchain): For AI-powered OCR and data extraction from invoices.
  • Basic LLM Chain (Langchain): To interact with the language model using specific prompts.
  • Output Parser Structured (Langchain): To structure the output from the language model.
  • Notion Node: For reading from and writing to your Notion databases.
  • Schedule Trigger: To automate the reporting process.
  • Summarize Node: To aggregate data for reports.
  • Code Node: Used here to format data for the chart.
  • QuickChart Node: For generating charts.
  • SplitOut Node: To process multiple items from a single invoice.

Setup Instructions:

  1. Credentials:
    • Telegram: Create a Telegram bot and get its API token. You'll also need the Chat ID where you'll send invoices and where reports should be sent.
    • Google Gemini (PaLM) API: You'll need an API key for Google Gemini.
    • Notion: Create a Notion integration and get the API key. Create a Notion database with properties corresponding to the data you want to save (e.g., Name (Title), Quantity (Number), Price (Number), Total (Number), Category (Select), Date (Text or Date), Tax (Number)). Share this database with your Notion integration.
  2. Configure Telegram Trigger:
    • Add your Telegram Bot API token.
    • When you first activate the workflow or test the trigger, send /start to your bot in the chat you want to use for sending invoices. n8n will then capture the Chat ID.
  3. Configure Google Gemini Node (Google Gemini Chat Model):
    • Select or add your Google Gemini API credentials.
    • Review the prompt in the Basic LLM Chain node and adjust if necessary (e.g., date format, categories).
  4. Configure Notion Nodes:
    • Record To Notion Database:
      • Select or add your Notion API credentials.
      • Select your target Notion Database ID.
      • Map the properties from the workflow (e.g., ={{ $json.name }}) to your Notion database columns.
    • Get Recent Data from Notions:
      • Select or add your Notion API credentials.
      • Select your target Notion Database ID.
      • Adjust the filter if needed (default is "past_week").
  5. Configure Telegram Node for Reports (Send Chart Image to Group or Private Chat):
    • Select or add your Telegram Bot API token.
    • Enter the Chat ID for the group or private chat where you want to receive the reports.
  6. Configure Schedule Trigger (Schedule Trigger | for send chart report):
    • Set your desired schedule (e.g., every Monday at 9 AM).
  7. Test: Send an image of an invoice to your Telegram bot and check if the data appears in Notion and if you receive a summary message. Wait for the scheduled report or manually trigger it to test the reporting functionality.

Sticky Note Text for Your n8n Template:

(These are suggestions. You would place these directly into the sticky notes within your n8n workflow editor.)

Existing High-Level Sticky Notes:

  • ## Auto Notes Transaction with Telegram and Notion database
  • ## Schedule report to send on chanel or private message

Specific Sticky Notes to Add:

  • On Telegram Trigger | When recive photo:
    📸 INVOICE INPUT 📸
    Bot listens here for photos of your receipts/invoices.
    Ensure your Telegram Bot API token is set in credentials.
    
  • Near Google Gemini Chat Model & Basic LLM Chain:
    🤖 AI MAGIC HAPPENS HERE 🧠
    - Image is sent to Google Gemini for data extraction.
    - Check 'Basic LLM Chain' to customize the AI prompt (e.g., categories, output format).
    - Requires Google Gemini API credentials.
    
  • On Parse To your object | Table:
    ✨ STRUCTURING AI DATA ✨
    Converts the AI's text output into a usable JSON object.
    Check the schema if you modify the AI prompt significantly.
    
  • On Record To Notion Database:
    📝 SAVING TO NOTION 📝
    - Extracted transaction data is saved here.
    - Configure with your Notion API key & Database ID.
    - Map fields correctly to your database columns!
    
  • On Sendback to chat and give summarize text:
    💬 TRANSACTION SUMMARY 💬
    Sends a confirmation message back to the user in Telegram
    with a summary of the recorded expense.
    
  • On Schedule Trigger | for send chart report:
    🗓️ REPORTING SCHEDULE 🗓️
    Set how often you want to receive your spending report (e.g., weekly, monthly).
    
  • On Get Recent Data from Notions:
    📊 FETCHING DATA FOR REPORT 📊
    - Retrieves transactions from Notion for the report period.
    - Default: "Past Week". Adjust filter as needed.
    - Requires Notion API credentials & Database ID.
    
  • On Summarize Transaction Data:
    ➕ SUMMARIZING SPENDING ➕
    Aggregates your expenses, usually by category,
    to prepare for the chart.
    
  • On Convert Data to JSON chart payload (Code Node):
    🎨 PREPARING CHART DATA 🎨
    This Code node formats the summarized data
    into the JSON structure needed by QuickChart.
    
  • On Generate Chart (QuickChart Node):
    📈 GENERATING VISUAL REPORT 📈
    Creates the actual chart image based on your spending data.
    You can customize chart type (bar, pie, etc.) here.
    
  • On Send Chart Image to Group or Private Chat:
    📤 SENDING REPORT TO TELEGRAM 📤
    - Delivers the generated chart to your chosen Telegram chat/group.
    - Set the correct Chat ID and Bot API token.
    
  • General Sticky Note (Place where relevant):
    🔑 CREDENTIALS NEEDED 🔑
    Remember to set up API keys/tokens for:
    - Telegram
    - Google Gemini
    - Notion
    
  • General Sticky Note (Place where relevant):
    💡 CUSTOMIZE ME! 💡
    - Adjust AI prompts for better accuracy.
    - Change Notion database structure.
    - Modify report frequency and content.