Migrating from @telegram-apps/bridge ​
This guide provides a summary of the migration process from @telegram-apps/bridge to @tma.js/bridge.
mockTelegramEnv ​
onEventoption now receives not a tuple, but an object with propertiesevent: stringandparams?: any. The actual typing depends on theeventproperty.
retrieveLaunchParams ​
- The function now has no way of returning a camel-cased version of launch parameters. Instead, it always returns them in form they were passed from Telegram. Nevertheless, you can import the
deepSnakeToCamelObjKeysfunction from the package in order to deeply camelize keys:
typescript
import { deepSnakeToCamelObjKeys, retrieveLaunchParams } from '@tma.js/bridge';
const lpCamelCased = deepSnakeToCamelObjKeys(retrieveLaunchParams());- Type
RetrieveLPResultwas renamed toRetrieveLaunchParamsResult; - Type
RetrieveLPResultCamelCasedwas removed.
on ​
- Listening to all events (using
on(*)) you will now receive not a tuple, but an object with propertiesevent: stringandpayload?: any. The actual typing depends on theeventproperty.
targetOrigin ​
- This signal became readonly, so the
targetOrigin.setmethod is inaccessible now. You should use thesetTargetOriginfunction instead:
typescript
import { setTargetOrigin } from '@tma.js/bridge';
setTargetOrigin('https://some-domain.com');debug ​
- This signal became readonly, so the
debug.setmethod is inaccessible now.
postMessageImplementation ​
- The signal was renamed to
postMessageImpl.
Errors ​
- The following functions were removed:
isMethodUnsupportedErrorisMethodMethodParameterUnsupportedErrorisLaunchParamsRetrieveErrorisInvalidLaunchParamsErrorisUnknownEnvErrorisInvokeCustomMethodError
Instead, you should use the errors' static is() method:
typescript
import { UnknownEnvError } from '@tma.js/bridge';
if (UnknownEnvError.is(someValue)) {
// someValue is instance of UnknownEnvError.
}InvokeCustomMethodErrorwas renamed toInvokeCustomMethodFailedError
