Telegram bot for Age of Empires II ranked stats.
It supports:
/elo <player>: pick Team Random or 1v1, then show ELO + record/last <player> [count]: pick Team Random or 1v1, then show recent matches
- TypeScript
- grammY
- Cloudflare Workers (webhook mode)
- Node.js 20+
- npm
- Cloudflare account + Wrangler
- Telegram bot token
npm installLocal development uses .env:
BOT_TOKEN: Telegram bot token
Production (Worker) uses secrets:
BOT_TOKEN: Telegram bot tokenBOT_INFO: raw JSON of TelegramgetMeresult object
Example .env:
BOT_TOKEN=123456:abcDEF...npm run devThis starts the bot using src/dev.ts.
npm run setup:commandsThis updates Telegram's command list scopes so the / menu shows:
- Private chats:
/start,/help,/elo,/last - Group chats:
/elo,/last
npx tsc --noEmit
npm run test:run- Set Worker secrets:
npx wrangler secret put BOT_TOKEN
npx wrangler secret put BOT_INFO- Deploy:
npm run deploy- Set Telegram webhook to your Worker URL:
curl "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=https://<your-worker-url>"- Verify webhook:
curl "https://api.telegram.org/bot<BOT_TOKEN>/getWebhookInfo"Fetch bot metadata:
curl "https://api.telegram.org/bot<BOT_TOKEN>/getMe"Take the result JSON object from that response and store it as BOT_INFO.
- If player name is ambiguous, bot asks you to pick a player.
- Then bot asks you to pick mode:
Team Randomor1v1. /lastcount defaults to5and max is5.
src/bot.ts: bot wiring (commands, callbacks, mention handling)src/handlers/: command and callback handlerssrc/age2.ts: Age2 API clientsrc/parsers.ts: text parsing and count clampingsrc/formatters.ts: response/help formattingsrc/index.ts: Cloudflare Worker entry pointsrc/dev.ts: local long-polling entry point