How It Works
End-to-end flow from Discord message to accounting result.
Document Processing
- Message arrives on Discord #invoices (forwarded email receipt, invoice PDF, or text with photo)
- OpenClaw extracts merchant, amount, date, VAT from the document using the LLM
- OpenClaw calls the API with the extracted data (e.g.,
POST /receipt/attach) - API does the work: checks Folio for matching transaction, attaches receipt, or registers in Fiken
- API returns result to OpenClaw (success, match details, or error)
- OpenClaw replies in a Discord thread on the original message
Queries
- User asks a question in Discord (e.g., "Hva er saldo?")
- OpenClaw determines the intent using the LLM
- OpenClaw calls the appropriate API endpoint (e.g.,
GET /folio/balance) - API queries Folio/Fiken and returns data
- OpenClaw formats and posts the answer in Discord
Learned Patterns
- API stores merchant-to-account/VAT mappings in Postgres
- OpenClaw reads patterns via
GET /patternsto provide context to the LLM - When a new merchant appears, OpenClaw asks the user, then calls
POST /patterns/suggest - The suggest endpoint creates a PR to the gitops repo (not a direct DB write)
- After PR merge, the pattern is available via
GET /patterns
Proactive Checks
A cron job (k8s CronJob) calls the API's check endpoints daily:
GET /check/missing-receipts-- Folio transactions without attachmentsGET /check/due-invoices-- purchases approaching due dateGET /check/overdue-invoices-- past due, not yet paid
Results are sent to OpenClaw, which posts reminders in Discord.
Configuration Changes
OpenClaw never writes config directly. For changes to patterns or company rules:
- OpenClaw creates a PR to the gitops repo via GitHub API
- Other agents or humans review the PR
- On merge, the new config is deployed via ArgoCD
Discord Thread Model
Every document gets its own thread. If clarification is needed, the conversation continues in the thread.
#invoices channel:
[Email forward: Adobe invoice PDF]
└── Thread:
Bot: "Adobe 199 kr, 22. mars --> konto 6540 (programvare, 25% MVA)
Lagt til pa Folio-transaksjon #evt-abc123"
[Email forward: Unknown supplier invoice]
└── Thread:
Bot: "Ny leverandor: CloudFlare. Hvilken konto?
Foreslar 6540 (skytjenester, 25% MVA)"
You: "Ja"
Bot: "Husker dette til neste gang. Registrert i Fiken,
forfaller 15. april."