Skip to content

Farfosh/telegram-web-app-pro-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” TG Data Inspector

Complete Telegram Mini App Data Inspector - Display and test all Telegram WebApp API capabilities in real-time.

⚠️ Important: This app works ONLY inside Telegram. It must be opened through a Telegram bot.


πŸš€ Quick Start (Choose Your Method)

1️⃣ Local Testing (30 seconds)

# Just open index.html in your browser
# βœ… App shows error message (expected - needs Telegram)
# βœ… Perfect for checking files are ready

2️⃣ Deploy to GitHub Pages (5 minutes) - FREE HTTPS

git init
git add .
git commit -m "TG Data Inspector"
git remote add origin https://github.com/Farfosh/telegram-web-app-pro-bot.git
git push -u origin main

# Then: GitHub β†’ Settings β†’ Pages β†’ Source: main β†’ Save
# URL: https://username.github.io/tg-inspector/

3️⃣ Quick Deploy with Vercel (1 minute) - FASTEST

npx vercel
# βœ… Gives you instant HTTPS URL: https://project.vercel.app

4️⃣ Connect to Telegram Bot (2 minutes)

1. Open @BotFather in Telegram
2. /mybots β†’ Select Your Bot β†’ Bot Settings β†’ Menu Button
3. Enter URL: https://your-deployed-url.com
4. Open bot β†’ Click Menu Button β†’ App launches! πŸŽ‰

✨ Features

πŸ“± Mobile-First Interface

  • Clean Telegram-like design
  • Full Light/Dark theme support
  • Responsive design with safe areas
  • Organized tabs for easy navigation

🎯 10 Main Sections

  1. Overview - User info, app info, initData viewer, quick actions
  2. Theme & Colors - All themeParams display, color customization, CSS variables
  3. Viewport & Safe Areas - Viewport dimensions, safe area insets (visual display)
  4. Context & Launch - Launch params, chat info, launch source, context actions
  5. Buttons & Haptics - Main/Secondary/Back/Settings buttons, haptic feedback
  6. Permissions & Device - Write access, Contact, Biometric, GPS Location, Sensors
  7. Storage Playground - Cloud Storage + Secure Storage (real Telegram APIs)
  8. Share & Invoices - Share to Story, Share Message, Open Invoice
  9. Debug & Event Stream - Popups, QR Scanner, Clipboard, Event logging
  10. Security Banner - Persistent warning about initDataUnsafe verification

⚑ Live Mode Only (No Demo Data)

This app now works ONLY inside Telegram (Demo mode removed):

  • βœ… Real data from window.Telegram.WebApp
  • βœ… Real API calls (CloudStorage, SecureStorage, BiometricManager)
  • βœ… Real Events (viewportChanged, themeChanged, etc.)
  • βœ… Real Sensors (Accelerometer, Gyroscope, Location)
  • βœ… Automatic WebApp.ready() call
  • ❌ Shows error screen if opened outside Telegram

🎨 Theme Integration

Supports all Telegram theme colors:

  • bg_color, text_color, hint_color
  • button_color, button_text_color
  • secondary_bg_color, header_bg_color
  • bottom_bar_bg_color, accent_text_color
  • section_bg_color, section_header_text_color
  • section_separator_color, subtitle_text_color
  • destructive_text_color

Colors are automatically applied via CSS Variables.

πŸ”’ Security Note

The app displays a persistent security banner:

⚠️ Security Note: initDataUnsafe is not trusted on the frontend. Any authentication/payment/privileges must be verified on the server via HMAC-SHA256 on initData before accepting any action.

πŸ’‘ Quick Tips

  • βœ… Deploy to HTTPS first (required by Telegram)
  • βœ… Test opening from Telegram (not browser)
  • βœ… Check Event Stream in Debug tab for all actions
  • βœ… Use "Load All Keys" in Cloud Storage to see saved data
  • βœ… Click "Check Status" for Biometric before authenticating
  • βœ… Try sensors on a real mobile device (not desktop)
  • βœ… Copy CSS Variables from Theme tab for your own projects

πŸ“ File Structure

web-app/
β”œβ”€β”€ index.html       # Main interface with all tabs
β”œβ”€β”€ style.css        # Styles (theme-aware, responsive)
β”œβ”€β”€ app.js           # Main logic (Live mode only)
β”œβ”€β”€ manifest.json    # PWA manifest
β”œβ”€β”€ icon.svg         # App icon
β”œβ”€β”€ package.json     # npm config
β”œβ”€β”€ .gitignore      # Git ignore
β”œβ”€β”€ LICENSE         # MIT License
└── README.md       # This file

πŸ› οΈ Features by Tab

1. Overview

  • User information (avatar, name, username, language, premium)
  • App information (platform, version, colorScheme)
  • Quick actions (Expand, Ready, Fullscreen)
  • initData viewer with Copy function

2. Theme & Colors

  • Display all themeParams as color swatches
  • Change colors (Header, Background, Bottom Bar)
  • CSS Variables viewer with Copy

3. Viewport & Safe Areas

  • Viewport dimensions
  • Safe Area Insets visual display
  • Content Safe Area Insets

4. Context & Launch

  • Launch parameters (start_param, query_id)
  • Chat information
  • Launch source detection
  • Actions (sendData, openLink, openInvoice)

5. Buttons & Haptics

  • MainButton control
  • SecondaryButton control
  • BackButton and SettingsButton toggles
  • Haptic feedback testing

6. Permissions & Device

  • Request permissions (Write Access, Contact, Biometric)
  • GPS Location (real coordinates)
  • Accelerometer (real device values)
  • Gyroscope (real device values)
  • Device Orientation control

7. Storage Playground

  • Cloud Storage - Synced across devices via Telegram Cloud
  • Secure Storage - Encrypted storage for sensitive data
  • Operations: Set/Get/Remove keys
  • Load All Keys - Fetch all existing cloud storage data

8. Share & Invoices

  • Share to Story
  • Share Message
  • Open Invoice

9. Debug & Event Stream

  • Show Popup/Alert/Confirm
  • QR Scanner
  • Read Clipboard
  • Add to Home Screen
  • Real-time Event Stream logging

πŸ› Common Issues & Solutions

❓ "Telegram WebApp Not Found"

Solution: This is normal! The app only works inside Telegram. Deploy it and open through a Telegram bot.

❓ "Bot Menu Button Not Working"

Solution: Make sure your URL uses HTTPS. GitHub Pages and Vercel provide free HTTPS.

❓ "Theme Not Applied"

Solution: Open the app from inside Telegram, not from a regular browser. Telegram themes only work in Telegram.

❓ "Sensors Not Working"

Solution:

  • Requires Telegram version 7.2+
  • Device must have physical sensors
  • User must grant permission when prompted

❓ "Cloud Storage Empty"

Solution: Click the "Load All Keys" button to fetch existing data from Telegram Cloud Storage.

❓ "Biometric Not Available"

Solution:

  • Check if your device supports biometric (fingerprint/face ID)
  • Make sure Telegram has permission to use biometric sensors
  • Click "Check Status" to see availability

πŸ“Š Project Statistics

Metric Value
Lines of Code ~1,300 lines
Total Size ~80 KB (uncompressed)
Load Time < 1 second
Dependencies Zero! Pure vanilla JS
Browser Support Chrome, Firefox, Safari, Telegram WebView
Telegram API Version 7.2+ (for sensors)

πŸ” Backend Verification

Important: Never trust initDataUnsafe on the frontend!

Always verify initData on your backend:

// Node.js example
const crypto = require('crypto');

function verifyTelegramData(initData, botToken) {
    const params = new URLSearchParams(initData);
    const hash = params.get('hash');
    params.delete('hash');
    
    const dataCheckString = Array.from(params.entries())
        .sort(([a], [b]) => a.localeCompare(b))
        .map(([k, v]) => `${k}=${v}`)
        .join('\n');
    
    const secretKey = crypto
        .createHmac('sha256', 'WebAppData')
        .update(botToken)
        .digest();
    
    const expectedHash = crypto
        .createHmac('sha256', secretKey)
        .update(dataCheckString)
        .digest('hex');
    
    return expectedHash === hash;
}

πŸ§ͺ Testing & Debug Mode

Using Telegram Test Environment

To test your Mini App without affecting production:

iOS:

  • Tap 10 times on Settings icon β†’ Accounts β†’ Login to another account β†’ Test

Telegram Desktop:

  • Open Settings β†’ Shift + Alt + Right click "Add Account" β†’ Select "Test Server"

macOS:

  • Click Settings icon 10 times β†’ ⌘ + click "Add Account" β†’ Log in

Note: Test environment is separate - you need a new user account and bot via @BotFather. You can use HTTP links (without TLS) in test mode.

Debug Mode for Mini Apps

iOS:

  1. Tap 10 times on Settings β†’ Toggle "Allow Web View Inspection"
  2. Connect iPhone to Mac via USB
  3. Open Safari β†’ Develop β†’ [Your Device Name]
  4. Launch Mini App on iOS - it appears in Develop menu

Android:

  1. Enable USB-Debugging on device
  2. In Telegram Settings, scroll down, press and hold version number twice
  3. Choose "Enable WebView Debug"
  4. Connect to computer β†’ Open chrome://inspect/#devices in Chrome
  5. Launch Mini App - it will appear for inspection

Telegram Desktop (Windows/Linux):

  1. Download Beta Version
  2. Settings β†’ Advanced β†’ Experimental β†’ Enable webview inspection
  3. Right click in WebView β†’ Choose "Inspect"

Telegram macOS:

  1. Download Beta Version
  2. Click 5 times on Settings icon β†’ Enable "Debug Mini Apps"
  3. Right click in Mini App β†’ Choose "Inspect Element"

πŸ†• Latest Telegram API Updates

This app supports the latest Telegram WebApp API features:

Bot API 9.1 (July 2025)

  • βœ… hideKeyboard() - Hide virtual keyboard

Bot API 9.0 (April 2025)

  • βœ… DeviceStorage - Persistent local storage (removed in this app - uses CloudStorage instead)
  • βœ… SecureStorage - Encrypted local storage for sensitive data

Bot API 8.0 (November 2024) - Largest Update Ever

  • βœ… Full-screen Mode - requestFullscreen(), exitFullscreen()
  • βœ… Safe Area Insets - safeAreaInset, contentSafeAreaInset
  • βœ… Homescreen Shortcuts - addToHomeScreen(), checkHomeScreenStatus()
  • βœ… Emoji Status - setEmojiStatus(), requestEmojiStatusAccess()
  • βœ… Media Sharing - shareMessage(), downloadFile()
  • βœ… Geolocation - LocationManager for GPS access
  • βœ… Device Motion - Accelerometer, Gyroscope, DeviceOrientation
  • βœ… Orientation Lock - lockOrientation(), unlockOrientation()
  • βœ… Subscription Plans - Paid subscriptions with Telegram Stars
  • βœ… Loading Screen Customization - Custom icons and colors

Bot API 7.10 (September 2024)

  • βœ… SecondaryButton - Second bottom button
  • βœ… Bottom Bar Color - setBottomBarColor()

Bot API 7.8 (July 2024)

  • βœ… Share to Story - shareToStory() method

See full changelog on Telegram Docs


πŸ“š References

🌟 Key Features Summary

Feature Status
βœ… 10 Organized Tabs All WebApp API features covered
βœ… Live Mode Only Real Telegram data (no demo)
βœ… Event Stream Real-time logging of all actions
βœ… Theme-Aware Auto Dark/Light theme support
βœ… Mobile-First Optimized for mobile devices
βœ… Safe Areas Full safe area inset support
βœ… Copy Features Copy initData, CSS vars, etc.
βœ… Zero Dependencies Pure vanilla JavaScript
βœ… Security-Aware Persistent security warnings
βœ… Real Storage APIs CloudStorage + SecureStorage
βœ… Real Sensors Accelerometer + Gyroscope + Location
βœ… Biometric Auth Fingerprint/Face ID support

πŸ“ Technical Notes

  • Requirements: Telegram WebApp API 6.1+ (7.2+ for sensors)
  • Error Handling: Global error handlers + try-catch blocks
  • Storage: Uses Telegram Cloud Storage (not localStorage)
  • Sensors: Uses Telegram's native Accelerometer/Gyroscope APIs
  • Location: Uses browser Geolocation API
  • Theme: Automatically applies via CSS variables
  • Safe Areas: Respects env(safe-area-inset-*)

Made with ❀️ for Telegram Mini Apps

Need help? Check the Common Issues section above.