mirror of
https://github.com/AmanIbrash-brsh/finance-website.git
synced 2026-11-09 09:35:10 +00:00
добавил кнопки в тг бота
This commit is contained in:
+47
-50
@@ -1,50 +1,47 @@
|
||||
// Telegram WebApp SDK Wrapper
|
||||
|
||||
export const tg = window.Telegram?.WebApp || null;
|
||||
|
||||
export function initTelegram() {
|
||||
if (tg) {
|
||||
tg.ready();
|
||||
tg.expand();
|
||||
console.log('Telegram WebApp SDK initialized');
|
||||
} else {
|
||||
console.warn('Telegram WebApp SDK not found. Running in browser mode.');
|
||||
}
|
||||
}
|
||||
|
||||
export function getTelegramUser() {
|
||||
return tg?.initDataUnsafe?.user || null;
|
||||
}
|
||||
|
||||
export function getAuthHeaders() {
|
||||
const headers = {};
|
||||
|
||||
if (tg && tg.initData) {
|
||||
headers['X-Telegram-Init-Data'] = tg.initData;
|
||||
}
|
||||
|
||||
// Also check if we have a token stored in localStorage (for desktop browser access)
|
||||
const token = localStorage.getItem('finance_auth_token');
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
export function saveTokenFromUrl() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const token = params.get('token');
|
||||
if (token) {
|
||||
localStorage.setItem('finance_auth_token', token);
|
||||
// Clean up url
|
||||
window.history.replaceState({}, document.title, window.location.pathname);
|
||||
return token;
|
||||
}
|
||||
return localStorage.getItem('finance_auth_token');
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
localStorage.removeItem('finance_auth_token');
|
||||
window.location.reload();
|
||||
}
|
||||
{
|
||||
"// Telegram WebApp SDK Wrapper": "",
|
||||
"export const tg = window.Telegram?.WebApp || null;": "",
|
||||
"export function initTelegram() {": "",
|
||||
" if (tg) {": "",
|
||||
" tg.ready();": "",
|
||||
" tg.expand();": "",
|
||||
" console.log('Telegram WebApp SDK initialized');": "",
|
||||
" } else {": "",
|
||||
" console.warn('Telegram WebApp SDK not found. Running in browser mode.');": "",
|
||||
" }": "",
|
||||
"}": "",
|
||||
"export function getTelegramUser() {": "",
|
||||
" return tg?.initDataUnsafe?.user || null;": "",
|
||||
"}": "",
|
||||
"export function getAuthHeaders() {": "",
|
||||
" const headers = {};": "",
|
||||
" if (tg && tg.initData) {": "",
|
||||
" headers['X-Telegram-Init-Data'] = tg.initData;": "",
|
||||
" }": "",
|
||||
" // Also check if we have a token stored in localStorage (for desktop browser access)": "",
|
||||
" const token = localStorage.getItem('finance_auth_token');": "",
|
||||
" if (token) {": "",
|
||||
" headers['Authorization'] = `Bearer ${token}`;": "",
|
||||
" }": "",
|
||||
" return headers;": "",
|
||||
"}": "",
|
||||
"export function saveTokenFromUrl() {": "",
|
||||
" const params = new URLSearchParams(window.location.search);": "",
|
||||
" const token = params.get('token');": "",
|
||||
" if (token) {": "",
|
||||
" localStorage.setItem('finance_auth_token', token);": "",
|
||||
" // Clean up url": "",
|
||||
" window.history.replaceState({}, document.title, window.location.pathname);": "",
|
||||
" return token;": "",
|
||||
" }": "",
|
||||
" return localStorage.getItem('finance_auth_token');": "",
|
||||
"}": "",
|
||||
"export function logout() {": "",
|
||||
" localStorage.removeItem('finance_auth_token');": "",
|
||||
" window.location.reload();": "",
|
||||
"}": "",
|
||||
"/**\n * Generates markup for a Telegram message with an 'Add Expense' button.\n */": "",
|
||||
"export function getExpenseButtonMarkup() {": "",
|
||||
" return `\n <telegram>\n <message>\n Please enter the expense amount and description:\n <button data-action=\"add_expense\">Add Expense</button>\n </message>\n </telegram>\n`;": "",
|
||||
"}": ""
|
||||
}
|
||||
Reference in New Issue
Block a user