MVP Telegram Mini App game on Netlify Functions + MongoDB.
- Frontend: Vite + React + TypeScript (
web) - Backend: Netlify Functions + TypeScript (
netlify/functions) - DB: MongoDB (
mongodb/init/001_init.js) - Bot: grammY webhook (
/api/telegram-webhook) - Shared domain/types:
packages/shared
yarn install
cp .env.example .envFill .env:
MONGODB_CONNECTION_STRINGMONGODB_DB_NAME(optional, defaultkoth)JWT_SECRETADMIN_SECRETTELEGRAM_BOT_TOKENTELEGRAM_BOT_USERNAMETELEGRAM_CHANNEL_ID(default-1003655493510)APP_BASE_URLVITE_TELEGRAM_BOT_USERNAMESENTRY_DSN(optional, enables backend error tracking)SENTRY_TRACES_SAMPLE_RATE(optional, e.g.0.1to sample 10% transactions)SLOW_REQUEST_THRESHOLD_MS(optional, default1200, emits slow-request Sentry messages)WAKE_INTERVAL_MS(optional, default28800000, 8h between wakes)TON_OUT_ADDRESS(fixed receiver for Web3 activation mission)TON_ACTIVATE_AMOUNT(TON units for activation mission, default1)TON_API_V4_ENDPOINT(for on-chain verification, e.g.https://ton-mainnet-v4.kingofthehill.pro/or localhttp://localhost:31777)
Run once against your MongoDB:
mongosh "$MONGODB_CONNECTION_STRING" mongodb/init/001_init.jsyarn dev:web
netlify devcurl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/setWebhook" \
-d "url=${APP_BASE_URL}/api/telegram-webhook"Start a self-hosted ton-api-v4 instance used by server-side payment verification:
cd ton-api-v4
docker compose up -dThis exposes http://localhost:31777 and matches the reverse proxy https://ton-mainnet-v4.kingofthehill.pro/.
yarn test
yarn typecheck
yarn build- Frontend sends
x-trace-idfor each API request and logs[api-trace]to browser console with:front_total_msserver_total_msdb_total_msdb_opsnetwork_plus_edge_ms
- Netlify functions return timing headers:
x-trace-idx-server-total-msx-db-total-msx-db-opsserver-timing
- Backend sends a Sentry warning message
Slow Netlify function requestwhen request latency exceedsSLOW_REQUEST_THRESHOLD_MS, with trace metadata (path, method, total, db breakdown).
Join channel(join_channel) is always active by default and uses channel id-1003655493510unless overridden byTELEGRAM_CHANNEL_ID.Connect wallet(connect_wallet) rewards 50 sandwiches + 50 coffee after wallet connection and mission completion.Activate Web3(activate_web3) requires a TON transfer with invoice comment and is verified on-chain before mission completion.
- Frontend uses TonConnect manifest from
web/public/tonconnect-manifest.json. - Replace placeholder URLs/icons in the manifest before production deploy.
- Connected wallet address is saved via
POST /api/payments/ton/confirm.
POST /api/auth/telegramPOST /api/action/wakeGET /api/inventoryGET /api/leaderboard?limit=50GET /api/missionsPOST /api/missions/completePOST /api/items/buy(stub)POST /api/items/use(stub)POST /api/payments/ton/create-intent(stub)POST /api/payments/ton/confirm(stub)POST /api/payments/ton/activate-web3/create-intentPOST /api/payments/ton/activate-web3/syncPOST /api/admin/missions/createPOST /api/admin/missions/activate-latest-postPOST /api/admin/users/set-premium
Admin endpoints require x-admin-secret.