Vue Telegram Integration Library
vue-tg is a lightweight package designed for seamless integration of Telegram Mini Apps and Telegram Widgets into Vue 3 applications. Currently at version 0.10.0, it maintains an active release cadence, frequently updating to support the latest Telegram Bot API versions, such as 9.5. Key differentiators include its use of Vue 3 composables for reactive interaction with the Telegram client, full TypeScript type safety, and an innovative API that enforces runtime feature support checks to prevent errors on clients with outdated Bot API versions. It also provides async/await support for methods, eliminating callback hell, and includes ready-to-use Vue components for common Mini App UI elements like MainButton and BackButton, streamlining development workflows.
Common errors
-
Type error: 'getItem' may not be available — DeviceStorage was introduced in Bot API 9.0
cause Attempting to use a Telegram Mini App feature (e.g., `deviceStorage.getItem`) that was introduced in a newer Bot API version without a runtime version check, potentially targeting an older client that does not support it.fixImplement a version check before using the feature: `if (deviceStorage.isVersionAtLeast('9.0')) { deviceStorage.getItem('token') }`. Alternatively, configure a minimum required Bot API version globally if all target clients are known to support it. -
Module not found: Error: Can't resolve 'vue-tg/latest'
cause An attempt to import a symbol (e.g., `usePopup`) using an incorrect import path, or when the `/latest` subpath export is not properly configured or recognized by the module bundler.fixVerify that the import statement matches the exact path specified in the `vue-tg` documentation for the given symbol (e.g., `import { usePopup } from 'vue-tg/latest'`). Ensure your bundler supports subpath exports if applicable.
Warnings
- breaking Since version 0.9.0, `vue-tg` introduces a new API that enforces runtime feature support checks. Directly calling Telegram Mini App features without verifying client Bot API version support can lead to runtime errors or TypeScript type errors on clients with outdated APIs.
- gotcha The core Telegram Web App JavaScript SDK (`telegram-web-app.js`) is not bundled with `vue-tg`. It is an essential external dependency that must be explicitly included in your HTML's `<head>` tag before your application scripts.
- gotcha Certain composables, such as `usePopup`, require importing from the non-standard `vue-tg/latest` subpath, rather than directly from the base `vue-tg` package. Incorrect import paths will result in module resolution errors.
- gotcha `vue-tg` frequently updates to support new Telegram Bot API versions. Developers should anticipate regular updates to the library and may need to adapt their code to leverage new features or accommodate changes in the underlying Telegram API paradigms.
Install
-
npm install vue-tg -
yarn add vue-tg -
pnpm add vue-tg
Imports
- MainButton
import MainButton from 'vue-tg'
import { MainButton } from 'vue-tg' - usePopup
import { usePopup } from 'vue-tg'import { usePopup } from 'vue-tg/latest' - useDeviceStorage
const useDeviceStorage = require('vue-tg')import { useDeviceStorage } from 'vue-tg' - Telegram Web App Script
<script src="https://telegram.org/js/telegram-web-app.js"></script>
Quickstart
<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>