# nuri-bot: Turning Telegram purchase requests into approvable deals

> I built a one-person back office where an LLM structures purchase requests that an overseas client scatters across Telegram into proposals, and code applies only the ones the administrator approves.

- Published: 2026-11-11
- Client: NURI Trading (international B2B sourcing and trading company)
- Role: Design, implementation, operations
- Period: 2026
- Stack: TypeScript, Cloudflare Workers, D1, R2, Queues, Hono, Next.js, Zod, Qwen
- Outcome: Intent classification golden set 97.3% (36/37)
- Tags: llm, human-in-the-loop, cloudflare, telegram, back-office

**Why**: A single administrator was keeping Telegram conversations in their head and handling quote requests and settlements by copy and paste. Money was involved, so the system had to catch missed requests and mistyped numbers.

**Principle**: Use the intelligence of the LLM, but never give the LLM write access to the system.

## Metrics

| Metrics | Value | Scope | Source |
| --- | --- | --- | --- |
| Intent classification accuracy (golden set) | 97.3% (36/37) | Production measurement | Golden set evaluation drawn from real conversations, Development log (private). Re-run: 94.6% (35/37) |
| LLM response JSON parse success | 100% (55/55) | Production measurement | Golden set evaluation, Development log (private) |
| Response per classification (thinking off) | 5 tokens · 0.8 s | Production measurement | Model evaluation notes, Development log (private). With thinking on: 3,574 tokens, 10+ s |
| Defined test cases | 1,165 | Reproducible measurement | Count of it/test definitions in test files (2026-11-11), Development log (private) |
| LLM proposal kinds (one apply function per kind) | 11 | Reproducible measurement | Design document, Development log (private) |

## 1. Situation

An overseas client sends requests to buy domestic products through a Telegram group, and a single administrator gets quotes from domestic suppliers and passes them on. One request arrives split across 4–6 messages, sometimes as photos only, in Uzbek mixed with Russian. The administrator had to remember which deal each message belonged to, write a new inquiry email to suppliers every time, copy prices, quantities and lead times out of their replies, summarize everything again for the client, and settle accounts at month end. All of it ran on human memory and copy and paste.

Letting an LLM read the conversations makes this easier. But misreading a quantity, a quote or a bank account moves real money. If "review before applying" is only a promise, it will eventually be bypassed. So I set the starting point this way: the system owns the process, templates own the wording, the LLM handles fuzzy understanding, and a human approves every deal decision. The LLM gets no write access.

## 2. Scoping

I treated input and output differently. Input adapts to the client: no required format, and split messages, photos and mixed languages are accepted as they come. Output is designed from scratch: fixed templates and structured data, sending the client only what they need to know.

I also decided up front what not to build: OCR and image recognition, automatic email sending (drafts only; a human sends), automatic payments and transfers, LLM tool-calling loops and autonomous execution, RAG and vector search, automatic supplier merging, and multi-user permissions. There is 1 user, the administrator, so authentication is left to Cloudflare Access and the app has no login code.

## 3. Build

| Category | What | Why |
| --- | --- | --- |
| Adopted | Cloudflare Workers, D1, R2, Queues, Cloudflare Access, Hono, Next.js (OpenNext), Zod | Queues and a DLQ keep deals from getting lost, and authentication goes to a managed service |
| Fixed | Made the evaluation harness read the production prompt directly instead of a copy | The measurements were scoring a different string from production |
| Built myself | The propose → approve → apply path, a closed Record of 11 per-kind apply functions, version-based stale detection | Code structure allows exactly one write path |

LLM output is parsed with Zod and stored only as a proposal; if parsing fails, the system does not guess and marks it `invalid`. Applying goes only through the per-kind functions, and dynamic column names are banned. SQL lives in a single package, and since D1 does not support BEGIN/COMMIT, atomicity comes from `db.batch()`. Each proposal stores the version it was created against, and if the version has changed at approval time it is marked `stale`. The schema fixes amounts as integer minor units plus currency, and timestamps as UTC epoch ms.

## 4. What broke

**Transitions that never happened showed up in history.** Automatic state transitions sent a version-conditioned UPDATE and a history INSERT in one batch. When something else changed the state first and the UPDATE hit 0 rows, the history row was still written. Code review caught it; I split the two so that 0 rows means no history row either.

**The mail account was suspended.** It happened right after switching mail providers. Every IP in the login alerts was in Cloudflare ranges, and the timestamps matched the mail-polling cron interval. My hypothesis was that the cron ran from a different country's data center each time and got flagged as account takeover. A throwaway probe Worker showed that placement applies only to the fetch handler, and a fetch the cron made to itself through a service binding ran in the specified region (3/3). I routed all mail calls through an internal endpoint and pinned it to the Seoul region.

**Custom-order inquiries went unclassified.** An inquiry that came with 8 photos was classified as `other`, so no proposal was created. I added that conversation to the golden set and ran 4 ablations. Adding vocabulary hints made things worse; adding one sentence to the `new_request` criteria was both the smallest change and the best.

## 5. Results

| Metric | Value | Scope | Source |
| --- | --- | --- | --- |
| Intent classification accuracy | 97.3% (36/37) | Golden set from real conversations, single run (re-run 94.6%) | Development log (private) |
| JSON parse success | 100% (55/55) | Same evaluation | Development log (private) |
| Response per classification | 5 tokens · 0.8 s | Thinking off | Development log (private) |
| Defined test cases | 1,165 | Reimplementation | Counted 2026-11-11 |
| Proposal kinds | 11 | Reimplementation | Development log (private) |

This system was delivered to the client and is currently in operation (confirmed by the author, 2026-11). I did not measure production throughput or monthly cost, so I do not report them.

## 6. If I did it again

The screens and the demo all run on real data, so none of it can be published. I would build a demo environment with synthetic clients, suppliers and conversations first. State facts are tracked per request, so in a multi-item request a quote for one item can move the other items forward too, and a wrong request link cannot be undone. I plan to fix both with per-item facts and recalculation when a link is cancelled. The quote-structuring evaluation has only 5 fake records and needs to be re-measured on real supplier replies, and every evaluation was a single run, so it needs averages over repeated measurements.
