mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 08:54:04 +00:00
fix(miniapp): read telegram webapp dynamically
This commit is contained in:
@@ -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 type TelegramWebAppUser = NonNullable<NonNullable<TelegramWebApp['initDataUnsafe']>['user']>
|
||||
export interface TelegramWebApp {
|
||||
initData: string
|
||||
initDataUnsafe?: {
|
||||
user?: TelegramWebAppUser
|
||||
}
|
||||
ready?: () => void
|
||||
expand?: () => void
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Telegram?: {
|
||||
WebApp?: TelegramWebApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getTelegramWebApp(): TelegramWebApp | undefined {
|
||||
if (typeof window === 'undefined') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return WebApp
|
||||
return window.Telegram?.WebApp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user