Day 19Productivity & FinanceTelegramOCRFinance

AI Invoice Manager — AI Agent for Telegram expense logging

Telegram-based expense logging to keep finances lean.

Impact

Telegram-based expense logging to keep finances lean.

Mechanism

Telegram Bot + OCR

DAY 19
Full README · Case Study

🤖 AI Invoice Extraction Agent

Turn your messy invoice images into structured data and organized files automatically! 🚀


📑 Table of Contents


🌟 Overview

The AI Invoice Extraction Agent is a state-of-the-art, no-code automation workflow built on n8n. It acts as your personal finance assistant, living right inside your Telegram messenger.

Imagine this: You're at a lunch meeting, you pay the bill, and instead of stuffing the receipt in your wallet to be forgotten, you simply snap a photo and send it to your Telegram bot. Done.

This workflow kicks into gear, automatically extracting all the crucial details (Invoice Number, Date, Amount, etc.), saving the data to a Google Sheet, archiving the original file to Google Drive, and even replying with a friendly, AI-generated summary.

Say goodbye to manual data entry and lost receipts! 👋


✨ Key Features

FeatureDescriptionTech Stack
📸 Instant OCRInstantly converts images into machine-readable text using advanced optical character recognition.OCR.space API
🧠 Intelligent ParsingUses regex and logic to identify specific fields like Total Amount, Due Date, and Billing Address with high precision.Javascript
🗄️ Auto-DatabaseAutomatically appends structured data to Google Sheets for easy tracking, accounting, and visualization.Google Sheets
☁️ Cloud ArchivingUploads the original image file to a designated Google Drive folder for audit trails and safekeeping.Google Drive
💬 AI AssistantPowered by OpenAI, the bot understands context and replies with a natural language summary, making interactions feel human.OpenAI GPT-4
📱 Mobile FirstWorks entirely within Telegram, making it accessible from anywhere, anytime—no new apps to install.Telegram API

🛠️ Architecture & Workflow

Here is a visual deep-dive into how the automation flows from start to finish:

Image Received

Binary Data

Raw Text JSON

Structured JSON

Success

File Metadata

File Link

Context + Data

Generated Summary

📱 Telegram Trigger
(Receive Image)

⬇️ Download File

🔍 Analyze Image
(OCR.space API)

💻 Parse Text
(Javascript/Regex)

📊 Update Database
(Google Sheets)

🔄 Get File Info

☁️ Upload to Drive
(Google Drive)

📝 Set Context

🤖 Invoice Agent
(OpenAI + LangChain)

💬 Reply to User

Step-by-Step Process

  1. Trigger: You send an image (invoice) to your Telegram Bot.
  2. Download: The workflow downloads the image file from Telegram's servers to the n8n instance.
  3. OCR Analysis: The image is sent to the OCR.space API, which returns the raw text found in the document.
  4. Data Extraction: A custom code node parses the raw text to find key information (Invoice #, Date, Amount, etc.).
  5. Database Update: The extracted data is added as a new row in your Google Sheet.
  6. File Storage: The original image is uploaded to a specific folder in your Google Drive.
  7. AI Processing: An AI Agent (LangChain) reviews the extracted info and constructs a helpful response.
  8. Response: The bot replies to you on Telegram with a summary and a link to the database.

📋 Prerequisites

Before you begin, ensure you have the following:

  • n8n Instance: You need n8n installed and running (Self-hosted or Cloud).
  • Telegram Account: To create a bot.
  • Google Account: For Sheets and Drive access.
  • OCR.space API Key: Free key available here.
  • OpenAI API Key: For the AI agent functionality.

⚙️ Installation & Setup

Follow these detailed steps to get your agent up and running.

1. Telegram Bot Setup

  1. Open Telegram and search for @BotFather.
  2. Send the command /newbot.
  3. Follow the prompts to name your bot and get your HTTP API Token.
  4. Save this token; you will need it for n8n credentials.

2. Google Cloud Setup

  1. Google Cloud Console: Create a new project and enable Google Sheets API and Google Drive API.
  2. Credentials: Create OAuth2 credentials (Client ID and Secret).
    • Note: For n8n, you'll need to set the redirect URI to your n8n instance's callback URL.
  3. Google Sheet: Create a new Google Sheet.
    • Name the first sheet Sheet1.
    • Create the following headers in the first row:
      • Invoice Number
      • Date
      • Total Amount ($)
      • Billing Address
      • Due Date
      • Notes
  4. Google Drive: Create a folder named Invoices (or whatever you prefer) to store the images.

3. OCR.space Setup

  1. Visit OCR.space.
  2. Register for a free API key.
  3. You will receive the key via email.

4. OpenAI Setup

  1. Go to platform.openai.com.
  2. Generate a new API Key.
  3. Ensure you have credits/billing set up.

5. n8n Configuration

  1. Import Workflow:
    • Copy the JSON content of the workflow file.
    • In n8n, go to Workflows > Import from JSON and paste the code.
  2. Configure Credentials:
    • Telegram Trigger: Create new credentials using your Bot Token.
    • Google Sheets: Connect your Google account using OAuth2.
    • Google Drive: Connect the same Google account.
    • OpenAI: Add your OpenAI API Key.
  3. Update Node Settings:
    • Update Database Node: Select your specific Google Sheet and Sheet Name.
    • Add Invoice Image to Drive Node: Select your specific Google Drive folder.
    • Analyze Image Node: In the Header Parameters, replace YOUR API KEY HERE with your actual OCR.space API key.
  4. Activate: Toggle the workflow to Active.

🚀 Usage Guide

Using the agent is incredibly simple:

  1. Open your Telegram app.
  2. Navigate to your new bot.
  3. Upload a photo of an invoice or forward a file (PDF/Image) to the bot.
  4. Wait a few seconds... ⏳
  5. Ding! 🔔 You will receive a reply confirming the data extraction, along with a link to your dashboard.

Tip: Ensure the image is clear and the text is legible for the best OCR results.


💾 Data Structure & Customization

The system is designed to extract the following fields. You can modify the Parse Text node (Javascript) to add more fields if needed.

FieldRegex LogicDescription
Invoice NumberInvoice Number:\s*(\S+)Captures the ID of the invoice.
DateDate:\s*(\S+)Captures the invoice date.
Total AmountTotal Amount:\s*([\d,.]+)Captures the final total.
Billing AddressBilling Address:\s*(.+)Captures the address line.
Due DateDue Date:\s*(\S+)Captures when payment is due.
NotesNotes:\s*([\s\S]*)Captures any additional text/notes.

Adding New Fields

To add a new field (e.g., "Tax Amount"):

  1. Open the Parse Text node in n8n.
  2. Add a new line to the parsedData object:
    javascript
    taxAmount: text.match(/Tax:\s*([\d,.]+)/)?.[1],
    
  3. Add a new column to your Google Sheet.
  4. Update the Update Database node to map the new field.

🔧 Troubleshooting & FAQ

❌ The bot isn't responding!

  • Check if the workflow is Active in n8n.
  • Verify your Telegram credentials are correct.
  • Check the n8n Executions tab for any error logs.

❌ OCR is missing data!

  • The image might be blurry. Try a higher quality image.
  • The regex patterns in the "Parse Text" node might need adjustment to match your specific invoice format.

❌ Google Drive/Sheets errors!

  • Ensure your OAuth2 credentials haven't expired.
  • Verify that the specific Sheet ID and Folder ID in the nodes match your actual files.

❓ Can I use a different OCR provider?

  • Yes! You can replace the OCR.space node with Google Cloud Vision, AWS Textract, or any other OCR service supported by n8n.

🤝 Contributing

Contributions are welcome! If you have ideas for improvements, feel free to fork this repository and submit a pull request.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

Distributed under the MIT License. See LICENSE for more information.


Made with ❤️ by the Ai agent bros team

Website •
Documentation •
Support

Explore more agents

30 open-source systems · full registry

Browse All 30 Agents