Tahrirchi Bot backdrop
2023 → 20244 min read–
Tahrirchi Bot logo

Tahrirchi Bot

Spell-checking, Latin ↔ Cyrillic conversion for messages and Office files, and a channel assistant that fixes posts in place, built on the Tahrirchi platform.

Status
Live on Telegram
Users
~20K
Alphabets
Latin ↔ Cyrillic
Files
.docx.xlsx.pptx.txt
Stack
Pythonaiogram 2aiohttpRedis

Uzbek is written in two alphabets, Latin and Cyrillic, and both are in everyday use. The Latin one has letters like oʻ and gʻ, which people type with whatever apostrophe their keyboard gives them, and most of those are the wrong character.

Tahrirchi is an Uzbek spell-checker built by a small team I was part of. Our keyboard took first place at mGovAward 2022, and Tahrirchi won first place again at President Tech Award 2023. I worked on the spell-checker early on and was responsible for the platform's backend. I also built Tahrirchi's official Telegram bot, @tahrirchi_uzbot, so people could fix and convert their text where they already write it.

Today it has close to 20,000 users.

What it does#

Spell-check. Send a message, or a photo with a caption. The bot first fixes the apostrophes itself, then works out whether the text is Latin or Cyrillic and sends it to the Tahrirchi spell-checking API. Then it walks you through the suggestions one at a time: a few words of context with the word in bold, and a button for each correction. At the end you get your text back, corrected, with your bold, italics and links where they were. If the only problems were apostrophes, you get the fixed text straight away.

Convert. Latin to Cyrillic or back, for messages, captions and whole files: .txt, .docx, .xlsx and .pptx up to 10 MB. You send a Word document and get report_kirill.docx back, with the formatting untouched.

Channel assistant. Make the bot an admin of your Telegram channel, and it checks every new or edited post. Apostrophe fixes it applies on its own. For real mistakes it sends you a message with the error count, you step through the fixes, and it edits the post in the channel. It can also convert a post to the other alphabet and either replace it or publish it as a new post.

AutoPost. Write a post in the bot, check or convert it, and send it now or schedule it with an inline calendar and time picker.

How it's built#

How Tahrirchi Bot is put togetherView

Telegram sends updates to a webhook behind nginx. The bot answers the webhook immediately and handles the update in a background job, so a slow API call doesn't hold Telegram up. Redis holds each user's state, the current spell-check session, daily limits and stats counters. PostgreSQL holds users, channels and scheduled posts. A Celery worker checks for due posts every 15 seconds and sends them.

The bot talks to the Tahrirchi platform two ways: plain HTTP for spell-checking, and gRPC for the account side. Users can link their tahrirchi.uz account with a one-time code, and the bot checks their word quota and premium subscription over gRPC.

Everything runs as five containers with Docker Compose: the bot, Celery, nginx with certbot, PostgreSQL and Redis.

The hard parts#

Converting changes the length of the text. Cyrillic ш is two Latin letters, sh, and ц can become ts. Telegram stores formatting as offsets into the text: bold from character 12 to 20, a link from 31 to 45. Convert the text and every offset after the first change points at the wrong letters. The bot recomputes every entity's position and length segment by segment. Emoji made it worse, because Telegram counts offsets in UTF-16, where many emoji take two units. It took three fixes in August 2023 to get right.

Not everything should be converted. A URL, an e-mail address, a @username or a Roman numeral in "XXI asr" must stay as it is. Some letters depend on their neighbours: е becomes ye at the start of a word or after a vowel and e elsewhere, ц becomes s at the edges of a word and ts after a vowel, and сҳ becomes s’h so it isn't read as ш. Month names get their Russian soft signs back: fevral becomes февраль. The conversion rules run in the bot itself. The platform's API marks the words that shouldn't be converted mechanically, and the bot protects links, addresses and usernames locally.

Office files are zip archives of XML. To convert a Word document without breaking it, the bot unzips it, rewrites only the text nodes in the document XML (slides and diagrams for PowerPoint, the shared strings table for Excel) and zips it back. Fonts, tables and styles never get touched, because the bot never sees them.

What came out of it#

Two of my open-source libraries started as code in this bot. The small in-memory layer I put in front of Redis became FlipCache. The calendar and time picker I built for AutoPost became the first widgets of AiogramX.

Stack#

Python, aiogram 2, aiohttp, aiojobs, Redis, PostgreSQL (asyncpg), Celery, gRPC, lxml, Docker Compose, nginx.

A spell-checker is only useful where people already write. In Uzbekistan, that's Telegram.

Need a similar system?

If you are building a bot, automation workflow, or platform feature, I can help with architecture and implementation.

Discuss a project

More projects

Related systems, decisions, and outcomes.