diff --git a/tgram/tgbot.py b/tgram/tgbot.py index 98c25bd..7419b52 100644 --- a/tgram/tgbot.py +++ b/tgram/tgbot.py @@ -11,7 +11,7 @@ from .methods import TelegramBotMethods from .decorators import Decorators from .errors import APIException -from .utils import API_URL +from .utils import API_URL, get_file_name from .sync import wrap from concurrent.futures.thread import ThreadPoolExecutor @@ -155,7 +155,9 @@ async def _send_request(self, method: str, **kwargs) -> Any: ) else: value = str(value) - data.add_field(key, value) + data.add_field( + key, value, filename=get_file_name(value) if has_files else None + ) response = await session.request( "POST" if has_files else "GET", diff --git a/tgram/utils.py b/tgram/utils.py index 33bfeee..4d30ceb 100644 --- a/tgram/utils.py +++ b/tgram/utils.py @@ -1,7 +1,15 @@ from .handlers import Handlers +import os + API_URL = "https://api.telegram.org/" ALL_UPDATES = [ getattr(Handlers, i) for i in filter(lambda x: not x.startswith("_"), Handlers.__dict__) ] + + +def get_file_name(obj): + name = getattr(obj, "name", None) + if name and isinstance(name, str) and name[0] != "<" and name[-1] != ">": + return os.path.basename(name)