Automate Invoices with n8n, Telegram & OCR
Use this n8n workflow template to turn messy invoice intake into a simple, automated pipeline. Your invoices arrive in Telegram, get processed with OCR, key fields are parsed and stored in Google Sheets, the original file is archived in Google Drive, and an OpenAI-powered agent sends a confirmation back to the sender.
What you will learn
By the end of this guide, you will understand:
- What the Telegram Invoice Agent workflow does and when to use it
- How each n8n node in the template works, step by step
- How to connect Telegram, OCR, Google Drive, Google Sheets and OpenAI in n8n
- How to customize parsing, validation and security for your own invoices
- How to troubleshoot common issues like poor OCR or failed Google Sheets writes
Why use this n8n Invoice Agent workflow?
This template is designed for anyone who regularly receives invoices as images or PDFs and wants a lightweight automation instead of manual data entry. It is especially useful for:
- Small businesses that get invoices via chat apps
- Freelancers who want a simple invoice inbox
- Bookkeeping and finance teams that need quick, structured invoice data
Key benefits of this n8n invoice automation:
- Faster invoice intake: Forward invoices to your Telegram bot and let n8n handle download, OCR, parsing and storage.
- Accurate data capture: OCR plus parsing extracts fields like invoice number, date, total amount, due date, billing address and notes.
- Centralized file storage: Original invoice files are archived in a Google Drive folder.
- Structured logging: Parsed invoice data is appended to a Google Sheets spreadsheet for filtering, reporting and follow-up.
- User-friendly confirmation: An OpenAI-powered agent summarizes the invoice and confirms successful storage directly in Telegram.
Concept overview: How the workflow fits together
At a high level, the n8n template follows this flow:
- Capture: A Telegram Trigger node listens for incoming invoice files.
- Extract: The file is downloaded and sent to an OCR service to extract text.
- Parse: A Code node uses regular expressions to pull out key invoice fields.
- Store: Parsed data goes into Google Sheets, while the original file is saved to Google Drive.
- Confirm: An OpenAI agent summarizes the invoice and replies to the sender in Telegram.
In n8n, these concepts are implemented as connected nodes that pass data along in JSON format. The template ships with all the logic wired up. You mainly need to plug in your credentials and adapt parsing rules if needed.
Prerequisites and setup checklist
Before you enable the workflow, make sure you have the following pieces ready and connected to n8n.
1. Telegram bot
- Create a Telegram bot using
@BotFather. - Copy the bot token and add it as credentials in n8n.
- Configure the Telegram Trigger node in the template to use these credentials.
2. OCR provider
- Obtain an API key for OCR.space or another OCR provider such as Google Vision, AWS Textract or a self-hosted Tesseract instance.
- If you use OCR.space, the included HTTP Request node is already configured for a standard POST request.
- If you use a different provider, adjust the HTTP Request node URL, headers and body format accordingly.
3. Google Drive and Google Sheets
- Set up OAuth credentials for Google in n8n.
- Create a Google Sheets spreadsheet that will act as your invoice database.
- Create or choose a Google Drive folder where invoice files will be stored.
- Configure the Google Sheets and Google Drive nodes to use your Google account and point them to the correct sheet and folder.
4. OpenAI account
- Get an OpenAI API key.
- Add it to n8n as credentials and select it in the OpenAI node used for the Invoice Agent.
- Review or tweak the system prompt to match your preferred tone and summary style.
5. Test data and parsing rules
- Collect a few sample invoices that represent the formats you usually receive.
- Run them through the workflow and refine the regular expressions in the parsing Code node if needed.
Step-by-step: How the n8n invoice workflow works
In this section, we walk through each node in the template in the order data flows through the system.
Step 1 – Capture invoices with the Telegram Trigger
The workflow starts with a Telegram Trigger node. It listens for messages sent to your Telegram bot.
For this template, you typically send:
- Invoice images (JPG, PNG)
- Invoice PDFs
When a user sends a document, the trigger node receives the message payload, including the file_id that Telegram uses to reference the file. This reference is then passed to the next node so the file can be downloaded.
Step 2 – Download the invoice file
Next, a Telegram API node (often called Download File in the template) uses the file_id to fetch the actual file from Telegram.
Key details:
- The node retrieves the file as binary data.
- This binary data is stored in the n8n execution context, ready to be sent to the OCR service.
Step 3 – Extract text with OCR
Once the file is downloaded, a HTTP Request node (labeled something like Analyze Image (OCR)) sends the binary file to your OCR provider.
In the default template:
- The workflow uses OCR.space via a POST request.
- The binary file is attached and the API key is passed in the headers or query parameters.
The OCR service processes the image or PDF and returns a response that contains the extracted text. The node parses this response and exposes the text for the next step.
You can swap OCR.space with other services by adjusting:
- The endpoint URL
- Authentication headers or parameters
- The way you read the extracted text from the response body
Step 4 – Parse invoice fields from OCR text
OCR gives you a big block of text. The next step is to turn that into structured data. A Code node (for example in JavaScript) performs this parsing.
This node typically:
- Receives the raw OCR text as input.
- Uses regular expressions to find patterns such as:
- Invoice number (e.g.
Invoice #12345orInvoice No. 12345) - Invoice date
- Total amount
- Due date
- Billing address
- Additional notes or descriptions
- Invoice number (e.g.
- Builds a JSON object with clearly named fields, for example:
invoiceNumberinvoiceDatetotalAmountdueDatebillingAddressnotes
This transformation is what allows downstream nodes like Google Sheets and OpenAI to work with clean, structured invoice data instead of free-form text.
Step 5 – Append structured data to Google Sheets
With the parsed JSON in hand, the workflow moves to a Google Sheets node, often labeled Update Database.
In this step:
- The node is configured in Append mode to add a new row to your invoice sheet.
- Each JSON field is mapped to a specific column, such as:
- Invoice Number
- Date
- Total Amount
- Billing Address
- Due Date
- Notes
- Optionally, you can also log metadata like timestamp and Telegram user ID for auditing.
The result is an ever-growing, filterable list of invoices that you can use for reporting and tracking unpaid amounts.
Step 6 – Archive the original invoice in Google Drive
In parallel or as a subsequent branch, another part of the workflow handles file storage using a Google Drive node.
This step:
- Uploads the original binary file received from Telegram to a chosen Drive folder.
- Sets a human-readable file name, often including the current date or invoice number.
- Optionally stores or returns the file URL or ID so it can be referenced later.
This gives you a secure, centralized archive of all original invoices alongside your structured sheet data.
Step 7 – Generate a confirmation with OpenAI and reply in Telegram
The final stage uses an OpenAI node, often referred to as the Invoice Agent, followed by a Telegram reply node.
The OpenAI node receives:
- The parsed invoice fields (total, due date, notes, etc.)
- The file name or link, if you choose to include it
- Any relevant context, such as the location of the Google Sheets database
The system prompt instructs the model to:
- Thank the user for sending the invoice
- Summarize key details like total amount and due date
- Confirm that the invoice file and data were stored successfully
The OpenAI response text is then passed to a Telegram node that sends a message back to the original sender. This closes the loop and gives the user immediate feedback that their invoice has been processed.
Quick node mapping reference
To help you visualize the flow in n8n, here is a concise node sequence:
- Main data path: Telegram Trigger → Download File → Analyze Image (OCR) → Parse Text → Update Database (Google Sheets)
- File and confirmation path: Download File → Upload to Drive → Set file name → Invoice Agent (OpenAI) → Reply (Telegram)
Customizations and best practices
Improving OCR accuracy
- Preprocess images to improve quality, such as deskewing or increasing contrast, before sending them to OCR.
- Switch to a higher accuracy OCR provider if OCR.space does not handle your invoice formats well.
- Encourage users to send higher-resolution scans or PDF exports instead of low-quality photos.
Enhancing parsing logic
- Replace single regex patterns with a list of patterns that cover variations like
Invoice #,Invoice No., orInvoice Number. - Add fallback logic so if one pattern fails, another one is tried.
- If you process many vendor-specific templates, consider building vendor-specific parsing branches or using a small ML-based classifier.
Data validation and quality checks
- Add an extra node that validates numerical formats for amounts and checks that dates are within reasonable ranges.
- Flag suspicious or incomplete entries by sending alerts to Slack, email or another Telegram chat.
- Require manual review for invoices above a certain threshold by routing them to a separate approval workflow.
Handling multiple file types
- Use conditional nodes in n8n to detect whether the file is a PDF, JPG, PNG or a multipage document.
- Route different file types to slightly different OCR configurations if needed.
Security and access control
- Use least-privilege OAuth scopes for Google Drive and Google Sheets, granting only the permissions the workflow really needs.
- Avoid storing full payment card numbers or CVV codes in Drive or Sheets. If invoices contain such data, redact or omit it before saving.
- Restrict access to the Drive folder and spreadsheet to only those who need it.
- Enable two-factor authentication on accounts used by n8n, such as Google, Telegram and OpenAI.
Auditing and traceability
- Add timestamp fields for when the invoice was received and processed.
- Log the Telegram user ID or username in the Google Sheet so you can trace the source of each invoice.
Troubleshooting common issues
OCR returns messy or incomplete text
Possible fixes:
- Try a different OCR provider or change OCR settings.
- Improve the quality of the source images by asking users for clearer photos or PDFs.
- Add pre-processing steps in n8n or upstream tools to enhance contrast or correct skew.
If invoices are very low resolution, consider asking users via the Telegram bot to send higher quality scans or enable PDF uploads.
Parsed fields are empty or incorrect
Focus on the Code node that parses text:
- Review and update regex patterns to match the labels used on your invoices, for example:
Invoice #vsInvoice No.TotalvsAmount Due
- Implement multiple patterns for each field and use fallback logic.
- Test the regexes against real OCR output from your invoices and adjust until they consistently match.
Google Sheets append fails
If the Google Sheets node fails to append rows:
- Verify that your Google Sheets OAuth credentials in n8n are valid and not expired.
- Check that the spreadsheet ID and sheet name (or
gid) are correct. - Make sure the authenticated Google user has edit access to the sheet.
- Confirm column mappings in the node configuration match your actual sheet structure.
Security & compliance considerations
- Avoid storing sensitive payment data, such as full card numbers or CVV codes, in plain text in either Google Drive or Google Sheets.
- If invoices contain sensitive details, consider redacting them or limiting access to the storage locations.
- Enable two-factor authentication for all accounts used by n8n, including Google, Telegram and OpenAI.
- Limit OAuth scopes for Drive and Sheets to the minimum required for this workflow.
- Implement an approval step for high-value invoices so that a human reviews them before payment is made.
Recap and next steps
This n8n Invoice Agent template gives you a complete, modular pipeline for invoice automation:
- Invoices arrive via Telegram and are captured by a Telegram Trigger node.
- Files are downloaded, passed through OCR and converted into plain text.
- A Code node parses key fields like invoice number, dates, amounts and billing details.
- Structured data is logged in Google Sheets and original files are archived in Google Drive.
- An OpenAI-powered agent summarizes the invoice and confirms processing back to the user in Telegram.
Each part
