Skip to content

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.

Client
NURI Trading (international B2B sourcing and trading company)
Role
Design, implementation, operations
Stack
TypeScript · Cloudflare Workers · D1 · R2 · Queues · Hono
nuri-bot: Turning Telegram purchase requests into approvable deals

By the numbers

Every figure is a measured value with a source. Values from the rebuilt environment are marked as such.

Intent classification accuracy · real-conversation golden set 36/37
97.3%
  • Intent classification accuracy (golden set)Production measurement

    97.3% (36/37)

    Golden set evaluation drawn from real conversations, Development log (private). Re-run: 94.6% (35/37)

  • LLM response JSON parse successProduction measurement

    100% (55/55)

    Golden set evaluation, Development log (private)

  • Response per classification (thinking off)Production measurement

    5 tokens · 0.8 s

    Model evaluation notes, Development log (private). With thinking on: 3,574 tokens, 10+ s

  • Defined test casesReproducible measurement

    1,165

    Count of it/test definitions in test files (2026-11-11), Development log (private)

  • LLM proposal kinds (one apply function per kind)Reproducible measurement

    11

    Design document, Development log (private)

A vault behind a glass wall

How this project works, redrawn as one machine. Left alone it tours itself; press or drag to take over.

How it was solved

01Problem

Problem

The client splits one request into 4 to 6 messages, sometimes sends only photos, and mixes Uzbek with Russian. A single administrator kept these conversations in their head and handled quotes and settlements by copy and paste.

02Judgment

Judgment

Letting an LLM read the conversation makes the work easier. But a misread quantity, quote, or bank account moves real money. A "review before applying" rule that is only a promise gets bypassed sooner or later.

03Principle

Philosophy

Use the intelligence of the LLM, but never give the LLM write access to the system. Input adapts to the client. Output is redesigned as fixed templates and structured data.

04Structure

Structure

LLM output is parsed with Zod and stored only as a proposal. If parsing fails, it is marked invalid. Only proposals the administrator approves are applied, by a per-kind function. If the version changed after the proposal was made, it is marked stale.

05Result

Result

The code structure allows one write path. Intent classification on the golden set is 97.3% (36/37), and JSON parse success is 100% (55/55). There are 1,165 defined test cases.

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

CategoryWhatWhy
AdoptedCloudflare Workers, D1, R2, Queues, Cloudflare Access, Hono, Next.js (OpenNext), ZodQueues and a DLQ keep deals from getting lost, and authentication goes to a managed service
FixedMade the evaluation harness read the production prompt directly instead of a copyThe measurements were scoring a different string from production
Built myselfThe propose → approve → apply path, a closed Record of 11 per-kind apply functions, version-based stale detectionCode 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

MetricValueScopeSource
Intent classification accuracy97.3% (36/37)Golden set from real conversations, single run (re-run 94.6%)Development log (private)
JSON parse success100% (55/55)Same evaluationDevelopment log (private)
Response per classification5 tokens · 0.8 sThinking offDevelopment log (private)
Defined test cases1,165ReimplementationCounted 2026-11-11
Proposal kinds11ReimplementationDevelopment 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.