Spaces:
Runtime error
Runtime error
Update server.ts
Browse files58 unmodified lines5960616263646566676867697069717273743015 unmodified lines3090309130923091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173094311831193120312158 unmodified lines isServiceKey: !!process.env.SUPABASE_SERVICE_ROLE_KEY, appUrl: appUrl
// --- MODIFICATION HUGGING FACE (REMPLACE LA LIGNE 60) ---const bot = new Telegraf(botToken);
// On ne bloque pas le démarrage si Telegram n'est pas joignable immédiatementlet botUsername = 'Bot'; bot.telegram.getMe().then(me => { botUsername = me.username; console.log(`Bot username initialized: @${botUsername}`); console.log(`✅ Bot en ligne : @${botUsername}`);}).catch(err => { console.log('Note: getMe failed (normal au démarrage sur HF), le bot attend les Webhooks.'); console.log('⚠️ Note: Connexion initiale Telegram impossible (normal sur HF), attente du Webhook...');});
const bot = new Telegraf(botToken);3015 unmodified lines }});
app.listen(PORT, '0.0.0.0', () => { console.log(`Server running on http://localhost:${PORT}`);// --- CONFIGURATION WEBHOOK & DÉMARRAGE HUGGING FACE --- // 1. On crée le chemin secret pour Telegram const secretPath = `/telegraf/${botToken}`; // 2. On dit à ton serveur Express d'écouter Telegram app.use(bot.webhookCallback(secretPath));
// 3. On lance le serveur sur le port 7860 app.listen(7860, '0.0.0.0', async () => { console.log(`🚀 Serveur opérationnel sur le port 7860`);
// 4. On enregistre l'URL du bot auprès de Telegram if (appUrl) { try { await bot.telegram.deleteWebhook(); await bot.telegram.setWebhook(`${appUrl}${secretPath}`); console.log(`✅ Webhook configuré : ${appUrl}${secretPath}`); } catch (e: any) { console.error("❌ Erreur configuration Webhook:", e.message); } } else { console.error("⚠️ CUSTOM_APP_URL est vide dans tes Secrets HF !"); } });}} // Cette accolade ferme ta fonction "async function startServer() {"
// On lance enfin toute la machinestartServer();server.ts+30-5