debug n fix

This commit is contained in:
Andrey Kondratev
2025-08-29 17:47:58 +05:00
parent 89a7f4ab11
commit a08fd5b495
3 changed files with 72 additions and 49 deletions

View File

@@ -189,40 +189,36 @@ app.post('/api/convert', async (req: Request, res: Response) => {
}
});
// Fallback API for Telegram notifications when WebApp data doesn't work
app.post('/api/telegram-notify', async (req: Request, res: Response) => {
// Direct Telegram API for sending audio when WebApp fails
app.post('/api/telegram-send', async (req: Request, res: Response) => {
try {
const { userId, audioUrl, title }: { userId?: string; audioUrl?: string; title?: string } = req.body;
console.log('📡 Fallback Telegram notification received:', { userId, audioUrl, title });
console.log('🔄 Direct Telegram send request:', { userId, audioUrl, title });
if (!userId || !audioUrl || !title) {
return res.status(400).json({ error: 'Missing required fields' });
}
// Find bot instance and send the audio
// Note: We need to get the bot instance from somewhere
// For now, we'll store a reference to it
if ((global as any).quixoticBot) {
console.log('🤖 Using global bot instance for fallback notification');
const bot = (global as any).quixoticBot;
// Get user's chat ID from database
const user = await db.getUserByTelegramId(userId);
if (user) {
// We need to get chat ID - for now use user's telegram ID as chat ID
await bot.sendAudioFile(parseInt(userId), audioUrl, title);
console.log('✅ Fallback notification sent successfully');
} else {
console.log('❌ User not found for fallback notification');
}
} else {
console.log('❌ No bot instance available for fallback');
// Get bot instance
const botInstance = (global as any).quixoticBot;
if (!botInstance) {
console.log('❌ No bot instance available');
return res.status(500).json({ error: 'Bot not available' });
}
res.json({ success: true });
} catch (error) {
console.error('Fallback notification error:', error);
res.status(500).json({ error: 'Fallback failed' });
console.log('🤖 Using bot instance for direct send');
// Use userId as chatId for private chats (this is how Telegram works)
const chatId = parseInt(userId);
console.log(`📤 Sending audio to chat ${chatId}`);
await botInstance.sendAudioFile(chatId, audioUrl, title);
console.log('✅ Audio sent successfully via direct API');
res.json({ success: true, message: 'Audio sent successfully' });
} catch (error: any) {
console.error('❌ Direct send error:', error.message);
res.status(500).json({ error: error.message });
}
});