LiaDevelopers

SDK reference

Loading the Lia SDK, the Lia object's properties, how calls answer and fail, and an index of every method.

#Loading it

HTML
<script src="https://api.lialabs.org/sdk/lia-apps-v1.js"></script>

Load it from Lia, before your own scripts. It defines one global, window.Lia, once (loading it twice does nothing). It's plain JavaScript with no dependencies, and works with any framework or none. This page describes version 1.6.0.

In TypeScript, declare the global until there's a types package:

TypeScript
declare global {
  interface Window { Lia: any }
}
const Lia = window.Lia;

#How calls answer

  • Most methods return a promise. It resolves with the answer described for each method, or rejects with an Error that has a code (and a message in English for you, not for players).
  • Bad arguments reject too, with a code like bad_text, before anything reaches Lia. A few methods that don't return promises (Lia.inviteLink, Lia.on, the buttons' setters) throw instead.
  • Outside the Lia app, every call rejects with not_in_lia. Lia.available tells you up front.
  • Lia must answer within 20 seconds, or the call rejects with timeout. Calls that wait on the person (the pay sheet, ads, dialogs, the friend picker, the notifications ask, the scanner, the clipboard, Face ID, share) wait as long as it takes.
JavaScript
try {
  const result = await Lia.pay("extra-lives");
} catch (error) {
  switch (error.code) {
    case "cancelled": return; // they changed their mind
    case "not_in_lia": return showOpenInLia();
    default: Lia.toast("Something went wrong", { tone: "error" });
  }
}

Every code is listed in Error codes.

#Properties

Read these after Lia.init() has answered; before that they hold defaults. Most are kept current by Lia's events.

PropertyTypeWhat it is
Lia.versionstringThe SDK's version, for example "1.6.0".
Lia.availablebooleantrue inside the Lia app. Known as soon as the script loads.
Lia.platformstring"ios" or "android" ("unknown" before init()).
Lia.languagestringThe person's language in Lia: en, es, pt, fr, tr, ru, vi, id, fil, sw, hi, ar or zh. See Language.
Lia.rtlbooleanWhether that language reads right to left (Arabic).
Lia.colorSchemestring"light" or "dark".
Lia.themeobjectLia's colours, as bg_color, text_color and the rest. See Lia's theme.
Lia.viewportobject{ height, expanded }: your page's height in px, and whether a sheet is at full height.
Lia.safeAreaobject{ top, bottom, left, right }: the phone's safe area in px.
Lia.contentSafeAreaobject{ top, bottom, left, right }: also clear of Lia's floating controls in fullscreen.
Lia.displaystringHow your app opened: "sheet", "full" or "fullscreen".
Lia.isFullscreenbooleanWhether it's edge to edge right now.
Lia.startParamstring or nullWhat it was opened with: an invite's, a link's or a notification's startParam. null when opened from the Apps Center.
Lia.soundOnbooleanWhether the person wants your app's sounds.
Lia.notificationsAllowedbooleanWhether this person lets your app send them notifications.

#Lia.isVersionAtLeast(version)

Whether the SDK is at least this version, for features added later.

JavaScript
if (Lia.isVersionAtLeast("1.3")) Lia.inviteFriend({ startParam: room });
ParameterType
versionstringLike "1.3" or "1.3.0".

Returns a boolean (not a promise).

#CSS variables

After init(), the SDK sets these on your page's root and keeps them current: Lia's theme (--lia-bg-color and the rest), --lia-color-scheme, --lia-viewport-height, --lia-safe-area-inset-* and --lia-content-safe-area-inset-*. See Look and feel.

#Every method

AreaMethods
Startup and lifecycleLia.init, Lia.ready, Lia.session, Lia.close, Lia.on, Lia.off, Lia.onPause, Lia.onResume
Payments and adsLia.pay, Lia.charges, Lia.onCharge, Lia.showAd, Lia.showRewardedAd, Lia.showRewardedInterstitialAd, Lia.showInterstitialAd, Lia.onAd
Notifications and invitesLia.requestNotifications, Lia.inviteFriend, Lia.inviteLink, Lia.share
DialogsLia.confirm, Lia.showPopup, Lia.showAlert, Lia.showConfirm, Lia.toast
Layout, colours and buttonsLia.expand, Lia.requestFullscreen, Lia.exitFullscreen, Lia.enableExpand, Lia.disableExpand, Lia.enableVerticalSwipes, Lia.disableVerticalSwipes, Lia.enableClosingConfirmation, Lia.disableClosingConfirmation, Lia.setBackgroundColor, Lia.setHeaderColor, Lia.mainButton, Lia.secondaryButton, Lia.backButton, Lia.settingsButton
DeviceLia.haptic, Lia.scanQr, Lia.copyText, Lia.readClipboard, Lia.openLink, Lia.openLiaLink, Lia.biometric, Lia.accelerometer, Lia.gyroscope, Lia.deviceOrientation
Scores and storageLia.submitScore, Lia.leaderboard, Lia.cloudStorage, Lia.deviceStorage, Lia.secureStorage

#Coming from Telegram

Lia's SDK follows Telegram's Mini Apps where it fits, so most ideas carry over:

TelegramLia
Telegram.WebApp.initDataLia.init() answers with a session token your server verifies with POST /session/verify.
themeParams, --tg-theme-*Lia.theme, --lia-* (same names)
MainButton, SecondaryButton, BackButton, SettingsButtonLia.mainButton, Lia.secondaryButton, Lia.backButton, Lia.settingsButton
HapticFeedbackLia.haptic(kind)
CloudStorage, DeviceStorage, SecureStorageLia.cloudStorage, Lia.deviceStorage, Lia.secureStorage (promises, not callbacks)
showPopup, showAlert, showConfirmThe same, as promises
openInvoice and StarsLia.pay(productId), paid in $LIA
start_paramLia.startParam

Type to search every page, method and endpoint.