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.
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.
Create a Telegram bot
- Install Telegram, then open a chat with @BotFather.
- Send
/newbot, choose a display name, then a username ending in "bot" (e.g.my_invoices_bot). - Copy the access token BotFather returns — this is your credential in n8n, not an OAuth login.
- Open the chat link BotFather gives you and press Start, so the bot has an active conversation to receive messages in.
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.
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.
$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.
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.
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.
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 }}
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.
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.
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.
Sources
| Source | Used 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 API | Message & file object shapes |
| OpenAI docs, "Vision" | Reading receipt images |
| OpenAI docs, "Structured Outputs" | Forcing a fixed JSON schema |
| n8n docs, Extract From File node | Reading PDF text natively |
| n8n docs, Aggregate node | Collapsing split line items before notifying |