# Implement Ramper Telegram SDK

## Guide

There are 2 ways to add Ramper Embedded Wallet to a Telegram Mini App:

### **Method 1: Using npm (Recommended)**

> npm link: <https://www.npmjs.com/package/@ramper-v2/telegram-sdk>

```jsx
import RamperTelegram from 'ramper-telegram';
const sdkConfig = {
    // gameId provided by Ramper, request before using the SDK
    gameId: 'sdk_sample',
    partner: 'coin98',
    // partner app id provided by Ramper, request before using the SDK
    appId: 'missing_app_id',
    // callback functions for handling sign in success, sign in fail and sign message
    onSignInSucess: (uProfile) => {
        // handle user profile after sign in success
        console.log('sign-in-success', uProfile);
    },
    onSignMessage: (msg) => {
        // handle message after sign in success
        console.log('sign-message-success', msg);
    },
    onSignInFail: (ev) => {
        // handle sign in fail
        console.error('sign-in-fail', ev);
    }
}

// Initialize RamperTelegram
RamperTelegram.initializeAsync(sdkConfig)
    .then(() => {
        console.log('init ramper success')
    })
    .catch((reason => {
        console.error('');
    }))
```

### **Method 2: Using CDN in HTML**

```jsx
<!-- Double check the version of the SDK before using it -->
<script src="https://game-sdk.static.cyborg.game/rampertelegram.umd.production.min.js"></script>
<script>
    RamperTelegram.initializeAsync({
        // gameId provided by Ramper, request before using the SDK
        gameId: 'sdk_sample',
        partner: 'coin98',
        // partner app id provided by Ramper, request before using the SDK
        appId: 'missing_app_id',
        // callback functions for handling sign in success, sign in fail and sign message
        onSignInSucess: (uProfile) => {
            // handle user profile after sign in success
            console.log('sign-in-success', uProfile);
        },
        onSignMessage: (msg) => {
            // handle message after sign in success
            console.log('sign-message-success', msg);
        },
        onSignInFail: (ev) => {
            // handle sign in fail
            console.error('sign-in-fail', ev);
        }
    }).then(() => {
        console.log('init ramper success')
    }).catch((reason => {
        console.error('');
    }))
</script>
```

## **Functions**

### getSDKVersion

#### **Description**

The string representation of this SDK version.

> **getSDKVersion**(): `string`

#### **Returns**

`string` Returns string The SDK version.

#### **Example**

```jsx
var sdkVersion = RamperTelegram.getSDKVersion(); // '1.0'
```

### hideIframe

#### **Description**

Hide iframe

> **hideIframe**(): `void`

#### Returns

`void`

#### **Example**

```jsx
RamperTelegram.hideIframe();
```

***

### initializeAsync

#### **Description**

Initializes the SDK library. This should be called before any other SDK functions. Login request be fired on this.

> **initializeAsync**(`config`): `Promise`<`any`>

#### **Parameters**

• **config**: Object • Properties `ts gameId: string; partner: string; onSignInSucess: (userProfile: UserProfile) => void; onSignMessage: (data: Object) => void; onSignInFail: (data: Object) => void;`

#### **Returns**

`Promise`<`void`>

**Example**

```jsx
RamperTelegram.initializeAsync({
    gameId: 'sdk_sample',
    partner: 'coin98',
    appId: 'missing_app_id',
    onSignInFail: (ev) => {
        console.error('sign in fail');
    },
    onSignInSucess: (uProfile) => {
        console.log('sign-in-success', uProfile);
    },
    onSignMessage: (msg) => {
        console.log('sign-message-success', msg);
    }
})
```

***

### showIframe

#### **Description**

Open iframe with target url

> **showIframe**(`url`, `afterLoadUrlCallback`): `void`

#### **Parameters**

• **url**: `string` set a callback to be fired on web loaded • **afterLoadUrlCallback**: `any`

#### **Returns**

`void`

#### **Example**

```jsx
RamperTelegram.showIframe(
    'example.com',
    ()=>{
        console.log('load url success')
    }
)
```

***

### signMessage

#### **Description**

#### Sign a string data.

> **signMessage**(`msg`): `void`

#### **Parameters**

• **msg**: `string`

#### **Returns**

`void`

#### **Example**

```jsx
RamperTelegram.signMessage('Hello World');
```

***

### signOut

#### **Description**

Sign out the user.

> **signOut**(`callback`): `void`

#### **Parameters**

Set a callback to be fired when a logout is triggered. • **callback**: `Function`

```jsx
RamperTelegram.signOut(function() {
  console.log('logout event was triggered!');
})
```

#### **Returns**

`void`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ramper.xyz/embedded-wallet-sdk/quickstart/for-telegram-mini-apps/implement-ramper-telegram-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
