mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 15:54:03 +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 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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user