// Minimal typed access to the Telegram WebApp bridge (loaded via telegram-web-app.js). // Everything is null-guarded so the game still runs in a plain browser (dev mode). export type TelegramInvoiceStatus = 'paid' | 'cancelled' | 'failed' | 'pending'; type TelegramWebApp = { initData: string; ready: () => void; expand: () => void; openInvoice: (url: string, callback?: (status: TelegramInvoiceStatus) => void) => void; }; export function telegramWebApp(): TelegramWebApp | null { return (window as { Telegram?: { WebApp?: TelegramWebApp } }).Telegram?.WebApp ?? null; } /** Auth header for every API call; empty outside Telegram (server dev mode allows that). */ export function tgHeaders(): Record { const initData = telegramWebApp()?.initData ?? ''; return initData ? { 'X-Telegram-Init-Data': initData } : {}; } export function bootTelegram(): void { const app = telegramWebApp(); if (!app) return; app.ready(); app.expand(); }