const fs = require('fs'); const { listDataFiles } = require('../commands/backuplogs'); module.exports = { prefix: 'bkdl:', handler: async (bot, query) => { const chatId = query.message.chat.id; const parts = query.data.split(':'); const fileIdx = parseInt(parts[1]); const userMessageId = parts[2]; const files = await listDataFiles(); const file = files[fileIdx]; if (!file || !fs.existsSync(file.path)) { bot.answerCallbackQuery(query.id, { text: 'File non trovato', show_alert: true }); return; } try { await bot.sendDocument(chatId, file.path, { caption: `\`${file.name}\``, parse_mode: 'Markdown' }); } catch (e) { bot.answerCallbackQuery(query.id, { text: 'Errore invio file', show_alert: true }); return; } bot.answerCallbackQuery(query.id, { text: 'File inviato' }); } };