
How I Built a Telegram Bot with AI for Business
I'm an economist, not a programmer. My company, Specraz (спецраз.рф), arranges special permits for oversize and overweight cargo. My first AI-built bot was a mail bot: it receives emails from a government system and sorts them into chats. Everything else I'm building now started there. Here is how it happened, without sugarcoating.
Why I Needed a Bot
Special permits for oversize cargo are issued through the Safe-Route government system. It communicates by email: application statuses, completed permits, and two-factor sign-in codes.
That is manageable with a few customers. Once you have hundreds of customers and about a dozen orders a day, you end up with a dozen different carrier inboxes.
This is what signing in to a carrier account looked like. Open a Safe-Route tab, then a tab for that carrier's email. Sign in to the email, then enter the username and password in Safe-Route. The two-factor code arrives by email, so you go back, copy it, and paste it. Meanwhile, three, four, sometimes five applications are in progress. That means five account tabs and five email tabs.
There was also waiting. The government system can be slow: a state-duty invoice may not appear, or an application may take a long time to register. I had to keep checking the account or email. You can turn on email notifications, but they pop up for every message and become annoying. We also paid state duties manually by entering the UIN into a payment-order template.
I did not need another email client. I needed the right email to arrive automatically where the team was already working: Telegram.

What I Built
The bot is called @saferouteru_bot. It is public and has been running since July 2025.
- A carrier inbox in a few taps. The inboxes run on our own mail server.
- Safe-Route emails are parsed and delivered to the right order thread in Telegram.
- Smart notifications. The bot writes only about important events: a state-duty invoice arrived or an application was registered. Unneeded email types can be turned off.
- Permits are downloaded as PDF files and sent to the customer. The bot assembles the order's document package and final result.
- QR codes for unpaid state-duty invoices are generated by the bot for each account. The payment button is in the order thread. No one has to enter a UIN by hand anymore.
- Two-factor sign-in codes arrive in the same chat, so you can sign in to the account without opening email.
- Monitoring of application statuses and Safe-Route availability.
- Application watchman (still a pilot): every five minutes it checks accounts, re-sends lost emails, and raises an alert if a refusal arrives.
- Brief reconciliation: if the dimensions in a permit are smaller than in the order, the permit is not sent to the customer until a person clicks “Everything is correct.”
There is more: team invitations and member permissions, inbox-quota monitoring and cleanup of old emails, moving vehicles between accounts, exporting permits to CSV for partners, a public navigator, and MAX (a Russian messenger) integration. The bot works as a delivery channel for permits, state-duty invoices, and statuses across the logistics operation.

Since September 2026, the emails have had an archive: the “Safe-Route Emails” tab in SUZ (our order management system). It collected 660 emails in its first two days.

How I Built It
This was my first project that worked. When I started, I copied code from ChatGPT into the terminal. Then I discovered VS Code with Claude Code built in, and everything changed.
- June 10, 2025. The first commit. The history shows how I named versions: “Claude version 10,” “v16,” “v35.” Those were the numbers of code chunks I got from chatbots.
- June 13. The bot began receiving emails in real time instead of polling the inbox on a timer (IMAP IDLE).
- Early July 2025. Inbox passwords were stored encrypted. The bot began working with real emails. It took 22 days from the first commit to the first users. They were the Specraz team: the bot was already collecting emails from different inboxes into one Telegram chat.
- July 22. The bot learned to recognize Safe-Route confirmation codes.
- September 2025. A Safe-Route account parser appeared: the bot could sign in and check statuses on its own.
- 2026. The bot became part of a larger system: emails are linked to orders, permits go to the customer in their chat, and the order result is assembled automatically.
- September–October 2026. The incoming-email archive, delivery protection against failures, and brief reconciliation. More than half of all bot commits, about 215 out of 500, were made in these two months.
The bot has never been rewritten from scratch. It grows in layers, like a progressive JPEG: first a rough but working image, then the details.
How I Work with AI Agents
I do not write code. My job is to explain what hurts and check whether it got better. Claude Code handles the plan and task breakdown, Codex writes the code, and another AI agent reviews every change. Deployment is one button with a log.
Tasks are split by risk. AI handles the small things on its own. Anything involving money, writing to a government system, or irreversible actions waits for my “go ahead.” The mail bot has many such moments: it sends documents to customers, and you cannot take an email back.
What Went Wrong
Versions in names and manual rollbacks. In the first weeks, a “version” was a number in the commit message. The history has an entry from July 10, 2025: “restore stable version 118ad82.” Something broke, and I rolled it back manually. Lesson: if you cannot quickly return to a working version, every improvement is a gamble. Now rollback is a normal part of deployment.
Lost codes. The bot can sign in to a Safe-Route account on its own, which makes the government system send a code. To avoid showing people unnecessary codes, I enabled suppression: if an automatic sign-in was running then, the code was hidden. At one point, frequent automatic sign-ins caused the suppression to hide human-requested codes too: 337 of them in two days. Now the bot still delivers the code, just marked “possibly requested automatically.” The codes are one-time, so no major harm was done. Lesson: when in doubt, an extra notification is better than a lost code.
Another agent and the secrets file. Once, my five-hour Claude limit ran out on the $20 plan, and I decided to experiment by giving Gemini a task. It wiped every key and password from the settings file. It hurt: I had to restore everything. Lesson: back up your secrets file, and try a new tool on a copy of the project first.
A permit with the wrong dimensions. Sometimes the dimensions in a permit are smaller than in the customer's brief. This happened to us. The customer got lucky and noticed in time. Otherwise, they could have faced a fine of 600,000 rubles. At first, I only added a warning in the chat. Then I added a hold: the permit waits for the “Everything is correct — send to customer” button. I enabled it gradually: off, then “shadow” mode (the bot only logged that it would have held it), then live mode. Lesson: anything you cannot retract, such as an email to a customer, goes behind a flag and starts in shadow mode.
A crash in the middle of sending. If the bot crashes while sending a permit to a customer, you do not know whether it was delivered. Send it again, and the customer may receive a duplicate. Do not send it, and the customer waits. I chose this: if the outcome is unknown, the bot sends nothing and tells the team, “send it manually.” Lesson: one extra manual step is better than a document sent twice.
What got better. Instead of ten tabs, there is one chat. Sign-in codes, state-duty invoices, and statuses arrive automatically, and only for the events that matter: you can immediately see that an invoice arrived or an application was registered. There is no need to cycle through accounts anymore.
Numbers
- 22 days from the first commit to the first user.
- About 500 commits in the bot folder; the first was June 10, 2025.
- About 146,000 lines of Python code, roughly half of them automated tests.
- 660 Safe-Route emails collected by the archive in its first two days.
- Hundreds of carrier inboxes and a couple dozen users. It is a very niche product.
I described the cost of working with AI agents and servers in my article about the order management system.
Could This Work for You?

If you have already tried vibe coding yourself and got stuck—on architecture, deployment, or AI breaking something that worked—message me. I can explain how something like this could be built for you.