Open xffc opened 11 months ago
Here the problem is that the sendDocument accepts only "A file path, Stream or Buffer" while you are passing the contents of the file using fs.readFileSync, which reads the file and returns its content as a string and the sendDocument interpret it as a path. To pass the ".log" file you should use "fs.createReadStream("path_to_the_log_file");" or the directly the path of the file ".sendDocument(chatId, ${__dirname}/path_to_the_log_file
)". There is still a problem using the Buffer because the fileType don't support the ".log" extention. For this reason you should enable manually the NTBA_FIX_350 inside env file as "NTBA_FIX_350=1". This would enable the library to auto-detect the file extension from the provided filename. So in your case you should be:
bot.sendDocument(chatId, fs.readFileSync(${name}.log
), {caption: "logs"}, { filename: ${name}.log
});
In this solution remember to specify the "filename" otherwise remove NTBA_FIX_350 from your env file.
let name = "tester";
await bot.sendDocument(chatId, fs.readFileSync(${name}.log
), {caption: "logs"});
Write await if you want to wait and remove encoding option "utf-8" from readFileSync then you good to go 🙌
I have read:
I am using the latest version of the library.
Expected Behavior
Send tester.log file.
Actual Behavior
It gives me error Unhandled rejection Error: ETELEGRAM: 400 Bad Request: invalid file HTTP URL specified: Wrong port number specified in the URL
Example