Skip to content

TeleDeveloperz/twa-sdk

Repository files navigation

Telegram Web Apps (TWA) SDK

npm version License: MIT

An enhanced TypeScript SDK for Telegram Web Apps (TWA), providing easy access to user data and Telegram Bot API functionality.

Join our Telegram group: https://t.me/TeleDeveloperz

Features

  • 🚀 TypeScript support for better developer experience
  • 👤 Easy access to TWA user data
  • 🤖 Integration with Telegram Bot API
  • 🛠 Utility functions for common TWA operations
  • 📦 Lightweight and easy to integrate

Installation

npm install @teledeveloperz/twa-sdk

Quick Start

import { TWASDK } from "@teledeveloperz/twa-sdk";

// Initialize the SDK with the TWA init data
const sdk = new TWASDK(window.Telegram.WebApp.initData);

// Access user information
console.log(sdk.user.getFullName());

// Make API calls
sdk.getBotInfo().then(botInfo => {
  console.log("Bot info:", botInfo);
});

API Reference

TWASDK

The main class for interacting with the TWA SDK.

Constructor

new TWASDK(initData: string)
  • initData: The initialization data provided by Telegram Web App.

Properties

  • user: An instance of TelegramUser containing user information.

Methods

  • getBotInfo(): Fetches information about the bot.
  • getUserProfilePhotos(userId: number): Fetches profile photos for a given user ID.

TelegramUser

A class representing the Telegram user.

Methods

  • getId(): Returns the user's ID.
  • getFullName(): Returns the user's full name.
  • getUsername(): Returns the user's username.

Advanced Usage

For more advanced usage and examples, please refer to our documentation.

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please file an issue on our GitHub repository or join our Telegram group for community support.