fix(miniapp): read telegram webapp dynamically

This commit is contained in:
2026-03-24 05:25:01 +04:00
parent 3d52038be5
commit 25f93a6d1f

View File

@@ -1,12 +1,31 @@
import WebApp from '@twa-dev/sdk' export interface TelegramWebAppUser {
id?: number
first_name?: string
username?: string
language_code?: string
}
export type TelegramWebApp = typeof WebApp export interface TelegramWebApp {
export type TelegramWebAppUser = NonNullable<NonNullable<TelegramWebApp['initDataUnsafe']>['user']> initData: string
initDataUnsafe?: {
user?: TelegramWebAppUser
}
ready?: () => void
expand?: () => void
}
declare global {
interface Window {
Telegram?: {
WebApp?: TelegramWebApp
}
}
}
export function getTelegramWebApp(): TelegramWebApp | undefined { export function getTelegramWebApp(): TelegramWebApp | undefined {
if (typeof window === 'undefined') { if (typeof window === 'undefined') {
return undefined return undefined
} }
return WebApp return window.Telegram?.WebApp
} }