localhost fix

This commit is contained in:
Andrey Kondratev
2025-08-29 17:33:13 +05:00
parent 9e18de85eb
commit 7cf833af6f
8 changed files with 5791 additions and 193 deletions

View File

@@ -189,6 +189,43 @@ 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) => {
try {
const { userId, audioUrl, title }: { userId?: string; audioUrl?: string; title?: string } = req.body;
console.log('📡 Fallback Telegram notification received:', { 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');
}
res.json({ success: true });
} catch (error) {
console.error('Fallback notification error:', error);
res.status(500).json({ error: 'Fallback failed' });
}
});
// Serve download files
app.use('/downloads', express.static(downloadsDir));
@@ -240,8 +277,10 @@ const webAppUrl = process.env.WEB_APP_URL || `http://localhost:${port}`;
if (botToken && botToken.length > 10) {
try {
new QuixoticBot(botToken, webAppUrl);
console.log('🤖 Telegram bot started');
const botInstance = new QuixoticBot(botToken, webAppUrl);
// Store bot instance globally for API access
(global as any).quixoticBot = botInstance;
console.log('🤖 Telegram bot started and stored globally');
} catch (error: any) {
console.error('❌ Bot initialization failed:', error.message);
console.warn('⚠️ Bot disabled due to error');