mullwar / telebot

The easy way to write Telegram bots in Node.js
https://www.npmjs.com/package/telebot
MIT License
1.48k stars 269 forks source link

fileName when sendDocument #92

Open jesusgn90 opened 7 years ago

jesusgn90 commented 7 years ago

I have a trouble with the method bot.sendDocument, it don't put the filename as expected.

    bot.sendDocument(msg.chat.id,'someurl',{
           caption:'foo', 
           fileName:'MYNAME'}
    );

I receive the pdf on the chat, that's fine but the file name is '.pdf' not 'MYNAME.pdf'

nadimz commented 6 years ago

As far as the Telegram Bot API, there is no way to pass a custom file name when passing its URL sendDocument.

After a quick look at Telebot code, seems that the filename option is used when sending a file using multipart/form-data, which happens if you pass a Stream, Buffer, a local file path or set serverDownload option when calling bot.sendDocument.

You can try this just to see if what I just said makes sense. Note however that with the below code, it's your server that downloads the file, not Telegram servers:

bot.sendDocument(msg.chat.id,'someurl',{
           caption:'foo', 
           fileName:'MYNAME',
           serverDownload:true}
    );

However, not sure why you are seeing .pdf as the file name and not something else.

Hope this helps.