Skip to content

nikandr-surkov/telekit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Telegram Mini App Dev Kit

Next.js 16 TypeScript React 19 Tailwind CSS Telegram Mini App MIT License

The most comprehensive open-source playground for Telegram Mini App development

17 interactive demos ยท 50+ production-ready code snippets ยท Full TypeScript support


Quick Start โ€ข Features โ€ข Demos โ€ข Deployment โ€ข Contributing

โšก Why This Project?

Building a Telegram Mini App shouldn't mean guessing how APIs work. This dev kit gives you a live, interactive reference for every Telegram WebApp API โ€” from haptic feedback and biometric auth to Star payments and sensor access.

Whether you're building a Telegram bot, a Web3 dApp on TON, a clicker game, or a full-stack SaaS inside Telegram, this project shows you exactly how every feature works with copy-paste TypeScript code.

Perfect for:

  • Developers building their first Telegram Mini App
  • Teams evaluating Telegram as a distribution platform
  • Hackathon participants who need working examples fast
  • Anyone who learns best by reading real, working code

๐Ÿ“ฆ Features

๐Ÿ”ง Developer Experience

  • Next.js 16 App Router โ€” latest React Server Components architecture
  • Full TypeScript โ€” complete type definitions for the entire Telegram WebApp API
  • Tailwind CSS 4 โ€” utility-first styling with Telegram theme integration
  • Zustand state management โ€” lightweight, scalable global state
  • Framer Motion animations โ€” smooth, performant UI transitions
  • Prism syntax highlighting โ€” beautiful code blocks with copy-to-clipboard
  • Hot module replacement โ€” instant feedback during development

๐Ÿ“ฑ Telegram API Coverage

Category Features
Authentication Init data validation, HMAC-SHA256 verification, user identity
UI Controls Main Button, Secondary Button, Back Button, Settings Button
Payments Telegram Stars (XTR), invoices, refunds, webhooks
Biometrics Face ID, Touch ID, fingerprint authentication
Sensors Accelerometer, gyroscope, device orientation, GPS location
Storage Cloud Storage (cross-device sync), key-value persistence
Haptics Impact feedback (5 styles), notification feedback (3 types)
Media QR code scanner, file downloads, camera/microphone permissions
Sharing Story sharing with widgets, inline queries, URL sharing
Theming Dynamic header/background/bottom bar colors, dark mode
Game APIs Fullscreen, orientation lock, vertical swipe control
Platform Home screen install, emoji status, version detection

๐ŸŽฎ Demos

Every demo is interactive โ€” open the app in Telegram, tap a button, and see the API in action.

# Demo Description
1 Init Data Validate Telegram authentication with HMAC-SHA256
2 Core API Platform info, fullscreen, theme, clipboard, permissions
3 Buttons Main, Secondary, Back, and Settings button management
4 Links External links, Telegram deep links, Instant View, browser selection
5 Popups Alerts, confirms, multi-button popups, safe nesting patterns
6 QR Scanner Scan and parse URLs, contacts, WiFi, game codes
7 Storage Cloud Storage CRUD with game save/load example
8 Haptics All impact and notification feedback types with patterns
9 Sensors Accelerometer, gyroscope, device orientation, GPS
10 Biometrics Face ID / fingerprint auth flow with token management
11 Share Story Share images/videos to Telegram Stories with widget links
12 Home Screen Add-to-home-screen prompt with status checking
13 Emoji Status Set custom emoji status with duration control
14 File Downloads Trigger native file downloads (images, videos, PDFs)
15 Activity Track app activate/deactivate lifecycle events
16 Game Features Fullscreen, orientation lock, swipe control + tap game
17 Payments Complete Telegram Stars payment flow with backend examples

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • A Telegram account
  • ngrok (free) for HTTPS tunneling during development

1. Clone and Install

git clone https://github.com/nikandr-surkov/telegram-mini-app-dev-kit.git
cd telegram-mini-app-dev-kit
npm install

2. Create a Telegram Bot

  1. Open @BotFather in Telegram
  2. Send /newbot and follow the prompts
  3. Save your bot token

3. Configure Environment

cp .env.example .env.local
# .env.local
TELEGRAM_BOT_TOKEN=your_bot_token_here

4. Start Development Server

npm run dev

5. Start HTTPS Tunnel

Telegram requires HTTPS. In a separate terminal:

ngrok http 3000

Copy the https:// URL from ngrok output.

6. Connect to Telegram

  1. Go to @BotFather โ†’ /mybots โ†’ your bot
  2. Bot Settings โ†’ Menu Button โ†’ Edit Menu Button
  3. Paste your ngrok HTTPS URL
  4. Open your bot in Telegram and tap the Menu button

๐Ÿ“ Project Structure

โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ api/telegram/validate/    # Init data validation endpoint
โ”‚   โ”œโ”€โ”€ globals.css               # Telegram theme-aware styles
โ”‚   โ”œโ”€โ”€ layout.tsx                # Root layout with WebApp script
โ”‚   โ””โ”€โ”€ page.tsx                  # Main app with tab navigation
โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ demos/                    # 17 interactive demo components
โ”‚   โ”‚   โ”œโ”€โ”€ InitDataDemo.tsx      # Authentication & validation
โ”‚   โ”‚   โ”œโ”€โ”€ CoreApiDemo.tsx       # Platform APIs & theming
โ”‚   โ”‚   โ”œโ”€โ”€ PaymentsDemo.tsx      # Telegram Stars integration
โ”‚   โ”‚   โ”œโ”€โ”€ BiometricsDemo.tsx    # Face ID / fingerprint auth
โ”‚   โ”‚   โ”œโ”€โ”€ SensorsDemo.tsx       # Accelerometer, gyroscope, GPS
โ”‚   โ”‚   โ””โ”€โ”€ ...                   # 12 more demos
โ”‚   โ”œโ”€โ”€ CodeBlock.tsx             # Syntax-highlighted code display
โ”‚   โ”œโ”€โ”€ ColorPicker.tsx           # Theme color picker component
โ”‚   โ”œโ”€โ”€ DemoSection.tsx           # Reusable demo layout wrapper
โ”‚   โ””โ”€โ”€ NavigationTabs.tsx        # Horizontal scrollable tabs
โ”œโ”€โ”€ hooks/
โ”‚   โ”œโ”€โ”€ useCloudStorage.ts        # Async Cloud Storage wrapper
โ”‚   โ””โ”€โ”€ useHaptic.ts              # Haptic feedback helper hook
โ”œโ”€โ”€ providers/
โ”‚   โ””โ”€โ”€ TelegramProvider.tsx      # React context for WebApp API
โ”œโ”€โ”€ store/
โ”‚   โ””โ”€โ”€ telegram.ts               # Zustand global state
โ”œโ”€โ”€ types/
โ”‚   โ””โ”€โ”€ telegram.d.ts             # Complete WebApp type definitions
โ””โ”€โ”€ utils/
    โ””โ”€โ”€ telegram.ts               # Validation & platform helpers

๐Ÿ” Init Data Validation

Every Telegram Mini App should validate init data on the backend. This project includes a working example:

// app/api/telegram/validate/route.ts
import { validate, parse } from '@telegram-apps/init-data-node'

export async function POST(request: NextRequest) {
  const { initData } = await request.json()
  
  validate(initData, process.env.TELEGRAM_BOT_TOKEN!)
  const data = parse(initData)
  
  return NextResponse.json({ valid: true, user: data.user })
}

The @telegram-apps/init-data-node package handles HMAC-SHA256 signature verification against your bot token.


๐Ÿ’ณ Telegram Stars Payments

The Payments demo includes complete frontend and backend code for:

  • Creating invoices via the Bot API
  • Opening the native payment UI with webApp.openInvoice()
  • Handling pre_checkout_query and successful_payment webhooks
  • Processing refunds via refundStarPayment
  • Testing strategies with minimal cost

All digital goods in Telegram Mini Apps must use Telegram Stars (XTR currency) per App Store and Play Store policies.


๐ŸŒ Deployment

Vercel (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

Or connect your GitHub repo to vercel.com for automatic deployments on every push.

Set TELEGRAM_BOT_TOKEN in your Vercel project's environment variables.

After deploying, update your bot's Menu Button URL in BotFather to your production domain.

Other Platforms

This is a standard Next.js 16 app โ€” deploy anywhere that supports Node.js:

  • Railway โ€” railway up
  • Render โ€” connect GitHub repo
  • Fly.io โ€” fly launch
  • Docker โ€” next build && next start
  • AWS Amplify, Google Cloud Run, Azure App Service

๐Ÿ› ๏ธ Tech Stack

Technology Purpose
Next.js 16 React framework with App Router
React 19 UI library
TypeScript 5 Type safety
Tailwind CSS 4 Utility-first CSS
Zustand Lightweight state management
Framer Motion Animation library
Prism React Renderer Syntax highlighting
react-qr-code QR code generation
@telegram-apps/init-data-node Server-side init data validation

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Ideas for Contributions

  • Add new demo components for upcoming Telegram APIs
  • Improve TypeScript type definitions
  • Add unit tests with Vitest or Jest
  • Create a dark/light theme toggle for the code blocks
  • Add internationalization (i18n) support
  • Write tutorials or blog posts about specific features
  • Improve accessibility (a11y)
  • Add E2E tests with Playwright

๐Ÿ“š Resources

Telegram Documentation:

Community & Learning:


๐Ÿ› Troubleshooting

Mini App not opening?

  • Verify ngrok is running and the HTTPS URL is correct
  • Check your bot token in .env.local
  • Make sure you set the Menu Button URL in BotFather (not just the bot description)

"WebApp is not defined" error?

  • The app must be opened through Telegram, not a regular browser
  • The telegram-web-app.js script loads only inside the Telegram client

Features not working?

  • Some APIs require specific Telegram client versions (check the Version Check demo)
  • Sensors require physical device โ€” they won't work in Telegram Desktop
  • Biometrics require device hardware support (Face ID, fingerprint scanner)

Payment invoice not opening?

  • Ensure provider_token is empty string "" for Stars payments
  • Currency must be "XTR" for Telegram Stars
  • Bot must have payment capability (check with BotFather)

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

You are free to use, modify, and distribute this code in personal and commercial projects.


โญ Star This Repo

If this project helped you build your Telegram Mini App, please give it a โญ on GitHub โ€” it helps other developers discover it!


Built by Nikandr Surkov

Website โ€ข YouTube โ€ข Telegram โ€ข GitHub

About

50+ production-ready code examples for payments, biometrics, sensors, haptics, QR scanner, cloud storage & more

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages