1.0.2 • Published 3 months ago

react-native-tdlib v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

React Native TDLib

NPM Version License npm Downloads

āš ļø Note: This library is currently under development, and contributions are welcome! If you'd like to help improve the library, feel free to submit issues or pull requests.

react-native-tdlib is a React Native bridge for the TDLib (Telegram Database Library) that allows developers to interact with Telegram's API seamlessly in their React Native applications.

Installation

npm install react-native-tdlib
# or
yarn add react-native-tdlib

Available Methods

The library provides the following methods for interacting with Telegram's TDLib. These are grouped into Base API and High-Level API for easier understanding.


High-Level API

These methods simplify common tasks and abstract away low-level details.

MethodDescription
startTdLibStarts the TDLib service with required parameters.
loginInitiates login with a phone number.
verifyPhoneNumberVerifies a phone number using an OTP code.
verifyPasswordVerifies the account password for two-factor authentication.
getAuthorizationStateFetches the current authorization state.
getProfileRetrieves the profile information of the logged-in user.
logoutLogs out of the current session.

Base API (Not recommended)

These methods offer low-level access to TDLib's functionalities.

MethodDescription
td_json_client_createCreates a new TDLib client instance.
td_json_client_executeSynchronously executes a TDLib request.
td_json_client_sendSends a TDLib request asynchronously.
td_json_client_receiveReceives a TDLib response with a timeout.

Example Usage

High-Level API Example

// Start TDLib
await TdLib.startTdLib({
  api_id: 123456,
  api_hash: 'your_api_hash'
});

// Login with phone number
await TdLib.login({
  countrycode: '+1',
  phoneNumber: '1234567890'
});

// Verify phone number
await TdLib.verifyPhoneNumber('12345'); // Replace with the OTP you received

// Verify password (Optional)
await TdLib.verifyPassword('password');

// Get current profile
const profile = await TdLib.getProfile();
console.log(profile);

Base API Example

const tdLibParameters = {
    '@type': 'setTdlibParameters',
    parameters: {
        database_directory: 'tdlib',
        use_message_database: true,
        use_secret_chats: true,
        api_id: 123456, // Replace with your API ID
        api_hash: 'your_api_hash', // Replace with your API Hash
        system_language_code: 'en',
        device_model: 'React Native',
        system_version: '1.0',
        application_version: '1.0',
        enable_storage_optimizer: true,
    },
};

// Send TDLib parameters
TdLib.td_json_client_send(tdLibParameters);

Features

  • Direct communication with TDLib for Telegram API interactions.
  • Cross-platform support for iOS and Android.
  • Easy-to-use methods for common TDLib operations, such as setting parameters, sending requests, and receiving updates.

šŸ“ TODO

  • Move Prebuilt Library out of Repository
  • Complete Android Method Implementations
  • Improve Documentation
  • Make a list of methods to implement

Example Project

This repository includes an example directory with a fully functional React Native project that demonstrates how to use the library. You can explore the example project to see how the library is integrated and used.

Running the Example

  1. Clone the repository:
git clone https://github.com/vladlenskiy/react-native-tdlib.git
cd react-native-tdlib/example
  1. Install dependencies:
npm install
# or
yarn install
  1. Run the app:
npx react-native run-android   # For Android
npx react-native run-ios       # For iOS