iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To integrate Telegram WebApp with Vue 3, load Telegram’s JavaScript API before your app starts, treat theme and viewport values as live platform state, and send raw launch data to your server for validation. The API works without a Vue wrapper; a wrapper is optional.
Load Telegram’s API before the Vue app starts
Telegram exposes its Mini Apps API as window.Telegram.WebApp. Add Telegram’s script to the document <head>, before other scripts, so the API is available when your app initializes:
<head>
<script src="https://telegram.org/js/telegram-web-app.js?64"></script>
<script type="module" src="/src/main.ts"></script>
</head>
The ?64 script version is the value shown in Telegram’s documentation; check the official Web Apps API reference for the current documented value before shipping, as it can change.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Keep the platform boundary small in Vue
Your app may run in an ordinary browser during development, where Telegram’s injected API is absent. Isolate access behind a small adapter and account for that absence instead of assuming the global always exists:
#1 Best Overall
import { computed } from 'vue'
type TelegramWebApp = {
themeParams: Record<string, string>
initData: string
viewportHeight: number
viewportStableHeight: number
onEvent: (event: string, callback: (...args: any[]) => void) => void
offEvent: (event: string, callback: (...args: any[]) => void) => void
}
function getTelegramWebApp(): TelegramWebApp | undefined {
return (window as any).Telegram?.WebApp
}
export function useTelegram() {
const webApp = getTelegramWebApp()
return {
webApp,
available: computed(() => Boolean(webApp)),
}
}
This minimal example provides a guarded access point; it does not make the platform’s changing values reactive by itself. Subscribe to the relevant Telegram events and update Vue state, or use a wrapper that already provides reactive values. Telegram’s API remains the canonical behavior either way.
Raw API or Vue wrapper?
Using the raw API avoids an extra dependency and lets the app follow Telegram’s documented interface directly. A Vue wrapper can offer composables and reactive values; for example, Vue-TG documents useTheme() and useViewport(). Choose based on the abstraction and dependency you want, and assess the package’s maintenance, API coverage, and types for your project. The existence of composables alone does not establish that a wrapper is the best choice.
Make theme colors respond to Telegram
Telegram supplies theme colors in themeParams and notifies the Mini App when the user’s Telegram theme changes. A one-time read at startup can leave the interface mismatched after a theme switch. Telegram also exposes CSS custom properties such as --tg-theme-bg-color and --tg-theme-text-color; using them lets styles follow platform values without manually copying each color.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors.app {
color: var(--tg-theme-text-color);
background: var(--tg-theme-bg-color);
}
If you need the colors in Vue logic, keep them in reactive state and refresh that state on Telegram’s theme-change notification. Remove the listener when the component or app-level adapter is disposed:
const webApp = getTelegramWebApp()
const theme = ref(webApp?.themeParams ?? {})
function updateTheme() {
theme.value = webApp?.themeParams ?? {}
}
webApp?.onEvent('themeChanged', updateTheme)
onUnmounted(() => {
webApp?.offEvent('themeChanged', updateTheme)
})
For a long-lived app-wide listener, register and clean it up in an app-level service rather than attaching duplicate listeners from multiple components.
Use stable viewport height for settled layout
Telegram distinguishes the current visible height from the settled height as its Mini App expands, collapses, or animates. Use viewportStableHeight when a layout needs the final available height; do not use viewportHeight as a smooth signal for pinning controls to the moving lower edge. Telegram explicitly cautions that viewportHeight does not refresh fast enough to follow that edge smoothly.
| Value | What it represents | Use |
|---|---|---|
viewportHeight |
Visible height while the Mini App sheet moves. | Not suitable for smoothly anchoring UI to the bottom edge. |
viewportStableHeight |
Visible height after gestures and animations settle. | Suitable for sizing a settled content area or bottom-anchored layout. |
Telegram exposes the settled value as --tg-viewport-stable-height. Let the main region occupy that height and scroll its content internally:
.app-shell {
height: var(--tg-viewport-stable-height, 100vh);
display: flex;
flex-direction: column;
}
.app-content {
min-height: 0;
overflow: auto;
}
.app-footer {
flex: 0 0 auto;
}
The fallback supports ordinary browser previews; it is not a substitute for checking the actual Telegram presentation modes you support. If JavaScript needs to know when the viewport has settled, listen for viewportChanged and inspect its isStateStable flag rather than treating every changing-height update as final.
Best Value
Account for safe areas and Telegram controls
Telegram’s design guidance calls for responsive, mobile-first interfaces that adapt to the user’s theme. It also highlights safe areas and content-safe-area insets, especially in fullscreen mode, so app content does not sit beneath Telegram controls or device system UI. Use the relevant inset values or CSS support in your layout; for example, apply device safe-area padding where supported:
.app-content {
padding-bottom: env(safe-area-inset-bottom, 0px);
}
Safe-area requirements can differ with client and presentation mode. Check the Telegram Mini Apps design and API guidance and verify the layout in the Telegram clients and modes your app supports.
Authenticate launch data on your server
Telegram launch data is not authenticated merely because it came from a Mini App. In particular, do not authorize from initDataUnsafe: Telegram warns that data from this field “should not be trusted” and says to use initData on the bot’s server only after validation.
Free tools Windows power users keep installed
One-click scans. No signup required.
- Read the raw launch string. In the client, send
Telegram.WebApp.initDatato your backend. Do not use the parsedinitDataUnsafeobject as proof of identity. - Validate on the backend. Parse the signed fields and verify the signature using the bot token and Telegram’s documented HMAC-SHA256 procedure. Follow the official validation instructions rather than implementing an ad hoc check.
- Check freshness. Apply an explicit maximum age to
auth_dateand reject data outside that policy. One hour is an illustrative expiry used in an authorization example, not a universal Telegram requirement; choose a limit appropriate to your application. - Create application authentication only after validation. Once the backend has verified the data and freshness, it can use the verified user or chat fields to establish the app’s own session or authorize a request.
Keep the bot token exclusively on the server. Never embed it in Vue source, a browser bundle, or a request parameter sent by the client. The browser is allowed to relay launch data; only the backend should decide whether that data is valid and what access it grants.
Quick Recap
Check the integration across launch and layout states
- Open the app in an ordinary browser preview and confirm it handles the missing Telegram global without crashing.
- Launch it inside Telegram and confirm the script loads before code that accesses
window.Telegram.WebApp. - Switch Telegram’s theme and confirm colors update without restarting the app.
- Expand and collapse the Mini App, and test fullscreen if supported; check settled sizing, internal scrolling, and safe-area spacing.
- Exercise the backend with invalidly signed launch data and data older than the app’s configured
auth_datelimit; neither should authorize a user.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

