We developed a Telegram service with an AI lawyer for a client, which consults users, analyzes documents and media, generates legal documents, and is already earning through a paid subscription.
The project was custom-built as a ready-made commercial product: the user receives a fast legal answer directly in Telegram, and the client gets an automated sales channel with payments, access limits, analytics, and an admin panel.
Task
The client needed a Telegram bot that could replace the first line of legal consultations and operate as an independent paid service.
The bot had to:
- answer users' legal questions;
- work with different request formats: text, voice, photos, video, and documents;
- support multiple languages;
- generate legal documents;
- limit free usage;
- accept subscription payments;
- provide the administrator with statistics on users, requests, and payments.
The main business goal was not to build a regular AI chat. It was necessary to launch a product that could be monetized immediately after implementation.
Problem
Legal consultations are difficult to scale manually.
Users ask questions in an unstructured way: some write several messages in a row, some send a voice message, a photo of a document, a PDF, video, or geolocation. Part of the audience speaks different languages, and legal information quickly becomes outdated and requires verification of current data.
At the same time, it was important for the client not to give away consultations for free indefinitely. A clear access model was needed: several free requests to get familiar with the product, followed by a paid subscription.
Without such a system, the client would depend on manual handling of requests, would not be able to properly control the workload, and would lose the ability to earn steadily from the service.
Solution
We developed a Telegram bot in Python and aiogram with OpenAI, PostgreSQL, Redis, and YuKassa integration.
The service works as a personal AI lawyer: it receives the user's request, converts it into a clear format, uses web search for up-to-date legal information when necessary, and returns the answer in Telegram.
A subscription model was implemented for the client: the user gets a limited number of free requests, after which the bot offers paid access. Payment is processed through YuKassa, the subscription is stored in the database, and auto-renewal enables repeat payments without manual involvement.
What we implemented
AI consultations with up-to-date information
The bot answers legal questions through an OpenAI agent. For questions where fresh data matters, web search is used: current requirements, state fees, lists of documents, nearest institutions, and changes in legislation.
The answer is generated in the user's language. This is important for an audience that may contact the service in Russian, Uzbek, Tajik, Armenian, Kazakh, or Kyrgyz.
Handling different request formats
The user can send not only text, but also:
- a voice message;
- a photo of a document or a screenshot;
- PDF, DOC, or DOCX;
- video or circular video;
- geolocation;
- a contact.
Voice and video messages are transcribed, documents are converted into text, and images are analyzed using a vision model. After that, the bot passes the data to the AI agent and returns a legal answer.
Combining several messages into one request
Users often formulate a question not in one message, but as a series of short messages. Therefore, buffering via Redis was implemented in the project.
The bot waits a few seconds, collects the user's messages into a single context, and only then sends them to the AI. This makes the answers more accurate and reduces the number of unnecessary requests to the API.
Legal document generation
The bot includes a document generation mode. The user selects the required template, answers clarifying questions, and the system automatically fills in the data and sends a ready DOCX file.
A template catalog is supported, along with working with DOCX, DOC, RTF, and TXT, as well as filling placeholders in documents.
Subscription and payments
For monetization, we implemented:
- a free request limit;
- a paid subscription;
- payment via YuKassa;
- saving the payment method;
- subscription auto-renewal;
- cancelling auto-renewal;
- a user account;
- checking access status before processing messages.
This turns the bot from a consultation tool into a commercial product that can independently accept payments and restrict access.
Admin panel and analytics
Admin statistics and data export commands were added for the administrator.
In the admin panel, you can view:
- total number of users;
- new and active users;
- number of requests;
- subscribers and non-subscribers;
- distribution by language;
- top users by activity;
- monthly dynamics in Excel.
Messages, replies, and user actions are also logged. This helps the client see how the service is being used, what requests are coming in, and how the product is evolving.
Technical foundation
The project is built on an asynchronous architecture:
- Python 3.12;
- aiogram 3;
- OpenAI Agents SDK;
- PostgreSQL;
- Redis;
- SQLAlchemy and Alembic;
- YuKassa;
- Docker and Docker Compose.
Separate background processes handle message buffer processing, user activity updates, and subscription auto-renewals.
The architecture is divided into handlers, middleware, services, database models, and background tasks. This makes it possible to further develop the product: add new document templates, change pricing plans, expand analytics, and connect new scenarios without a complete system redesign.
Result
The client received a ready-made Telegram product that is already generating revenue.
The bot does more than just answer questions; it covers the entire user journey: accepts the request, analyzes the data, provides legal consultation, generates documents, enforces limits, accepts payment, and stores the subscription.
For the client, this is a working monetization channel for legal expertise. The service can serve users without constant manual involvement, collect payments, show statistics, and scale through new templates, scenarios, and ad traffic.
What the client received
- A launched Telegram service instead of an idea or prototype.
- An AI consultant that works with text, voice, photos, video, and documents.
- A subscription model with payment and auto-renewal.
- A user account dashboard and free quota tracking.
- Admin statistics and Excel exports.
- A foundation for further product growth.
The project was built as a commercial system: the user receives legal assistance in the familiar Telegram interface, and the client gets a product that can already be sold and developed.