Mini Apps SDK (v8.0)
Build embedded web applications using window.Theaver.WebApp, reactive theme params, safe areas, CloudStorage, and X-Theaver-Init-Data verification.
Mini Apps v8.0 launches web applications inside native WebViews on mobile, desktop, and web clients via the native window.Theaver.WebApp JavaScript bridge. For drop-in compatibility aliases when adapting existing Mini Apps, see Migrating Bots & Mini Apps.
Attaching a Mini App to your bot
Configure a main app or named short_name mini app via @BotMother (or its Bot Studio) and open it from:
- A chat menu button (
setChatMenuButtonwithweb_app) - Inline keyboard buttons using
web_app: { url } - Direct deep link
https://theaver.app/u/<bot_username>?startapp=<param>
Client-side JS bridge (window.Theaver.WebApp)
const webApp = window.Theaver.WebApp;
webApp.ready();
webApp.expand();
// Adapt dynamically to the active Theaver theme
document.body.style.backgroundColor = webApp.themeParams.bg_color;
document.body.style.color = webApp.themeParams.text_color;
// Configure persistent main action button
webApp.MainButton.setText("Save Preferences");
webApp.MainButton.show();
webApp.MainButton.onClick(() => {
webApp.HapticFeedback.impactOccurred("medium");
webApp.sendData(JSON.stringify({ action: "saved" }));
});
Supported v8 features
- Lifecycle & insets:
ready(),expand(),close(),safeAreaInset,contentSafeAreaInset, eventssafe_area_changedandcontent_safe_area_changed. - Native buttons:
MainButton,SecondaryButton,BackButton,SettingsButton. - Storage & sensors:
CloudStorage(scoped key-value persistence),HapticFeedback,showScanQrPopup, andrequestWriteAccess.
Verifying initData on your backend
Never trust unverified initDataUnsafe fields. Send window.Theaver.WebApp.initData in the X-Theaver-Init-Data request header and validate its HMAC-SHA256 signature using key HMAC_SHA256("WebAppData", bot_token):
import hashlib
import hmac
from urllib.parse import parse_qsl
def verify_init_data(init_data: str, bot_token: str) -> dict[str, str] | None:
pairs = dict(parse_qsl(init_data, keep_blank_values=True))
received_hash = pairs.pop("hash", None)
if not received_hash:
return None
data_check_string = "\n".join(f"{k}={v}" for k, v in sorted(pairs.items()))
secret_key = hmac.new(b"WebAppData", bot_token.encode(), hashlib.sha256).digest()
expected_hash = hmac.new(secret_key, data_check_string.encode(), hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected_hash, received_hash):
return None
return pairs
Reject requests where int(time.time()) - int(pairs["auth_date"]) exceeds your replay window (for example, 3600 seconds).