A simple Next.js 15 project demonstrating how to build a Telegram Mini App with bot integration and Telegram Stars payments.
- Telegram Mini App with points game
- Telegram Bot with commands
- Telegram Stars payment integration
- Daily rewards with countdown timer
- In-memory storage (no database needed)
- TypeScript for type safety
- Tailwind CSS for styling
- Node.js 18+
- Telegram account
- ngrok (for local development)
git clone https://github.com/Hunga9k50doker/Telegram-Mini-App.git
cd Telegram-Mini-App
npm install- Message @BotFather
- Send
/newbotand follow instructions - Save your bot token
npm run devIn a new terminal:
ngrok http 3000Copy the HTTPS URL (e.g., https://123.ngrok-free.dev)
Create .env.local:
TELEGRAM_BOT_TOKEN=your_bot_token_here
NEXT_PUBLIC_APP_URL=https://123.ngrok-free.devImportant: Restart your Next.js server after updating .env.local!
npm run webhook:setupIn @BotFather:
- Send
/mybotsand select your bot - Go to Bot Settings → Menu Button
- Click "Edit menu button title" and type "Play Game"
- Click "Edit menu button URL" and enter your ngrok URL from
.env.local
Open your bot and click the menu button to launch the mini app!
├── app/
│ ├── api/
│ │ ├── buy-points/ # Stars payment
│ │ ├── claim-daily/ # Daily rewards
│ │ └── telegram-webhook/ # Bot webhook
│ ├── page.tsx # Mini app UI
│ └── layout.tsx # App layout
├── scripts/
│ ├── setup-webhook.ts # Webhook setup
│ ├── webhook-info.ts # Check webhook status
│ └── delete-webhook.ts # Remove webhook
└── .env.local # Your config
- ✅ Setting up a Telegram Mini App
- ✅ Creating a Telegram Bot
- ✅ Implementing Telegram Stars payments
- ✅ Handling webhooks in Next.js
- ✅ Building responsive Telegram UI
Users can claim 100 points every 24 hours. The countdown timer shows when the next claim is available.
Real payment integration with test refunds. Users can buy points packages:
- 1,000 points = 50 Stars
- 5,000 points = 200 Stars
- 10,000 points = 350 Stars
/start- Welcome message with mini app button/help- Instructions/refund RECEIPT_ID- Test refund system
When ngrok restarts:
- Copy new ngrok URL
- Update
NEXT_PUBLIC_APP_URLin.env.local - Restart Next.js server
- Run
npm run webhook:setup - Update URL in BotFather
Bot not responding?
- Check webhook is set correctly:
npm run webhook:info - Verify bot token is correct
- Make sure ngrok is running
Mini app not loading?
- Must use HTTPS (that's why we use ngrok)
- Open through Telegram, not regular browser
- Check
.env.localhas correct ngrok URL
"WebApp is not defined" error?
- You must open the app through Telegram
- This won't work in regular browsers
