A powerful and feature-rich TypeScript-based NPM package for interacting with Telegram Mini Apps. This package provides a seamless way to integrate Telegram Mini Apps into your projects, offering a wide range of functionalities to enhance user experience. π
- Core Methods: Ready, expand, close, and more. π οΈ
- UI Controls: BackButton, MainButton, SettingsButton. ποΈ
- Haptic Feedback: Provide tactile feedback to users. π³
- Cloud Storage: Store and retrieve user-specific data. βοΈ
- Biometric Authentication: Integrate fingerprint and face recognition. π
- Location Manager: Access device location. π
- Sensors: Accelerometer, Gyroscope, and Device Orientation. π‘
- QR Scanner: Scan QR codes directly in the app. π·
- Clipboard: Read text from the clipboard. π
- Sharing: Share media to stories and messages. π€
- Fullscreen Mode: Enter and exit fullscreen mode. π₯οΈ
- Orientation Control: Lock and unlock screen orientation. π
- Home Screen Integration: Add the app to the home screen. π
- Event Handling: Listen to and manage app events. π§
To install the package, run the following command:
npm install telegram-mini-apps-2.0
Importing the Package
import { TelegramWebApp } from 'telegram-mini-apps-2.0';
// Initialize the app
TelegramWebApp.ready();
// Set header color
TelegramWebApp.setHeaderColor('#ffffff');
// Show the back button
TelegramWebApp.BackButton.show();
// Set main button text
TelegramWebApp.MainButton.setText('Submit');
// Handle main button click
TelegramWebApp.MainButton.onClick(() => {
console.log('Main button clicked!');
});
// Provide haptic feedback
TelegramWebApp.HapticFeedback.impactOccurred('medium');
// Get device location
TelegramWebApp.LocationManager.getLocation((location) => {
console.log('Location:', location);
});
// Scan QR code
TelegramWebApp.QRScanner.show({ text: 'Scan QR Code' }, (data) => {
console.log('QR Code data:', data);
});
// Read text from clipboard
TelegramWebApp.Clipboard.readText((text) => {
console.log('Clipboard text:', text);
});
// Share media to story
TelegramWebApp.Share.shareToStory('https://example.com/media');
// Enter fullscreen mode
TelegramWebApp.Fullscreen.requestFullscreen();
// Lock screen orientation
TelegramWebApp.Orientation.lockOrientation();
// Add app to home screen
TelegramWebApp.HomeScreen.addToHomeScreen();
// Listen to events
TelegramWebApp.Events.onEvent('viewportChanged', (data) => {
console.log('Viewport changed:', data);
});
Core Modules
BackButton: Control the back button in the Mini App header. β©οΈ
MainButton: Manage the main button at the bottom of the Mini App. π―
HapticFeedback: Provide haptic feedback for user interactions. π³
CloudStorage: Store and retrieve user-specific data. βοΈ
BiometricManager: Handle biometric authentication. π
LocationManager: Access and manage device location. π
Accelerometer: Access accelerometer data. π‘
DeviceOrientation: Access device orientation data. π
Gyroscope: Access gyroscope data. π
SettingsButton: Control the settings button in the Mini App. βοΈ
Invoice: Open and manage invoices. π³
QRScanner: Scan QR codes. π·
Clipboard: Read text from the clipboard. π
Share: Share media to stories and messages. π€
Fullscreen: Manage fullscreen mode. π₯οΈ
Orientation: Control screen orientation. π
HomeScreen: Add the app to the home screen. π
We welcome contributions! If you'd like to contribute to this project, please follow these steps:
Fork the repository. π΄
Create a new branch for your feature or bugfix. πΏ
Commit your changes. πΎ
Push your branch to your fork. π
Submit a pull request. π
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions or need support, feel free to open an issue on GitHub or reach out to us at antontuzovj@gmail.com
Thanks to Telegram for providing the Mini Apps platform. π±
Special thanks to all contributors who helped make this project better. π
Happy Coding! ππ¨βπ»π©βπ»