Automating bookkeeping intake without letting the automation post
Receipts for a small precious-metals trading business in Manila arrive as photos in a chat thread. Someone reads each one, decides what it is, types it into the accounting system, and files the image somewhere findable. The work is not hard. It is constant, and it produces nothing until the typing is finished.
I built the intake half: a pipeline that captures every message, extracts the facts, files the evidence, and stages a record for approval. The posting half stays deterministic and human-gated, because an accounting entry that nobody approved is a liability with a receipt attached.
The process before
A sale closes in a chat. The buyer sends a transfer screenshot. The photo sits in a thread with forty other messages, some of which are later edited to correct an amount.
At the end of the day, or the end of the week, the backlog gets worked: open each image, match it to a customer, work out whether it is a deposit, a balance, or a refund, then encode it. By my estimate every transaction takes 30 to 60 minutes in this handoff, and almost none of that time is spent inside the accounting system. It is spent reconstructing context that already existed in the chat.
Two failure modes show up reliably:
- An edited message leaves the encoded record stale, because the correction happened after the entry.
- The image cannot be found later, so the entry cannot be defended when someone asks for the receipt.
The design
Six stages, each with one job:
| Stage | Component | What it may decide |
|---|---|---|
| Capture | Discord ingress service | Nothing. Normalises the message, including edits, into a stable envelope |
| Queue | Durable inbox in n8n | Nothing. Holds the message until a batch window opens |
| Extract | AI agent with a structured output parser | Facts and gaps only. Never an account, never an amount it cannot see |
| Record | Four-tab Google Sheets ledger | Structure only. Candidates, not postings |
| Approve | Human review | Everything that matters |
| Post | Deterministic service calling narrow Odoo operations | Nothing. Executes an approved request |
Batches run at 09:00 and 17:00 Manila time. Receipt images are renamed to a standard that encodes date, amount, description, and claimant, then written back to Drive with a checksum readback, so the file you approve is provably the file that arrived.
The gate that makes it safe
Every posting request carries an idempotency key built from the source message ID, vendor or customer, date, amount, and a hash of the receipt image. Replay the same message and the system recognises the request instead of writing a second entry. Edit the message and the pending record is amended, not duplicated.
Extraction runs fail-closed. The agent returns fields and a list of unresolved gaps. If the amount, date, or counterparty is missing, the record is flagged and cannot enter the posting step. Nothing in the chain treats a plausible guess as a fact.
The posting layer is deliberately boring: it validates the approved record against the ledger, prepares the exact operation, calls it, then writes the result to an event log with the approver, the timestamp, and the receipt hash.
What the database taught me
The accounting system had invoices marked paid while the customer payments register stayed empty. The cause was not a bug. Receipts had been encoded directly against receivables or reconciled from the bank statement, which bypasses the payment record entirely. The cash was right, the register was empty, and nobody could answer “how much did this customer actually pay us” without rebuilding it by hand.
The fix is a clearing-account method: receipts land in Outstanding Receipts, and the payment is created against the invoice so the register fills in. The design rule that came out of it: an automation that reconciles cash must also produce the record that explains the cash.
What I did not automate
- Account selection. The agent proposes a description; a person picks the account, and the mapping is reviewed once, not every transaction.
- Whether to post. There is no auto-approve path, no “high confidence” bypass.
- Reimbursements. Employee claims follow a different naming and approval route, and mixing them into the sales intake was how the first version got confused.
- Inventory valuation. Correct cost of sales per unit needs serial-level traceability that the business does not have yet.
What changed
Capture stopped being a person's job. The backlog becomes a queue with a batch window, an approval screen, and an audit trail where every posted entry traces to a message, an image with a verified hash, and an approval.
The honest limit: this shortens the handoff, not the posting decision. A transaction still needs a human to approve it. What disappears is the reconstruction, the retyping, and the version of the record that went stale because someone corrected the chat message afterwards.
Stack
n8n, a Node.js Discord gateway service, Google Drive and Sheets for evidence and staging, an AI agent with a structured output parser for extraction, Odoo with the Philippine localisation for the ledger, and self-hosted n8n on a small Linux host.
If you are automating accounting intake, the interesting engineering is not the extraction. It is the boundary: what the model is allowed to conclude, what a person must approve, and how you prove afterwards which of the two happened.