const token = process.env.TELEGRAM_BOT_TOKEN;
const publicUrl = process.env.PUBLIC_URL;
if (!token || !publicUrl) {
  console.error('Usage: TELEGRAM_BOT_TOKEN=... PUBLIC_URL=https://domain.example node scripts/configure-telegram-bot.js');
  process.exit(1);
}
const base = `https://api.telegram.org/bot${token}`;
async function call(method, body) {
  const response = await fetch(`${base}/${method}`, { method:'POST', headers:{'content-type':'application/json'}, body:JSON.stringify(body) });
  const data = await response.json();
  if (!data.ok) throw new Error(`${method}: ${data.description}`);
  return data.result;
}
await call('setMyCommands', { commands:[{command:'start',description:'OnlyCoin oyununu başlat'},{command:'game',description:'Tap-to-Earn ekranını aç'},{command:'help',description:'Destek bilgileri'}] });
await call('setChatMenuButton', { menu_button:{ type:'web_app', text:'OnlyCoin Oyna', web_app:{ url:`${publicUrl.replace(/\/$/,'')}/game/` } } });
console.log('Telegram bot menu button configured. Referral links may use: https://t.me/YOUR_BOT?startapp=REFERRAL_CODE');
