yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.12k stars 1.49k forks source link

FileOptions filename and contentType is can't work well #1202

Closed azickri closed 3 weeks ago

azickri commented 3 weeks ago

Bug Report

I have read:

I am using the latest version of the library.

Expected Behavior

I'm trying to send a Document with a custom file name

Actual Behavior

What happens is that the file name in Telegram becomes the default file URL to be "12345678990.pdf", it should be "file-name.pdf"

Steps to reproduce the Behavior

I have used the function for .sendDocument using FileOptions in this way

const url = 'https://media.com/12345678990.pdf'
const fileOption = {
 filename: "file-name.pdf",
 contentType: "application/pdf",
};

.sendDocument(chatId, url, options, fileOption);
Sp3rick commented 3 weeks ago

Seems that similiar behaivor is on telegraf by sending from file_id https://github.com/telegraf/telegraf/issues/1062#issuecomment-659553766

Probably filename can be given only when uploading (from Buffer or Stream), so you should try to download the file and then upload it to telegram with your fileOptions

azickri commented 3 weeks ago

Thanks, i will try it.