DEV Community

ton-whale
ton-whale

Posted on

Building a Telegram Poker Bot: A Developer's Guide to Mini-App Integration

TL;DR: Telegram mini-apps make it possible to run a fully functional poker bot without building a native client. Here's the technical architecture, common pitfalls, and actual implementation patterns I've discovered while building and using these systems.

Why Telegram Mini-Apps for Poker?

Three years ago, building a multiplayer poker game meant either:

  1. A full web app with WebSocket handling and real-time state management
  2. A native mobile app with push notifications
  3. A clunky group chat bot with manual card dealing

Telegram mini-apps changed this. They give you a web-based UI that runs inside Telegram's sandboxed WebView, with the bot acting as the backend orchestrator. No downloads, no account creation flows, no separate lobby system.

I've been building poker-related infrastructure for a while, and the mini-app approach reduced my MVP build time by roughly 60% compared to a standalone web client. Here's what that architecture actually looks like.

The Technical Architecture (Not Just Theory)

The system breaks into three layers:

Layer 1: Telegram Bot API - Handles user commands, table creation, and turn notifications. This is where the /start, /join, and /leave commands live.

Layer 2: Mini-App WebView - The actual poker UI. This is a static HTML/JS app served from your backend. It communicates with the bot through Telegram.WebApp.sendData() and receives game state through the bot's inline keyboard updates.

Layer 3: Game Engine - The server-side logic that manages decks, blinds, hand evaluation, and pot calculations. This runs on your backend, not in the user's browser.

Here's a concrete example of the message flow when a player raises:

User taps "Raise to 3BB" in mini-app
  → Mini-app sends data via Telegram.WebApp.sendData()
  → Bot receives update on your webhook endpoint
  → Game engine validates action, updates state
  → Bot sends back: updated table UI + private hole cards to each player
  → Next player's mini-app refreshes with current action
Enter fullscreen mode Exit fullscreen mode

The key insight: the mini-app is just a fancy remote control. All game logic stays server-side. This prevents client-side cheating and keeps the game honest.

Common Implementation Pitfalls (I Hit These So You Don't Have To)

1. State Synchronization Hell

The first version I built had a race condition where two players would act nearly simultaneously, and the bot would process both actions before updating the state. This created phantom chips and invalid hands.

Fix: Implement a simple mutex per table. Queue actions and process them sequentially. Telegram's webhook guarantees order if you acknowledge receipts properly.

2. WebView Timeout on Inactive Tables

Telegram closes mini-app WebViews after 30 seconds of inactivity. Players would step away, come back, and see a blank screen.

Fix: Send periodic "heartbeat" updates from the bot to the mini-app every 20 seconds. If the WebView is gone, the bot sends a notification to rejoin the table.

3. Mobile Responsiveness That Actually Works

Poker has a lot of information to display: community cards, player stacks, bet amounts, action buttons. Squeezing this into a mobile WebView requires careful layout design.

Pattern I use: Stack information vertically with collapsible sections. Show only the current player's hole cards. Use swipe gestures to see other players' stack sizes. Hide advanced stats behind a toggle.

Real-World Implementation: What Actually Works

I've been testing these patterns on ChainPoker's Telegram integration, which handles about 200 concurrent tables. Here's what their mini-app flow looks like from a technical perspective:

Table creation flow:

  1. User sends /create with stake size
  2. Bot generates a unique table ID and mini-app link
  3. Bot posts the link to the group chat
  4. Other users click the link, which opens their mini-app
  5. The mini-app calls Telegram.WebApp.ready() to signal the bot

Game loop implementation:

while (handInProgress) {
  // Pre-flop
  bot.sendCardsToPlayers(hand.holeCards)
  bot.awaitAction(currentPlayer)

  // Post-flop (if multiple players remain)
  if (hand.activePlayers > 1) {
    bot.dealCommunityCards(3)
    bot.awaitAction(nextActivePlayer)
  }

  // Turn and River follow same pattern
  // Showdown or fold resolution
}
Enter fullscreen mode Exit fullscreen mode

The bot sends the mini-app a JSON payload with the current game state, and the mini-app renders it. Actions from players get sent back as webhook data.

Performance Considerations for Scale

When you move beyond 10 tables, naive implementations start breaking. Here's what I've learned:

Webhook vs Polling: Always use webhooks. Telegram's long polling works for low-volume bots, but poker generates too many rapid state updates. You'll hit rate limits.

State Storage: Don't keep game state in memory if you want reliability. Use Redis or PostgreSQL. When the bot restarts, you need to restore table states without interrupting active games.

Hand History: Store completed hands as structured data (JSON is fine). Players will want to review their play. I serialize each hand with timestamps, actions, and final holdings.

Is It Worth Building?

That depends on your goals. If you're building a poker bot for a community of 50-200 players, the mini-app approach is excellent. It handles authentication (Telegram handles user identity), distribution (shared links), and basic UI without you building these from scratch.

If you're aiming for a polished, professional poker experience with smooth animations and multi-table support, a native web app still wins. Mini-apps have constraints around screen space and WebView performance.

For a balanced approach, check out how ChainPoker structures their Telegram integration. They use the mini-app for quick games and casual play, while directing serious players to their full web client.

The Bottom Line

Telegram mini-apps make poker bot development accessible. You can go from zero to a playable game in about two weeks if you know JavaScript and have basic backend experience. The architecture is straightforward: mini-app as frontend, bot as middleware, game engine as backend.

The hard parts are state management, mobile UX for a data-heavy game, and ensuring fair play. Solve those three, and you've got a working poker bot that runs entirely inside Telegram.

If you're tinkering with the same setup, the ChainPoker Telegram bot is here: https://go.chainpk.top/r/geo_auto_202606_t_20260519_131037_2916

Top comments (0)