From 816b0ec6729aee042764af4b612fa8a826fcbc20 Mon Sep 17 00:00:00 2001 From: Andrey Kondratev <81143241+cockroach-eater@users.noreply.github.com> Date: Fri, 29 Aug 2025 14:37:07 +0500 Subject: [PATCH] logs --- .../memories/song_selection_issue_analysis.md | 34 +++++++++++++++++++ public/script.ts | 6 ++-- src/bot.ts | 10 +++++- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 .serena/memories/song_selection_issue_analysis.md diff --git a/.serena/memories/song_selection_issue_analysis.md b/.serena/memories/song_selection_issue_analysis.md new file mode 100644 index 0000000..74ef2a3 --- /dev/null +++ b/.serena/memories/song_selection_issue_analysis.md @@ -0,0 +1,34 @@ +# Song Selection Issue Analysis + +## Problem +- Production: Song selection says it will send to chat but doesn't actually send +- /start command works fine +- No errors in logs + +## Code Flow Analysis + +### Working /start Command (src/bot.ts:66-95) +1. User sends /start command +2. Bot receives via `this.bot.onText(/\/start/)` +3. Direct bot.sendMessage() call works + +### Broken Song Selection Flow +1. User selects song in Web App (public/script.ts:248) +2. Web App calls `this.tg.sendData()` with JSON payload +3. Should trigger `web_app_data` event in bot (src/bot.ts:159) +4. Bot should call `sendAudioFile()` method (src/bot.ts:224) + +## Key Differences +- /start: Direct Telegram command → immediate bot response +- Song selection: Web App → sendData() → web_app_data event → bot response + +## Potential Issues +1. `this.tg.sendData()` might not be working in production environment +2. `web_app_data` event handler might not be triggered +3. Web App URL environment variable mismatch +4. Telegram Web App integration issues in production + +## Next Steps +- Check production environment variables (WEB_APP_URL, TELEGRAM_BOT_TOKEN) +- Add logging to web_app_data handler +- Verify Telegram Web App configuration \ No newline at end of file diff --git a/public/script.ts b/public/script.ts index ed2dea7..5703b14 100644 --- a/public/script.ts +++ b/public/script.ts @@ -245,11 +245,13 @@ class QuixoticApp { if (this.tg) { // Send to Telegram chat - this.tg.sendData(JSON.stringify({ + const payload = { action: 'send_audio', audioUrl: data.audioUrl, title: title - })); + }; + console.log('📤 Sending data to Telegram:', payload); + this.tg.sendData(JSON.stringify(payload)); this.showMessage('✓ MP3 готов! Отправляем в чат...', 'success'); } else { // For testing in browser - download file diff --git a/src/bot.ts b/src/bot.ts index 06163a1..cc1ab14 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -157,15 +157,23 @@ export class QuixoticBot { // Handle web app data this.bot.on('web_app_data', async (msg: Message) => { + console.log('🔍 Web app data received:', msg.web_app?.data); const chatId = msg.chat.id; - if (!msg.web_app?.data) return; + if (!msg.web_app?.data) { + console.log('❌ No web app data found'); + return; + } const data: WebAppData = JSON.parse(msg.web_app.data); + console.log('📝 Parsed data:', data); try { if (data.action === 'send_audio') { + console.log('🎵 Sending audio file:', data.title); await this.sendAudioFile(chatId, data.audioUrl, data.title); + } else { + console.log('⚠️ Unknown action:', data.action); } } catch (error) { console.error('Web app data error:', error);