How we built a Telegram Mini App shop on top of an existing store
A Telegram shop sounds like a front-end problem: draw a product grid in a Mini App and you're done. Building Chat'N'Sell taught us the grid is the easy part. The hard parts are at the edges: a catalogue in someone else's
A Telegram shop sounds like a front-end problem: draw a product grid in a Mini App and you're done. Building Chat'N'Sell taught us the grid is the easy part. The hard parts are at the edges: a catalogue in someone else's platform, a bot that belongs to the merchant, a checkout we may not own, and messages that must reach people without annoying them.
Chat'N'Sell turns an existing online store into a shop inside Telegram: its own bot plus a Mini App storefront built from its catalogue, kept in sync with WooCommerce, Magento / Adobe Commerce, OpenCart, PrestaShop, BigCommerce, Horoshop or KeyCRM.
The constraint: the store stays the store
Two rules shaped everything. The store is the source of truth: we keep a copy of the catalogue so the Mini App is fast, but changes only flow from the platform to us. And checkout stays on the store: the shopper pays on the merchant's own checkout, with its payment methods, shipping and taxes. Chat'N'Sell never takes the shopper's money.
So the platform plugins are thin, free connectors that translate their platform's data. The bot, storefront, discounts and messages are configured in our dashboard.
One catalogue shape for seven platforms
Every connector, plugin or API client, produces the same normalised product: title, HTML body, images, up to three options and a flat list of variants with price, availability, stock and a compare-at price (kept only when higher than the price). A product without options has exactly one variant. Everything goes through one ProductSyncService, so the Mini App and dashboard never know which platform a product came from.
The shape is simple; the ids are not. Our carts store variant ids as integers, but OpenCart identifies a variant by its option combination, a string like "227:31". Instead of a mapping table, the sync derives a stable integer from the composite key and keeps the original next to it:
'id' => self::intId($raw) ?: self::stableId($productId, (string) $raw),
// ...
'connect' => ['product_id' => $productId, 'variant_id' => is_numeric($raw) ? (int) $raw : (string) $raw],
private static function stableId(int $productId, string $raw): int
{
return (int) sprintf('%u', crc32("{$productId}:{$raw}")) + 1_000_000_000_000;
}
At checkout we send the original id back unchanged, so the plugin never has to decode ours.
How changes arrive depends on the platform. Those with a dependable background queue (WooCommerce's Action Scheduler, Magento's cron) push events within a minute. OpenCart and PrestaShop have no reliable cron, so their plugins send during the merchant's save with a 3-second timeout, queue failures locally, and we read that queue every 5 minutes. Horoshop and KeyCRM have no catalogue events, so we poll: Horoshop gets prices and stock every 15 minutes and a full pass hourly; KeyCRM runs slower because its 20 requests a minute are shared with the merchant's other integrations. A nightly full sync catches anything an event missed.
A bot per store, and trusting initData
Every store has its own bot, created by the merchant in BotFather. When they paste the token we check it with getMe, store it encrypted, set the Mini App as the menu button and register a webhook whose URL carries the store id. The webhook's secret_token is an HMAC of store id and bot token, so it needs no storage and changes with the token. Each update's X-Telegram-Bot-Api-Secret-Token header is checked with hash_equals; otherwise anyone who guessed a store id could post fake updates.
The Mini App sends Telegram's initData with every API request in an X-Telegram-Init-Data header, and middleware validates it against that store's own bot token:
$secretKey = hash_hmac('sha256', $botToken, 'WebAppData', true);
ksort($params);
$dataCheckString = collect($params)
->map(fn($v, $k) => "{$k}={$v}")
->implode("\n");
$computed = hash_hmac('sha256', $dataCheckString, $secretKey);
return hash_equals($computed, $hash);
Two details took longer than the hash. We accept initData up to a day old, because a shopper back from a slow checkout still carries the initData the Mini App opened with. And the first screen fires several requests at once, so the shopper row is created with createOrFirst on a unique store and user pair: the first insert wins, the others read its row.
Handing the cart to the store's own checkout
The cart lives on our side until the shopper taps Checkout. Then we reprice every line with today's bot discounts (an ended discount must not reach the store), remove lines whose variant no longer exists and name them, and build a handoff.
For our plugins (WooCommerce, OpenCart, PrestaShop) the handoff is a link to the plugin's checkout endpoint: a base64url JSON payload (lines, the shopper's name and email, a link back to the bot) signed with HMAC-SHA256 over timestamp.payload using the secret from pairing. The plugin accepts it for 30 minutes, fills the visitor's cart, applies a bot price only when it is below the catalogue price, and opens the normal checkout.
The payload also carries a ref, which is how the order finds its way back. We didn't want a lookup table that a cache flush could lose, so the ref proves itself:
public static function makeRef(Store $store, string $telegramUserId): string
{
$body = base_convert(ctype_digit($telegramUserId) ? $telegramUserId : '0', 10, 36) . '-' . strtolower(\Illuminate\Support\Str::random(6));
// refSignature(): the first 10 hex characters of an HMAC over
// the store id and $body, keyed with a server-side secret.
return self::REF_PREFIX . $body . '-' . self::refSignature($store->id, $body);
}
The Telegram user id rides inside in base 36 and the signature binds it to the store, in at most 40 characters of [a-z0-9-].
Other platforms take the cart their own way. For Magento we build a guest cart over REST, so stock and option errors show up in the bot before the shopper leaves, and the module's handoff page puts it in their session. BigCommerce gets a server-to-server cart and returns its checkout URL. Horoshop has no cart API, so a script on the shop reads a signed token, fetches the cart from us and opens /checkout/; with no line-price or coupon API there, the shopper pays the shop's own prices. KeyCRM has no storefront, so the cart becomes an order request (idempotent, keyed by a reference derived from the cart), and the merchant's team confirms it and arranges payment.
Opening the checkout mattered too. On phones we call openLink, which layers Telegram's in-app browser over the Mini App, so closing it returns the shopper to the cart. Loading the checkout into the Mini App's own window stranded people: the store's page has no Telegram script to answer the back button.
Orders back into the bot
Plugins report only orders that carry a ref, and we keep one only if its ref verifies for this store, so a plugin bug or a forged ref can't turn ordinary sales into bot orders. Every platform's order maps to one money model (subtotal, discounts, shipping, tax, a taxes_included flag), and any other charge shows as "Other charges", so the breakdown adds up.
Order updates must survive webhooks delivered twice. Each message (paid, received, shipped, tracking, cancelled, refunded) is claimed by setting its timestamp column with an update that matches only while the column is empty; only the call that set it sends. Orders that first reach us more than three days old are imported history and get nothing. Cash on delivery and bank transfer orders get "order received" at once instead of waiting for an offline payment.
The cart is kept after the handoff and emptied when the order arrives, so an unfinished checkout is still a cart a reminder can point at.
Messages that don't become spam
Broadcasts, abandoned cart reminders, back-in-stock alerts and order updates all end in the same delivery service. Three rules keep it polite.
Pace. Telegram allows about 30 messages a second per bot, so broadcast sends stay at 25 and wait for a slot instead of being skipped:
public static function throttled(int $storeId, callable $send): void
{
$key = "telegram-bot-{$storeId}";
while (\Illuminate\Support\Facades\RateLimiter::tooManyAttempts($key, 25)) {
usleep(250000);
}
\Illuminate\Support\Facades\RateLimiter::hit($key, 1);
$send();
}
An earlier version used RateLimiter::attempt, which returns false without sending, so every shopper after the 30th in a minute quietly missed the broadcast.
Once only. Every delivery is logged per message, so a retried broadcast job skips anyone already reached, and one message never runs in two workers at once.
Consent. When Telegram answers "bot was blocked by the user", "user is deactivated" or "chat not found", the shopper is marked blocked and left alone until they come back; my_chat_member updates flip that status both ways. Shoppers can opt out of promotions in the Mini App, and cart reminders, back-in-stock and price-drop alerts skip them. Each of those fires once: one reminder per cart state, after a delay the merchant sets (three hours by default) and only for carts touched in the last week; one alert per subscription; and a price drop counts only at 1% or more, not a rounding wobble.
Prices and languages, the store's way
Where the platform exposes its price format, we read symbol position, separators and decimals into one template like {amount} ₴, applied by the same rules in PHP (bot messages) and JavaScript (Mini App).
We translate the interface into eight languages. Product text comes only from the platform's own translations, falling back to the store's main language, never machine translation. A shopper's language is the one they saved, else the Mini App's request, else Telegram's, else the one the merchant set for their country, always one the store offers.
What we'd tell anyone building a Telegram Mini App shop
- Validate initData on every request, against the right bot's token, and decide how long it should stay valid.
- Don't own checkout. Hand off a signed, short-lived cart and let the store handle payment, tax and shipping.
- Make order references self-verifying, so matching orders back needs no state.
- Normalise the catalogue once, and keep the platform's original ids beside your own.
- Rate-limit by waiting, not skipping, and log every delivery so retries can't double-send.
- Treat "blocked" and opt-outs as data you act on immediately.
If you run a store on one of these platforms, the connectors are free and messages to your subscribers cost nothing; the bot, storefront and messages are all set up in the Chat'N'Sell dashboard. New to Mini Apps? Our guide What is a Telegram Mini App covers the basics. Questions about the internals are welcome in the comments.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.