feat: add telegram mini app dashboard
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
||||
<link rel="stylesheet" href="@Assets["app.css"]" />
|
||||
<link rel="stylesheet" href="@Assets["GmRelay.Web.styles.css"]" />
|
||||
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
||||
<ImportMap />
|
||||
<link rel="icon" type="image/png" href="favicon.png" />
|
||||
<HeadOutlet @rendermode="InteractiveServer" />
|
||||
@@ -23,6 +24,14 @@
|
||||
<ReconnectModal />
|
||||
<script src="@Assets["_framework/blazor.web.js"]"></script>
|
||||
<script>
|
||||
(function () {
|
||||
if (window.Telegram && window.Telegram.WebApp && window.Telegram.WebApp.initData) {
|
||||
var webApp = window.Telegram.WebApp;
|
||||
document.body.classList.add('telegram-mini-app');
|
||||
webApp.ready();
|
||||
}
|
||||
})();
|
||||
|
||||
window.loadTelegramWidget = function (botUsername, authUrl) {
|
||||
var container = document.getElementById('telegram-login-container');
|
||||
if (!container) return;
|
||||
@@ -36,6 +45,32 @@
|
||||
script.setAttribute('data-request-access', 'write');
|
||||
container.appendChild(script);
|
||||
};
|
||||
|
||||
window.authenticateTelegramMiniApp = async function (authUrl, redirectUrl) {
|
||||
if (!window.Telegram || !window.Telegram.WebApp || !window.Telegram.WebApp.initData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var webApp = window.Telegram.WebApp;
|
||||
document.body.classList.add('telegram-mini-app');
|
||||
webApp.ready();
|
||||
webApp.expand();
|
||||
|
||||
var response = await fetch(authUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({ initData: webApp.initData })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var payload = await response.json();
|
||||
window.location.href = payload.redirectUrl || redirectUrl || '/';
|
||||
return true;
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user