telebot icon indicating copy to clipboard operation
telebot copied to clipboard

fileName when sendDocument

Open jesusgn90 opened this issue 7 years ago • 1 comments

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'

jesusgn90 avatar Oct 07 '17 11:10 jesusgn90

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.

nadimz avatar Oct 26 '17 19:10 nadimz