Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendDocument issue #1149

Open
xffc opened this issue Oct 31, 2023 · 2 comments
Open

sendDocument issue #1149

xffc opened this issue Oct 31, 2023 · 2 comments

Comments

@xffc
Copy link

xffc commented Oct 31, 2023

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

let name = "tester";
bot.sendDocument(chatId, fs.readFileSync(`${name}.log`, "utf-8"), {caption: "logs"});
@klaus-10
Copy link

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.

@ronak2898
Copy link

image

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 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants