Automatic Invoice Data Extraction from Telegram to Sheets using Gemini AI - n8n Workflow

Use this comprehensive n8n workflow to automate invoice processing. Extract data from Telegram documents via OCR, structure it with Gemini AI, update Google Sheets, and archive the file in Google Drive.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Finance teams and accountants needing automated invoice logging.

  • Small business owners looking to digitize expense tracking.

  • Users searching for practical, complex n8n templates involving AI and file operations.

  • n8n specialists requiring an example of multi-step AI-driven data extraction.

Overview

This powerful n8n workflow eliminates the manual effort involved in recording invoices. By setting up a Telegram n8n trigger, the process is instantaneous when a document is received. The solution intelligently manages documents, using an external OCR service to read the text content of the invoice image or PDF. Following this, the Google Gemini AI is employed through a dedicated n8n node to transform the raw text into highly structured, usable data points (invoice number, amount, due date). The resulting data is automatically logged into Google Sheets, while the original file is archived in Google Drive. This end-to-end n8n workflow significantly enhances financial data management and provides an immediate confirmation reply back to the user via Telegram.

How it Works

The process is initiated by the Telegram Trigger, which is the foundational n8n trigger designed to activate upon receiving a document message.


  1. File Retrieval: The subsequent Telegram n8n node securely downloads the incoming invoice file based on the file ID provided by the n8n trigger.

  2. Text Extraction (OCR): An HTTP Request n8n node sends the binary file data to the OCR.space API. This step converts the visual data of the invoice into usable, raw text.

  3. Data Structuring (Gemini AI): The AI Agent n8n node, leveraging the Google Gemini Chat Model and a Structured Output Parser, analyzes the OCR text. It intelligently extracts and formats key data points (invoiceNumber, totalAmount, dueDate, etc.) into a strict JSON structure.

  4. Database Logging: The Google Sheets n8n node uses the extracted data to append a new row in the designated Invoice Database spreadsheet.

  5. File Archiving: The Telegram n8n node re-fetches the file, which is then passed to the Google Drive n8n node. This archives the original invoice file in a specified folder, ensuring regulatory compliance and easy access.

  6. Response Generation: A Set n8n node compiles all necessary information (raw OCR text, Drive link, file name) for the final user communication.

  7. User Confirmation (Gemini AI): The final Invoice Agent n8n node uses the Google Gemini Chat Model to generate a polite, concise summary that confirms the logging, lists key invoice details, mentions the archived file name, and includes a link to the database.

  8. Reply: The final Telegram n8n node sends this AI-generated confirmation message back to the sender of the original invoice, completing the n8n workflow execution.

Installation Guide

To implement this n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON and import it directly into your n8n instance.

  2. Configure Telegram Credentials: Set up your Telegram Bot token as the ‘Telegram account’ credential for all Telegram n8n nodes.

  3. Configure Google Sheets & Drive Credentials: Create OAuth2 credentials for Google Sheets and Google Drive. Ensure both credentials have the necessary scope (Sheets: read/write; Drive: write access to the target folder).

  4. Set External API Keys:

- In the Analyze Image1 (HTTP Request) n8n node, replace yourkeyhere in the header parameters with a valid API key from OCR.space.
- For the AI functionality, create a credential for the Google Gemini (PaLM) API and apply it to both Google Gemini Chat Model n8n nodes.

  1. Update Resource IDs:

- In the Update Database1 (Google Sheets) n8n node, replace the placeholder documentId with your actual Google Sheet ID and verify the sheetName (GID).
- In the Add Invoice Image to Drive1 (Google Drive) n8n node, replace the folderId with the ID of your target 'Invoices' folder.

  1. Activate: Set the n8n workflow to 'Active' to start listening for the Telegram n8n trigger.

Node Details

This advanced n8n workflow utilizes several key nodes:

Telegram Trigger (n8n trigger):
Function: Starts the n8n workflow when a user sends a document (file) to the configured Telegram Bot.
Key Configuration: Listens for message updates.
Analyze Image1 (HTTP Request n8n node):
Function: Sends the invoice file binary data to OCR.space for text extraction.
Key Configuration: URL: https://api.ocr.space/parse/image; Uses multipart-form-data and requires an apikey header.
AI Agent (n8n node):
Function: Uses the Google Gemini Chat Model2 and the Structured Output Parser to convert raw OCR text into a predictable JSON object with required invoice fields.
Key Configuration: Instructs the AI to map extracted text to fields like invoiceNumber, totalAmount, and to default the dueDate to the invoiceDate if the former is missing.
Update Database1 (Google Sheets n8n node):
Function: Appends the structured invoice data generated by the AI agent to the Google Sheet.
Key Configuration: Operation: append; Uses column mapping based on AI output (e.g., Date receives {{ $json.output.invoiceDate }}).
Add Invoice Image to Drive1 (Google Drive n8n node):
Function: Archives the original invoice file for storage.
Key Configuration: File name is dynamically set using the current timestamp (e.g., Invoice [MMMM-dd-yyyy]).
Invoice Agent1 (n8n node):
Function: Uses the Google Gemini Chat Model1 and a rich system prompt to formulate a friendly, informative response for the user, summarizing the key extracted data and providing the Drive link.
Reply1 (Telegram n8n node):
* Function: Sends the AI-generated confirmation summary back to the chat ID of the user who initiated the n8n workflow.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

Featured*