AI Email Triage and Automated Invoice Processing - n8n Workflow

Use this powerful n8n workflow to triage Gmail messages, auto-reply using AI, extract structured data from PDF invoices, and send alerts via Telegram. Great for technical teams and accounts payable.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Accounts Payable or Finance Teams receiving invoices via email.
Engineering firms (like the example 'Zenith Engineering') needing automated triage for technical documents.
Business owners seeking to implement advanced AI-driven auto-responders.
Users looking for sophisticated examples of how to combine multiple n8n node types for complex data processing.


  • Anyone who wants to deploy a robust, end-to-end n8n template for email and file automation.

Overview

This specialized n8n workflow template addresses the critical need for efficient email management and structured document processing in technical organizations. The automation starts with a Gmail n8n trigger, constantly monitoring for new messages, especially those containing attachments. The core value of this n8n template lies in its dual-path processing: first, an AI agent rapidly analyzes the email subject and body to categorize it ('Important,' 'Fishy,' 'Meeting') and formulate a polite, professional reply, which is sent immediately via a Gmail n8n node. Second, if the email contains a PDF identified as an invoice, a sophisticated chain of n8n nodes performs optical character recognition (OCR), extracts key financial metadata (invoice number, total amount, vendor name) using a large language model, and instantly forwards these structured details, along with the original document, to the relevant engineering or finance team via Telegram. This robust n8n workflow minimizes response lag, ensures critical documents are processed quickly, and significantly reduces the manual effort required for data extraction.

How it Works

The n8n workflow operates through the following steps:


  1. Trigger and Initial Check: The n8n workflow is started by the Gmail Trigger n8n node when a new email arrives. A Filter n8n node immediately checks if the email contains any attachments.

  2. Attachment Preparation: If attachments exist, the n8n node logic (Edit Fields and Split Out) prepares the attachment metadata, isolating file names and types for processing.

  3. AI Triage: The email content is passed to a Code n8n node to detect if an 'invoice' is explicitly mentioned in the filenames. This data, along with the email text, feeds into the AI Agent n8n node.

  4. AI Categorization and Response: The AI Agent, using a dedicated OpenRouter Chat Model, categorizes the email (e.g., 'Important' or 'Check Later') and drafts a suitable response. The Structured Output Parser ensures the output is a clean JSON object.

  5. Automated Reply: The generated response is immediately sent back to the original sender using the Reply to same thread Gmail n8n node.

  6. PDF Filtering and Extraction: Simultaneously, the workflow filters the attachments to isolate only PDF files. These PDFs are merged with the original email context.

  7. Data Extraction: An Extract from File n8n node performs OCR on the PDF text. This raw text is then passed to an Information Extractor n8n node (powered by Gemini via OpenRouter) to precisely pull structured data like invoicenumber, vendorname, and total_amount based on a predefined schema.

  8. Telegram Notifications: The n8n workflow concludes by sending two separate alerts to Telegram: first, the extracted invoice details (structured data) via the Send important details n8n node; and second, the original binary files (documents or drawings) via the Send a document n8n node.

Installation Guide

To deploy this comprehensive n8n template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON data and paste it directly into your n8n instance using the 'New' button and selecting 'Import from JSON'.

  2. Set Up Gmail Credentials: The workflow requires Gmail OAuth2 credentials for both the 'Gmail Trigger' and the 'Get a message'/'Reply to same thread' n8n node instances. Ensure these credentials have the necessary scope to read mail and send replies.

  3. Set Up OpenRouter Credentials: The 'OpenRouter Chat Model1' and 'Gemini' n8n nodes require an API Key for the OpenRouter platform. Configure this credential to enable AI processing.

  4. Set Up Telegram Credentials: The two Telegram n8n node actions ('Send important details' and 'Send a document') require a Telegram API credential (Bot Token and Chat ID). You will need to specify the correct Chat ID of the recipient engineering channel or group in the parameters of both Telegram n8n nodes.

  5. Customize the AI Agent: Review the system prompt within the 'AI Agent' n8n node. Update the company name ('Zenith Engineering') and specific categorization rules to match your organization's requirements.

  6. Activate: Once all credentials and configurations are set, activate the n8n workflow. The Gmail Trigger n8n node will begin polling for new emails.

Node Details

Gmail Trigger: This n8n node initiates the n8n workflow upon receiving a new email. Key Configuration: Set to download attachments immediately (downloadAttachments: true).
Get a message (Gmail): Fetches the full context of the email, crucial for retrieving both text and binary data accurately.
Code (Debugged code to find attachment): A custom scripting n8n node that iterates through binary attachments and uses regular expressions (/invoice/i.test) to specifically detect and flag invoice files, appending hasInvoiceAttachment flag to the data.
AI Agent (LangChain): The central decision-making n8n node. Function: Categorizes email priority and drafts a contextual reply based on extensive system instructions tailored for professional correspondence. Key Configuration: Uses OpenRouter/Gemini and enforces strict JSON output using a Structured Output Parser.
Reply to same thread (Gmail): Sends the AI-generated Response back to the sender, maintaining the conversation thread via the threadId provided by the original Gmail Trigger n8n node.
Filter: Filters processed attachments to ensure only files with the fileType equal to pdf proceed to the extraction path.
Extract from File: Performs text extraction (OCR) on the binary PDF data, making the document content readable by the downstream AI n8n nodes.
Information Extractor (LangChain): An advanced n8n node that utilizes a large language model (Gemini/OpenRouter) to analyze the raw PDF text and extract predefined structured data fields (invoice number, vendor name, currency, items, etc.).
Convert Names to download files (Code): Restructures the binary data received from the Merge n8n node into a format suitable for the Telegram Send Document n8n node.
Send important details (Telegram): Sends a concise message containing the final, structured extracted invoice data to the operational Telegram channel.


  • Send a document (e.g. dwg files) (Telegram): Forwards the full binary file (e.g., drawings or original PDFs) to the engineering team.

Related n8n Workflows

Free

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

An investment banker from India who's recently been diving deep into the world of AI and tech. While finance was the starting point, curiosity led into exploring artificial intelligence, digital trends, and the future of innovation. Always learning, always evolving , blending my finance background with a growing passion for tech.

Featured*