Telegram Bot
A Telegram bot that gives the sales team pricing autonomy, validating margins against the ERP in real time and escalating to a supervisor when limits are exceeded.
- Areas
- Backend
- Technologies
- Python
- SQL Server
01How I spotted the opportunity
A sales rep would walk over to my desk: they needed to change an item's price. I'd pull the cost, work out the margin by hand and compare it against the minimum. If it cleared, go ahead; if it didn't, I sent them back to get the sales manager's approval. That errand repeated all day long, burning my time and the IT team's in equal measure. What bothered me wasn't the volume, it was the nature of the task: the rule already existed and it was deterministic — a minimum margin per item — and it still needed a human to apply it. There was no judgment to add there; it was a calculator with legs. Nobody asked me for the bot: I proposed it, because I was the one paying the cost of the errand. I picked Telegram for two reasons. The API is free, and every sales rep already had the app on their phone: zero install, zero training. But it was also the door to something bigger — the underlying idea was to put the same AI assistant that already lived in the BI platform into their pocket, so a rep out in the field could ask the business questions in plain language, not just change prices.
02How I built it
The first thing I decided was not to build a second user system. The bot reads its permissions from the same table as the BI platform, and they're toggled from the BI web app: who gets into the bot, who can touch prices, who approves, how many queries they get per day. The bot only reads those values; it has no admin panel of its own and no list of IDs in the code. The scopes are shared too, so a rep only ever queries their own business unit, business line and warehouse. The pricing flow became a guided conversation: the bot pulls the cost from the ERP, works out the margin on the proposed price and decides. Above the minimum, it applies. Below it, the change turns into a request a supervisor approves or rejects from their own chat. The case I cared most about was the ugly one: the request nobody answers. Requests expire on their own, and a nightly job reverts any price still waiting on approval — no price is left dangling in the ERP because someone went on vacation. For free-form queries the model writes SQL, but never against the ERP tables: there are dedicated views that already apply the user's scope filter in the database, and the bot connects through a read-only account with trimmed-down permissions. Voice notes are transcribed on the same machine with Whisper, so no audio leaves for a third-party service. It runs as a Windows service on the ERP machine, on long polling, with its configuration validated at startup so it fails on second one instead of halfway through an operation. The dumbest and most real obstacle was infrastructure: the central SQL Server negotiates TLS over an old protocol that the OpenSSL on my Linux dev machine flatly refuses. Production is Windows and never sees it, so the fix was a local OpenSSL config for development only — documented in the repo, because that's exactly the kind of thing that costs you an afternoon twice.
03What problem it solves
Around 20 sales reps and 2 supervisors use it today, and the database logs an average of 200+ price changes per day. None of them go through me or through IT: the ones that clear the margin apply themselves, the ones that don't wait on a supervisor who decides from their phone, and the ones nobody answers get reverted that same night. The errand that used to occupy my desk stopped existing. The margin rule is exactly the same as before — the only thing that changed is that it no longer needs a person to apply it. The free-form assistant, which was the original plan, ended up being used somewhere I hadn't predicted: the group's owner and the finance director talk to the bot with voice notes and get the report back in chat. I designed it for the sales rep out in the field, and the top of the pyramid adopted it.
