Spaces:
Runtime error
Runtime error
Update server.ts
Browse files58 unmodified lines59606162636465666768697071723015 unmodified lines30883089309030913092309330943095309658 unmodified linesisServiceKey: !!process.env.SUPABASE_SERVICE_ROLE_KEY,appUrl: appUrlconst bot = new Telegraf(botToken);let botUsername = 'Bot';bot.telegram.getMe().then(me => {botUsername = me.username;console.log(`Bot username initialized: @${botUsername}`);}).catch(err => {console.log('Note: getMe failed (normal au démarrage sur HF), le bot attend les Webhooks.');});const bot = new Telegraf(botToken);3015 unmodified lines}});app.listen(PORT, '0.0.0.0', () => {console.log(`Server running on http://localhost:${PORT}`);});}startServer();58 unmodified lines596061626364656667686970717273743015 unmodified lines3090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312158 unmodified linesisServiceKey: !!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 en ligne : @${botUsername}`);}).catch(err => {console.log('⚠️ Note: Connexion initiale Telegram impossible (normal sur HF), attente du Webhook...');});const bot = new Telegraf(botToken);3015 unmodified lines}});// --- CONFIGURATION WEBHOOK & DÉMARRAGE HUGGING FACE ---// 1. On crée le chemin secret pour Telegramconst secretPath = `/telegraf/${botToken}`;// 2. On dit à ton serveur Express d'écouter Telegramapp.use(bot.webhookCallback(secretPath));// 3. On lance le serveur sur le port 7860app.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 Telegramif (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