Skip to content

Commit

Permalink
fix send_document with only document title
Browse files Browse the repository at this point in the history
  • Loading branch information
z44d committed Jul 6, 2024
1 parent 6b78a20 commit 09c263a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tgram/tgbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,30 @@ async def _send_request(self, method: str, **kwargs) -> Any:
logger.info("Sending request using the method: %s", method)
session = await self._get_session()
data = aiohttp.FormData(quote_fields=False)
has_files = False
has_files, file = False, None

for key, value in kwargs.items():
if value is None or key == "timeout":
continue
if isinstance(value, Path):
has_files = True
with open(value, "rb") as f:
value = f.read()
elif isinstance(value, io.BytesIO):
has_files = True
value = value.read()
elif isinstance(value, bytes):
value = f
file = f.read()
elif isinstance(value, (io.BytesIO, io.BufferedReader, bytes)):
has_files = True
value = value
file = value if isinstance(value, bytes) else value.read()
elif isinstance(value, (tgram.types.Type_, list)):
value = json.dumps(
value, ensure_ascii=False, default=tgram.types.Type_.default
)
else:
value = str(value)
data.add_field(
key, value, filename=get_file_name(value) if has_files else None
key,
file if has_files else value,
filename=get_file_name(value) if has_files else None,
)

response = await session.request(
Expand Down

0 comments on commit 09c263a

Please sign in to comment.