vue-tg
- Telegram integration for Vue
A lightweight package for seamless integration of Telegram Mini Apps and Telegram Widgets features.
<template> <MainButton text="Open alert" @click="() => popup.showAlert('Hello!')" /> </template> <script lang="ts" setup> import { MainButton } from 'vue-tg' import { usePopup } from 'vue-tg/latest' const popup = usePopup() </script>
Install package:
To connect your Mini App to the Telegram client, place the script telegram-web-app.js
in the <head>
tag before any other scripts, using this code:
<script src="https://telegram.org/js/telegram-web-app.js"></script>
In addition to static typing, the library enforces runtime feature support checks to prevent errors on clients with outdated Bot API support.
const deviceStorage = useDeviceStorage() // ❌ Type error: // 'getItem' may not be available — DeviceStorage was introduced in Bot API 9.0 deviceStorage.getItem('token') if (deviceStorage.isVersionAtLeast('9.0')) { // ✅ Safe to use deviceStorage.getItem('token') }
You can opt out of these checks or define a minimum required Bot API version, which disables warnings for features introduced up to that version. For details, see the versioning section in the documentation.
You can react to changes using the standard Vue reactivity pattern:
const miniApp = useMiniApp() watch(miniApp.isActive, (isActive) => { if (isActive) startUpdating() else stopUpdating() })
The isActive
field is reactive, so it can be used in watch
, computed
, or any other reactive context.
In the documentation, all reactive fields are marked with reactive tag.
You can use async
/await
to work with methods — no need to nest callbacks.
const miniApp = useMiniApp() const qrScanner = useQrScanner() const popup = usePopup() // Old callback-style flow qrScanner.show({ text: 'Scan URL' }, (url) => { popup.showConfirm(`Open ${url}?`, (ok) => { if (ok) { miniApp.openLink(url) } }) }) // The modern way — flat and readable const url = await qrScanner.show({ text: 'Scan URL' }) const ok = await popup.showConfirm(`Open ${url}?`) if (ok) { miniApp.openLink(url) }
Methods that support async execution are marked with async tag in the documentation. Callback-style usage is still available for compatibility.
Available components:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4