cd361a1eaa
- POST /api/public/tg-webapp-auth: HMAC-verifies WebApp initData against the companion bot token (12h freshness, timing-safe), maps chat -> member via tg-links.json, mints a message session -> linked members land on /my/<id> with zero login - /app entry page (vendored telegram-web-app.js keeps CSP script-src 'self'); unlinked users get the one-time wallet-link instructions - tg-app.js on all pages: no-op in browsers; inside the webview lazy-loads the SDK, expands, themes header/background #071421, wires native BackButton - Bot menu button set programmatically to open /app; /start + help mention it - Synced chat.js canned answer + AI system prompt (Mini App facts) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
33 lines
1.4 KiB
JavaScript
33 lines
1.4 KiB
JavaScript
// In-Telegram polish for every site page. No-ops in a normal browser; inside
|
|
// the Mini App webview it lazy-loads the vendored Telegram SDK (CSP stays
|
|
// script-src 'self') and wires theme + BackButton so pages feel native.
|
|
(function () {
|
|
'use strict';
|
|
var inTg = false;
|
|
try { inTg = sessionStorage.getItem('rmcTg') === '1'; } catch (e) {}
|
|
if (!inTg && (window.TelegramWebviewProxy !== undefined || /tgWebApp(Data|Platform)/.test(location.hash))) inTg = true;
|
|
if (!inTg) return;
|
|
try { sessionStorage.setItem('rmcTg', '1'); } catch (e) {}
|
|
|
|
function boot() {
|
|
var tg = window.Telegram && window.Telegram.WebApp;
|
|
if (!tg || !tg.initData) return;
|
|
tg.ready();
|
|
try { tg.expand(); } catch (e) {}
|
|
try { tg.setHeaderColor('#071421'); tg.setBackgroundColor('#071421'); } catch (e) {}
|
|
// Back button mirrors webview history: /app enters via location.replace, so
|
|
// the landing dashboard has no history and stays clean; any deeper page
|
|
// (tools, training, another member view) gets a native back arrow.
|
|
var bb = tg.BackButton;
|
|
if (bb && history.length > 1) {
|
|
bb.show();
|
|
bb.onClick(function () { history.back(); });
|
|
}
|
|
}
|
|
if (window.Telegram && window.Telegram.WebApp) { boot(); return; }
|
|
var s = document.createElement('script');
|
|
s.src = '/telegram-web-app.js';
|
|
s.onload = boot;
|
|
document.head.appendChild(s);
|
|
})();
|