hermes-kanban-miniapp/frontend/src/telegram.ts
kisskin ade88808fb
Some checks failed
CI / backend (push) Failing after 37s
CI / frontend (push) Failing after 21s
feat: M4 docker deployment - bridge + frontend containers
- packages/bridge/Dockerfile: multi-stage build (node:22-alpine)
- frontend/Dockerfile: multi-stage build + nginx:alpine
- frontend/nginx.conf: proxy /bridge to bridge service
- docker-compose.yml: bridge (3456) + frontend (8080)
- .dockerignore: exclude backend/node_modules/dist
- Fix vite proxy target to port 3456
- .env with bridge vars (AUTH_MODE=dev)
2026-07-10 14:58:20 +03:00

103 lines
2.7 KiB
TypeScript

// Telegram WebApp integration
// Uses window.Telegram.WebApp directly for maximum compatibility
// @telegram-apps/sdk-react provides typed wrappers but we keep a thin layer here
export function initTelegram(): void {
const tg = window.Telegram?.WebApp
if (tg) {
tg.ready()
tg.expand()
}
}
export function getInitData(): string {
return window.Telegram?.WebApp?.initData || ''
}
export function getColorScheme(): 'light' | 'dark' {
return window.Telegram?.WebApp?.colorScheme || 'dark'
}
export function getThemeParams(): Record<string, string> {
return window.Telegram?.WebApp?.themeParams || {}
}
export function hapticFeedback(type: 'light' | 'medium' | 'heavy' = 'medium'): void {
window.Telegram?.WebApp?.HapticFeedback?.impactOccurred(type)
}
export function showMainButton(text: string, onClick: () => void): void {
const btn = window.Telegram?.WebApp?.MainButton
if (btn) {
btn.setText(text)
btn.show()
btn.onClick(onClick)
}
}
export function hideMainButton(): void {
window.Telegram?.WebApp?.MainButton?.hide()
}
export function showBackButton(onClick: () => void): void {
const btn = window.Telegram?.WebApp?.BackButton
if (btn) {
btn.show()
btn.onClick(onClick)
}
}
export function hideBackButton(): void {
window.Telegram?.WebApp?.BackButton?.hide()
}
export function closeMiniApp(): void {
window.Telegram?.WebApp?.close()
}
// Apply Telegram theme CSS variables
export function applyTheme(): void {
const params = getThemeParams()
const root = document.documentElement
Object.entries(params).forEach(([key, value]) => {
if (typeof value === 'string') {
root.style.setProperty(`--tg-${key.replaceAll('_', '-')}`, value)
}
})
const scheme = getColorScheme()
root.dataset.theme = scheme
}
// Augment Window for TypeScript
declare global {
interface Window {
Telegram?: {
WebApp?: {
ready: () => void
expand: () => void
close: () => void
initData: string
colorScheme: 'light' | 'dark'
themeParams: Record<string, string>
HapticFeedback?: {
impactOccurred: (type: 'light' | 'medium' | 'heavy') => void
notificationOccurred: (type: 'error' | 'success' | 'warning') => void
selectionChanged: () => void
}
MainButton?: {
setText: (text: string) => void
show: () => void
hide: () => void
onClick: (cb: () => void) => void
offClick: (cb: () => void) => void
}
BackButton?: {
show: () => void
hide: () => void
onClick: (cb: () => void) => void
offClick: (cb: () => void) => void
}
}
}
}
}