debug n fix
This commit is contained in:
@@ -57,6 +57,13 @@ class QuixoticApp {
|
||||
this.tg.ready();
|
||||
this.tg.expand();
|
||||
this.tg.MainButton.hide();
|
||||
|
||||
// Debug Telegram user info
|
||||
console.log('🔧 Telegram WebApp initialized');
|
||||
console.log('👤 User ID:', this.tg.initDataUnsafe?.user?.id);
|
||||
console.log('📋 Full initData:', this.tg.initDataUnsafe);
|
||||
} else {
|
||||
console.log('❌ Telegram WebApp not available');
|
||||
}
|
||||
|
||||
this.searchInput = document.getElementById('searchInput') as HTMLInputElement;
|
||||
@@ -248,40 +255,59 @@ class QuixoticApp {
|
||||
console.log('🔧 About to send to Telegram, tg available:', !!this.tg);
|
||||
|
||||
if (this.tg) {
|
||||
// Send to Telegram chat
|
||||
// Try WebApp method first (might not work)
|
||||
const payload = {
|
||||
action: 'send_audio',
|
||||
audioUrl: data.audioUrl,
|
||||
title: title
|
||||
};
|
||||
console.log('📤 Sending data to Telegram via sendData:', payload);
|
||||
console.log('📤 Attempting WebApp sendData first:', payload);
|
||||
|
||||
try {
|
||||
this.tg.sendData(JSON.stringify(payload));
|
||||
console.log('✅ Data sent via Telegram.sendData');
|
||||
console.log('✅ WebApp sendData called');
|
||||
this.showMessage('✓ MP3 готов! Отправляем в чат...', 'success');
|
||||
|
||||
// Fallback: also try to send via HTTP request to our server
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
console.log('🔄 Sending fallback notification to server...');
|
||||
await fetch('/api/telegram-notify', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
userId: this.tg?.initDataUnsafe?.user?.id,
|
||||
audioUrl: data.audioUrl,
|
||||
title: title
|
||||
})
|
||||
});
|
||||
} catch (fallbackError) {
|
||||
console.log('Fallback notification failed (not critical):', fallbackError);
|
||||
}
|
||||
}, 2000); // Wait 2 seconds before fallback
|
||||
|
||||
} catch (sendError) {
|
||||
console.error('❌ Failed to send via Telegram.sendData:', sendError);
|
||||
this.showMessage('❌ Ошибка отправки в Telegram', 'error');
|
||||
console.error('❌ WebApp sendData failed:', sendError);
|
||||
}
|
||||
|
||||
// Always use direct API as primary method now
|
||||
const userId = this.tg?.initDataUnsafe?.user?.id;
|
||||
console.log('👤 Current user ID for sending:', userId);
|
||||
|
||||
if (!userId) {
|
||||
console.error('❌ No user ID available from Telegram WebApp');
|
||||
this.showMessage('❌ Ошибка: не удается определить пользователя', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('🔄 Sending via direct API...');
|
||||
const requestData = {
|
||||
userId: userId,
|
||||
audioUrl: data.audioUrl,
|
||||
title: title
|
||||
};
|
||||
console.log('📦 Request data:', requestData);
|
||||
|
||||
const directResponse = await fetch('/api/telegram-send', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(requestData)
|
||||
});
|
||||
|
||||
if (directResponse.ok) {
|
||||
const result = await directResponse.json();
|
||||
console.log('✅ Direct API success:', result);
|
||||
this.showMessage('✅ MP3 отправлен в чат!', 'success');
|
||||
} else {
|
||||
const error = await directResponse.json();
|
||||
console.error('❌ Direct API failed:', error);
|
||||
this.showMessage('❌ Ошибка отправки в Telegram', 'error');
|
||||
}
|
||||
} catch (directError) {
|
||||
console.error('❌ Direct API request failed:', directError);
|
||||
this.showMessage('❌ Ошибка соединения с ботом', 'error');
|
||||
}
|
||||
} else {
|
||||
// For testing in browser - download file
|
||||
|
||||
Reference in New Issue
Block a user