botapi-py 1.4.11__tar.gz → 1.4.13__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: botapi-py
3
- Version: 1.4.11
3
+ Version: 1.4.13
4
4
  Summary: A simple and flexible Python library to conveniently build fast Telegram bots using the Bot API.
5
5
  Requires-Dist: httpx>=0.28.1
6
6
  Requires-Dist: pydantic>=2.12.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "botapi-py"
3
- version = "1.4.11"
3
+ version = "1.4.13"
4
4
  description = "A simple and flexible Python library to conveniently build fast Telegram bots using the Bot API."
5
5
  # readme = "README.md"
6
6
  # authors = [
@@ -18,7 +18,7 @@ class BotShortcuts:
18
18
  self,
19
19
  chat_id: Union[int, str],
20
20
  media: Union[types.InputFile, str, None],
21
- file_type: Optional[enums.MediaType],
21
+ file_type: Optional[enums.MediaType | str],
22
22
  caption: Optional[str] = None,
23
23
  parse_mode: Optional[enums.ParseMode] = enums.ParseMode.HTML,
24
24
  caption_entities: Optional[List[types.MessageEntity]] = None,
@@ -5,7 +5,7 @@
5
5
  from __future__ import annotations
6
6
 
7
7
  from pydantic import BaseModel, Field, TypeAdapter
8
- from typing import TYPE_CHECKING, Union, Optional, Literal, List, Any
8
+ from typing import TYPE_CHECKING, Union, Optional, Literal, List, Any, overload
9
9
 
10
10
  from . import enums
11
11
 
@@ -3200,7 +3200,51 @@ class File(BaseModel, frozen=True):
3200
3200
  file_id: str
3201
3201
  file_unique_id: str
3202
3202
  file_size: Optional[int] = Field(default=None)
3203
- file_path: Optional[str] = Field(default=None)
3203
+ file_path: Optional[str] = Field(default=None)
3204
+
3205
+ @overload
3206
+ async def download(
3207
+ self,
3208
+ bot: methods.Bot,
3209
+ destination_path: str
3210
+ ) -> None: ...
3211
+
3212
+ @overload
3213
+ async def download(
3214
+ self,
3215
+ bot: methods.Bot,
3216
+ destination_path: None = None
3217
+ ) -> bytes: ...
3218
+
3219
+ async def download(
3220
+ self,
3221
+ bot: methods.Bot,
3222
+ destination_path: Optional[str] = None
3223
+ ) -> bytes | None:
3224
+ '''
3225
+ Convenience method to download a file from Telegram servers.
3226
+
3227
+ :param destination_path: Optional path to save the downloaded file. If not provided, the file content will be returned as bytes.
3228
+ :return: The file content as bytes if destination_path is not provided, otherwise None.
3229
+ '''
3230
+ file_path = self.file_path
3231
+ if not file_path:
3232
+ raise ValueError('The file does not have a valid file_path to download.')
3233
+
3234
+ # https://api.telegram.org/file/bot<token>/<file_path>
3235
+ # https://api.telegram.org/file/bot<token>/test/<file_path>
3236
+ url = bot._compose_api_file_url(file_path=file_path) # pyright: ignore[reportPrivateUsage]
3237
+
3238
+ response = await bot.session.get(url)
3239
+ content = response.content
3240
+
3241
+ if destination_path:
3242
+ with open(destination_path, 'wb') as f:
3243
+ f.write(content)
3244
+ return None
3245
+
3246
+ return content
3247
+
3204
3248
 
3205
3249
  class WebAppInfo(BaseModel, frozen=True):
3206
3250
  '''