eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.12k stars 2.03k forks source link

How to add a string to file name when sending file? #378

Closed AliBahaari closed 4 years ago

AliBahaari commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? 3.10 - I think, Because Installed By PIP

  2. What OS are you using? GNU/Linux - Ubuntu 16.04

  3. What version of python are you using? 3

Hello, First thanks for your implementation ... I have a question, Is it possible to add a string to file name we send to user ? For example my file name is "Biology.pdf", So I want to add a channel name like " - @Test" to the end of it to be "Biology.pdf - @Test". I know I can add caption but I need this too.

Kylmakalle commented 7 years ago

It's not TeleBot issue https://docs.python.org/3/library/os.html#os.rename

AliBahaari commented 7 years ago

I know it is not, But It is very good if TeleBot that has many advantages have this ability too, Because some frameworks has this ability to not to use os.rename ... And It is not related to os.rename, Because I don't want to rename source file, In this option in other frameworks will add a text to the end of the file & send it to user but source file name is not changed.

Kylmakalle commented 7 years ago

Adding text to the end of file will mess up file extention

Are you sure that you'r talking not about Caption?

alfilesnet commented 7 years ago

you can use:

filename='Biology.pdf' extension=filename[-4:] string=' - @mychannel' filename=filename[0:-4]+string+extension

-> Biology - @mychannel.pdf

AliBahaari commented 7 years ago

@Kylmakalle I'm sure, Please check python-telegram-bot ...

AliBahaari commented 7 years ago

@alfilesnet Thanks, I will check it ...

Ratgor commented 4 years ago

I think the problem is in telegram bot api, by that reason filename 'document' was hardcoded see commit 151880f, line 688 in https://github.com/eternnoir/pyTelegramBotAPI/blob/master/telebot/__init__.py