Telegram store bot architecture: from inline keyboards to PostgreSQL
A robust telegram shop bot operates across three independent architectural layers: the Telegram chat interface, the application business logic, and external enterprise systems. Customers interact only with messages and inline buttons, but behind the scenes sits a high-performance Go backend, a PostgreSQL relational database, and an asynchronous task queue. Attempting to store cart sessions or catalog caches in volatile application memory leads to dropped orders whenever services redeploy.
Incoming traffic arrives through Telegram webhooks. The HTTP handler parses the update, authenticates the request signature, maps the user to their persistent record via telegram_user_id, and dispatches the relevant catalog or cart view. To maintain sub-second response times under load, heavy operations are offloaded to background workers: invoking banking gateways, claiming warehouse inventory, or notifying dispatchers runs asynchronously through message queues.
In an e-commerce architecture, the database remains the single source of truth rather than the messaging UI. Customer carts, product variants, price tiers, status histories, and stock locks must be governed by database transactions. For deeper insights into conversational state machines, see how a bot keeps conversation state, and explore our end-to-end telegram bot development services.
Catalog and shopping cart in chat: buttons, pagination, and UX constraints
An in-chat product catalog is powered by inline keyboards (InlineKeyboardMarkup). Each product card features an image, description, price, and action buttons to adjust quantities or open the cart. However, the Telegram Bot API imposes strict structural limits: callback data payloads cannot exceed 64 bytes, and overwhelming users with hundreds of messages creates extreme friction.
To maintain an intuitive flow, a telegram bot for online store organizes inventory into a category tree no deeper than two or three levels. Navigation relies on compact pagination with previous and next buttons. The callback payload contains only a concise action identifier and entity ID (such as add:142:1), while item attributes are retrieved from PostgreSQL. Search functionality can be supported via text commands or Telegram Inline Queries.
Managing the shopping cart requires in-place message updates. Rather than generating fresh messages on every tap, the backend uses editMessageText or editMessageMedia to modify the active message. This preserves chat hygiene, updates totals instantly, and prevents the conversation from devolving into endless scrollback.
- Strict category depth: keep navigation menus within two to three levels and limit buttons per screen to avoid cluttering mobile displays.
- Payload limitations: Telegram restricts callback data to 64 bytes, requiring concise identifier schemes instead of serializing item metadata.
- In-place message editing: mutating the active message on quantity changes (+ and -) delivers instant feedback without spamming new messages.
- Persistent cart storage: save cart items in PostgreSQL or Redis keyed by telegram_user_id with a time-to-live so shoppers can resume sessions.
Inventory reservations and race conditions: stopping overselling
The most critical failure in store engineering is overselling inventory. If a store has only one item left in stock and two shoppers tap the buy button at the same instant, a naive backend might charge both customers. Resolving stock collisions manually with refunds frustrates buyers and drains operational time.
On a Go backend paired with PostgreSQL, race conditions are mitigated through row-level locking (SELECT ... FOR UPDATE) or atomic SQL statements. When a customer initiates checkout, the backend creates an inventory hold with a strict time-to-live. Available inventory is decremented atomically: UPDATE products SET available_stock = available_stock - 1 WHERE id = $1 AND available_stock >= 1 RETURNING id. If zero rows update, the bot alerts the buyer that the item just sold out.
A background worker monitors expiring reservations. If the customer fails to complete payment before the countdown expires, the hold is released, returning units to available inventory. For implementing reliable retry loops and background cleanup routines, review our guide on background jobs and queues in Go.
- Atomic inventory holds: check availability and claim stock inside a single ACID database transaction to eliminate concurrency bugs.
- TTL reservation windows: give each order a limited payment window, after which inventory returns to the shelf automatically.
- Separation of physical and available stock: track total warehouse units alongside reserved units to preserve operational visibility.
- Idempotent checkout triggers: ensure duplicate taps on the checkout button do not generate duplicate reservation holds or double-charge cards.
Checkout flow and payment processing
Friction during checkout damages conversion rates. A high-converting bot collects only essential order details: fulfillment method (pickup or courier), delivery address, and a verified telephone number. For contact collection, the bot displays a native SendContact keyboard button, allowing buyers to share their verified phone number in a single tap without manual typing.
Payment processing can be implemented through native Telegram Payments API or by dispatching an external checkout link to an acquiring gateway. Telegram Payments opens a native payment sheet directly within the messenger, delivering high conversion with minimal screen hops. Telegram submits a pre_checkout_query update to your backend, which must respond with answerPreCheckoutQuery(ok=true) within 10 seconds after verifying pricing and stock integrity.
Once payment clears, Telegram delivers a successful_payment event. The backend transitions the order status to paid, logs transaction metadata, and triggers digital fiscal receipt generation. For integration specifics, webhook security, and fiscal compliance, consult our guide to telegram bot payments, and verify safe retry handling in API idempotency and retries.
Syncing with 1C, ERP, and CRM: catalogs, prices, and orders
A Telegram store bot cannot operate as an isolated silo. If your enterprise uses 1C:Enterprise, MoySklad, or a CRM like amoCRM or Bitrix24, the bot must sync with the master catalog. New customer orders must register in warehouse systems instantly, while price updates and stock adjustments must propagate back to the bot.
Avoid executing synchronous API requests to 1C or CRM systems inside Telegram webhook handlers. If an enterprise server slows down during batch processing or becomes unreachable, the webhook will time out and the user encounters a frozen dialogue. Instead, decouple systems with an asynchronous task queue. The bot writes the order locally, confirms receipt to the buyer, and a background worker delivers the payload to the ERP with automatic retries.
Synchronizing product catalogs and inventory levels is handled through periodic delta imports or inbound webhooks triggered by ERP events. For comprehensive architectural blueprints covering enterprise connectors and data protocols, explore telegram bot 1C integration and our overview of CRM and ERP integration methods.
Order management: Telegram operator chat vs web admin panel
Every order requires operational oversight: confirming shipments, printing waybills, and fielding customer inquiries. In the early stages of a store, deploying an elaborate web dashboard is often unnecessary overhead. The entire fulfillment loop can run inside a private staff Telegram group.
When a new order arrives, the bot posts an operational card to the staff group. The card details ordered items, delivery addresses, customer phone numbers, and interactive status buttons ("In Assembly", "Handed to Courier", "Delivered", "Cancelled"). When an operator taps a button, the bot updates the card in the staff chat and pushes an immediate status alert to the customer's private chat.
As volume grows, chat-based management reaches its limits: searching order histories becomes unwieldy, bulk packing slips cannot be batch-printed, and analytical reporting is absent. At scale, businesses transition dispatchers to a dedicated web portal or native CRM, keeping the bot focused on customer communication.
- Staff group dispatching is ideal for: emerging stores, low order volumes, and small teams managing orders collaboratively.
- Real-time customer status updates: dispatch actions taken by managers trigger instant push notifications to the buyer's chat.
- Chat-based limitations: lacks financial reporting, role-based permission scoping, and advanced logistics routing.
- Dedicated web admin or CRM needed for: multi-warehouse routing, high order velocity, automated courier dispatching, and accounting exports.
Chatbot, Telegram Mini App, or website: choosing the right format
Forcing an inventory of ten thousand SKUs into conversational message threads creates a frustrating user experience. Endless clicking through nested menus exhausts shoppers. Choosing the right channel depends on catalog breadth, visual requirements, and purchasing frequency.
A chat-based bot using inline keyboards excels for compact inventories, routine repeat orders, subscription renewals, and digital goods. When your store sells apparel, cosmetics, or electronics requiring multifaceted filters, size charts, and complex shopping carts, a Telegram Mini App provides the optimal middle ground. Mini Apps run responsive web applications inside Telegram without leaving the platform. Read our breakdown on telegram mini apps for design and technical nuances.
A traditional e-commerce website remains indispensable for organic search engine acquisition and desktop shoppers. In mature commerce ecosystems, a Telegram bot or Mini App rarely replaces a website entirely; instead, it serves as a high-retention retention engine for repeat buyers.
- Inline keyboard chatbot: up to thirty items, single-product funnels, recurring delivery re-orders, digital downloads, fast purchases.
- Telegram Mini App: visual catalogs, apparel, consumer electronics, multi-attribute filtering, large shopping carts.
- Standard e-commerce website: SEO customer acquisition, large wholesale portals, multi-thousand SKU indexing.
- Omnichannel strategy: acquire top-of-funnel traffic via search and web ads, then drive retention and recurring orders into a Telegram bot.