SDK
Javascript
How to
Setup Authentication
Telegram
Authorize

OAuth Telegram Authorize

ℹ️

Before getting started, you need to follow Configuring Telegram Bot

This method allows you to login to your Xellar Embedded wallet account using a Telegram account.

Parameters

  • body (object, required): The body object containing the user's Telegram information.
    • data (object, required if dataString is empty): The data object containing the user's Telegram information.
      • id (string): User's Telegram ID
      • first_name (string): User's first name
      • last_name (string, optional): User's last name
      • username (string, optional): User's Telegram username
      • photo_url (string, optional): URL of user's profile photo
      • auth_date (string): Authentication date
      • hash (string): Authentication hash
    • dataString (string, required if data is empty): Telegram initData for Telegram Mini App
    • botUsername (string, required): The bot username generated when creating a bot on Telegram
    • expireDate (string, optional): The expiration date for the JWT token generated from the response
  • options (object, optional): Configuration object.
    • rampable (object, optional): Rampable account configuration.
      • username (string): The username for the rampable account.
      • fullName (string): The full name for the rampable account.
      • password (string): The password for the rampable account.

Returns

An AuthSuccessResponse object, potentially including a rampableAccessToken if the rampable option was provided.

If a wallet is created, the response will include a walletToken.

{
  "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "isWalletCreated": true,
  "walletToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
}

If a wallet is not created, the response will include an accessToken.

{
  "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "isWalletCreated": false,
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

If the rampable option was provided, the response will include a rampableAccessToken.

{
  "isWalletCreated": false,
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "rampableAccessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Example Usage

Basic usage

const body = {
  data: {
    id: "123456789",
    first_name: "John",
    last_name: "Doe",
    username: "johndoe",
    photo_url: "https://t.me/i/userpic/320/johndoe.jpg",
    auth_date: "1630510000",
    hash: "f1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7"
  },
  botUsername: "your_bot_username",
  expireDate: "2024-01-02"
};
const response = await sdk.auth.telegram.authorize(body);

Using Telegram Mini App

const body = {
  dataString: "auth_date=1696600040&query_id=XXxxXXXXXXXxxxx&id=123456789&first_name=John&last_name=Doe&username=johndoe&is_premium=true&hash=f1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7",
  botUsername: "your_bot_username",
  expireDate: "2024-01-02"
};
const response = await sdk.auth.telegram.authorize(body);

With rampable option

const body = {
  data: {
    id: "123456789",
    first_name: "John",
    last_name: "Doe",
    username: "johndoe",
    photo_url: "https://t.me/i/userpic/320/johndoe.jpg",
    auth_date: "1630510000",
    hash: "f1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7"
  },
  botUsername: "your_bot_username",
  expireDate: "2024-01-02"
};
 
const options = {
  rampable: {
    username: "username",
    fullName: "fullName",
    password: "password"
  }
};
 
const response = await sdk.auth.telegram.authorize(body, options);