← n8n Builder & Seller Stack Layer 04 — binary files & vision
Layer 04 · Build

Build: Document & Receipt AI

Send a photo of a receipt or a PDF invoice into a Telegram chat; get back clean, structured line items in a spreadsheet a few seconds later. This build is the clearest possible teacher of n8n's binary file type and of forcing AI output into a schema you can actually build on.

Apps used Telegram, OpenAI (vision), Google Sheets Difficulty Intermediate Build time 60–75 min
00

What we're building, and why

Bookkeeping-adjacent busywork — retyping receipts and invoices into a spreadsheet — is one of the most reliably sellable automations there is, because the pain is universal and the ROI is obvious to anyone who's ever done it by hand. The workflow below accepts either an image or a PDF, extracts every line item, and standardizes the output regardless of how differently each document is formatted.

01

Create a Telegram bot

  1. Install Telegram, then open a chat with @BotFather.
  2. Send /newbot, choose a display name, then a username ending in "bot" (e.g. my_invoices_bot).
  3. Copy the access token BotFather returns — this is your credential in n8n, not an OAuth login.
  4. Open the chat link BotFather gives you and press Start, so the bot has an active conversation to receive messages in.
02

Trigger & route by file type

Add trigger → Telegram → On Message Received, paste in the access token. Send the bot a file (choose "File," not "Photo," for the most consistent metadata) with a caption, and confirm the trigger's output includes a document object with a file_id and a MIME type.

Add a Switch node keyed on mimeType: route application/pdf to one branch and image/jpeg (or image/png) to the other.

03

Download the file

The trigger only gives you a file_id, not the actual file. Add Telegram → Get a File, pass in that ID, and the node returns the binary content — viewable and downloadable directly in n8n's output panel from this point on.

Anytime you insert a new node between a trigger and something referencing $json directly, re-check every downstream reference: $json always means "the node immediately before this one," so inserting a step in between silently breaks anything that assumed otherwise. Reference the trigger explicitly instead — {{ $('Telegram Trigger').item.json… }} — whenever you might reorder nodes later.
04

Read images with AI vision

On the image branch, add OpenAI → Analyze Image. Set Input Type to Binary File (not Image URL), point the field name at the binary property from the download step, and prompt it simply: "Pull out all the text from this image." The model reads the receipt like a human would and returns it as plain text — merchant name, address, and every line item, in whatever order they appear on the page.

05

Read PDFs natively

On the PDF branch, skip the vision call entirely — add Extract From File → Extract from PDF, pointing at the same binary field name. This pulls raw text directly from the PDF's structure, which is both faster and more accurate than running a PDF through an image model.

06

Force a standard JSON schema

Raw extracted text is a wall of unstructured words — useless for a spreadsheet. Add a second OpenAI → Message a Model call on each branch, enable Output Format → JSON Object under Options, and hand it a fixed structure to fill in rather than leaving the shape up to the model:

SYSTEM:
Pull out every line item from this receipt/invoice text. Output the
data in exactly this JSON structure — omit any field you can't find,
never invent a value:

{
  "merchant": { "name": "", "address": "", "phone": "" },
  "receipt_id": "",
  "date": "",
  "line_items": [
    { "title": "", "description": "", "price": 0, "tax": 0 }
  ],
  "total": 0,
  "currency": ""
}

USER:
{{ $json.text }}
Every receipt looks different, but if you force the same schema every time, everything downstream — the spreadsheet columns, the mapping, a client's reporting dashboard — can be built once and never touched again. This is the difference between a demo and a production data pipeline.
07

Split line items into rows

A single receipt with four line items is still one item at this point — an object containing an array. Add Split Out on the line_items field to turn it into four separate items, then Google Sheets → Append Row, mapping each split item's title, description, price, and tax, plus the shared merchant.name, total, and currency fields — which are safe to repeat across every row since they describe the one receipt all four items came from.

08

Aggregate, then notify once

Without an Aggregate step after the sheet write, a four-item receipt sends four separate "done" notifications — and a hundred-line invoice would send a hundred. Add Aggregate → Aggregate All Item Data right after the Sheets write so all four items rejoin into a single list, then a single Telegram → Send Message confirms "Receipt processed" exactly once. Finally, add a Merge node joining the PDF and image branches so both paths land on the same confirmation step.

09

Variations worth selling

  • Route by document type instead of file type — invoices to one sheet, receipts to another, contracts to a Drive folder.
  • Add a categorization pass (business expense category) before the row is written.
  • This exact skeleton — download → extract → force-schema → split → write → aggregate-notify — is the pattern behind almost every "document processing" offer sold to bookkeepers, property managers, and logistics companies.
10

Sources

SourceUsed for
Jono Catliff (Automatable), "n8n 8 Hour Masterclass — Build & Sell AI Agents (Automate Anything)"Primary source for this build's workflow steps
Telegram, "From BotFather to 'Hello World'"Creating the bot & access token
Telegram, Bot APIMessage & file object shapes
OpenAI docs, "Vision"Reading receipt images
OpenAI docs, "Structured Outputs"Forcing a fixed JSON schema
n8n docs, Extract From File nodeReading PDF text natively
n8n docs, Aggregate nodeCollapsing split line items before notifying