Migrating from @telegram-apps/sdk ​
This guide provides a summary of the migration process from @telegram-apps/sdk to @tma.js/sdk.
Before reading this document, it is recommended to first learn more about migration process related to @tma.js/bridge as you probably used some functionality from it.
Loggers ​
The bridgeLogger variable and BridgeLogger type have been removed. You should now use logger and Logger if needed.
Component-related Functions and Variables Removed ​
@tma.js/sdk has moved away from this approach as it was quite difficult to support and didn't provide significant benefits. Previously used component-related functions and variables such as showBackButton, hideBackButton, isBackButtonVisible, and others should now be replaced with their component counterparts.
So, having this code:
import {
showBackButton,
hideBackButton,
isBackButtonVisible,
} from '@telegram-apps/sdk';
showBackButton();
isBackButtonVisible(); // true
hideBackButton();
isBackButtonVisible(); // falseYou should update it to this one:
import { backButton } from '@tma.js/sdk';
backButton.show();
backButton.isVisible(); // true
backButton.hide();
backButton.isVisible(); // falseErrors ​
We have removed functions responsible for determining if a value is a specific error. Previously, you could use them like this:
import { isNotAvailableError } from '@telegram-apps/sdk';
if (isNotAvailableError(value)) {
// value is NotAvailableError.
}Now, you can achieve the same functionality with this code:
import { NotAvailableError } from '@tma.js/sdk';
if (NotAvailableError.is(value)) {
// value is NotAvailableError.
}.ifAvailable() Now Returns Object ​
Previously, functions' ifAvailable method returned a tuple: [ok: true, value: something] | [ok: false]. We've updated it to return an object with ok and data fields for better clarity.
Here is an example:
import { invoice } from '@tma.js/sdk';
console.log(invoice.openSlug.ifAvailable('abc'));
// Output:
// { ok: true, data: Promise<...> }Biometry ​
requestBiometryhas been removed. You can use the SDK'srequestmethod to achieve the same functionality.isMounting,mountError, andmountPromisehave been removed.
Invoice ​
openErrorandopenPromisehave been removed.- The
openmethod was replaced with separateopenUrlandopenSlugmethods.
LocationManager ​
requestLocationmay now returnnullif there is no access to the location.
MainButton ​
- The
backgroundColorsignal name was shortened tobgColor.
ThemeParams ​
- Some signal names were shortened:
backgroundColor→bgColorheaderBackgroundColor→headerBgColorsecondaryBackgroundColor→secondaryBgColorsectionBackgroundColor→sectionBgColor
mountSyncwas removed.mountis now synchronous.
init ​
The function options were updated. There is no longer a need to pass a complete set of launch parameters. Here is the list of all options:
interface InitOptions {
/**
* True if SDK should accept styles sent from the Telegram
* application.
* @default true
*/
acceptCustomStyles?: boolean;
/**
* True if the application is launched in inline mode.
* @default Will be calculated based on the launch parameters'
* tgWebAppBotInline field.
*/
isInlineMode?: boolean;
/**
* A custom `postEvent` function to use across the package.
* @default tma.js/bridge's postEventFp function will be used.
*/
postEvent?: PostEventFpFn;
/**
* Mini application theme parameters.
* @default Will be calculated based on the launch parameters'
* tgWebAppThemeParams field.
*/
themeParams?: ThemeParams;
/**
* Telegram Mini Apps version supported by the Telegram
* client.
* @default Will be calculated based on the launch parameters'
* tgWebAppVersion field.
*/
version?: Version;
}CloudStorage ​
- The
getItemmethod no longer accepts a list of keys. - The
getItemsmethod is now used to get a list of keys.
Popup ​
- The
showmethod now returnsstring | undefinedinstead ofstring | null.
QrScanner ​
- The
openmethod was divided intoopenandcapture. Theopenmethod allows capturing multiple QR-s, when thecapturemethod is responsible for capturing a single QR. Learn more
Viewport ​
- Static methods
requestContentSafeAreaInsets,requestViewport, andrequestSafeAreaInsetshave been removed. You can use the SDK'srequestfunction to achieve the same functionality.
InitData ​
- Signals such as
chat,receiver, andusernow return objects as they are presented in the init data—with snake_case keys instead of camelCase.
MiniApp ​
- Signals and methods renamed:
backgroundColor→bgColorbackgroundColorRGB→bgColorRgbbottomBarColor→bottomBarBgColorbottomBarColorRGB→bottomBarBgColorRgbheaderColorRGB→headerColorRgbsetBackgroundColor→setBgColorsetBottomColor→setBottomBarColor
.supports() ​
The functions' supports field is now a function that accepts an option name, rather than an object. You should rewrite this code:
import { miniApp } from '@telegram-apps/sdk';
if (miniApp.setHeaderColor.supports.rgb()) {
miniApp.setHeaderColor('#aabbcc');
}Into this one:
import { miniApp } from '@tma.js/sdk';
if (miniApp.setHeaderColor.supports('rgb')) {
miniApp.setHeaderColor('#aabbcc');
}Utilities ​
- Functions
onAddToHomeScreenFailed,offAddToHomeScreenFailed,onAddedToHomeScreenandoffAddedToHomeScreenwere removed. Use SDK'sonandofffunctions instead.
