Telegram Bot for Automated Invoice Data Extraction using OpenAI - n8n Workflow

Use this powerful n8n workflow to instantly analyze uploaded PDF invoices via Telegram using OpenAI's capabilities. Automate data extraction and receive structured results.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Finance Departments: Those needing rapid, automated extraction of invoice details without manual input.
Small Businesses & Accountants: Users who manage a high volume of vendor invoices and rely on Telegram for communication.
n8n Automation Specialists: Users looking for advanced n8n templates integrating Telegram, file operations, and OpenAI for complex document processing.
Developers & Integrators: Teams building intelligent document processing systems using the n8n platform.

Overview

Handling invoices often involves tedious manual data entry, which is prone to errors. This specific n8n workflow template solves this challenge by transforming your Telegram chat into an intelligent document processor. When an invoice (e.g., PDF) is dropped into your Telegram bot, the n8n automation takes over, automatically downloading the file, extracting the text content, and routing it to a specialized OpenAI agent. The agent is prompted to identify key fields like the invoice number, total amount, and vendor name. The result is a clean, structured analysis delivered back to the Telegram chat, drastically accelerating your accounts payable process. This powerful n8n node combination demonstrates how sophisticated AI capabilities can be seamlessly integrated into everyday messaging platforms.

How it Works

This n8n workflow begins with the dedicated Telegram n8n trigger. Once a message is received:


  1. Trigger and Validation: The Telegram n8n trigger fires. The subsequent If n8n node immediately checks if the incoming message contains a document ($json.message.document). If no document is found, an error message is sent back to the chat via a Telegram n8n node.

  2. File Download: If a document is present, the workflow proceeds. The Get File from Telegram n8n node retrieves the necessary metadata, followed by an HTTP Request n8n node which uses the Telegram Bot token to securely download the actual file content.

  3. Text Extraction: The Extract Invoice Data n8n node (configured for PDF extraction) reads the binary file and converts the content into raw, searchable text.

  4. AI Analysis: The raw text is passed to the AI Agent - Analyze Invoice n8n node, powered by the OpenAI Chat Model n8n node. This agent, acting as an expert analyst, uses a detailed prompt to parse the text and structure the required invoice fields (like Invoice Date, Total Amount, etc.).

  5. Output Formatting: A Code n8n node (Format Response) standardizes the output, merging the AI's analysis with the original chat details to prepare the final message payload.

  6. Notification: Finally, the Send Analysis to Telegram n8n node sends the detailed, structured analysis back to the original Telegram chat, completing the fully automated n8n workflow.

Installation Guide

To deploy this specialized n8n workflow template, follow these steps:


  1. Import: Copy the provided n8n workflow JSON and import it into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Telegram Credentials: You need to set up a Telegram bot via BotFather. Create or update your Telegram API credentials in n8n, ensuring the webhook link for the Telegram Trigger n8n node is correctly configured and pointing to your n8n instance.

  3. OpenAI Credentials: Provide your OpenAI API key to the OpenAI Chat Model n8n node. This model requires a connection to an OpenAI service capable of handling the agent logic (e.g., GPT-4o-mini or similar models).

  4. Activation: Ensure all credentials are set on the respective n8n node blocks. Activate the n8n workflow by toggling the 'Active' switch in the top menu. This will enable the Telegram n8n trigger to start listening for incoming documents.

Node Details

Telegram Trigger: This n8n trigger initiates the entire n8n workflow whenever a message is received on the connected Telegram bot. It is the crucial starting n8n node for the automation.
Check if Document (If n8n node): Essential control flow n8n node that validates if the incoming message contains the expected file data ($json.message.document). It handles necessary error routing.
HTTP Request - Download File: A critical n8n node used to dynamically download the file contents from the Telegram API servers using the bot's access token and the file path obtained from Telegram metadata.
Extract Invoice Data (extractFromFile n8n node): This core utility n8n node specializes in reading the binary file (likely a PDF) and performing OCR or text extraction to prepare the data for the AI analysis.
OpenAI Chat Model (n8n node): Provides the necessary language model connection (e.g., using GPT-4o-mini) to the agent architecture, enabling complex reasoning and data structuring.
AI Agent - Analyze Invoice (Agent n8n node): This is where the intelligence resides. It utilizes a powerful system prompt instructing it to act as an invoice analyst, extracting structured data based on the text provided by the previous n8n node.
Format Response (Code n8n node): A custom scripting n8n node used for mapping and restructuring the data, ensuring the AI's output is cleanly packaged alongside necessary metadata (like chatId) before being sent out.
Send Analysis to Telegram (Telegram n8n node): The final action n8n node, responsible for delivering the detailed, formatted analysis back to the user via their private Telegram chat.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Cheng Siong Chin
Cheng Siong Chin

Prof. Cheng Siong CHIN serves as Chair Professor in Intelligent Systems Modelling and Simulation in Newcastle University, Singapore. His academic credentials include an M.Sc. in Advanced Control and Systems Engineering from The University of Manchester and a Ph.D. in Robotics from Nanyang Technological University.

Featured*