botapi-py 1.4.11__tar.gz → 1.4.12__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.
- {botapi_py-1.4.11 → botapi_py-1.4.12}/PKG-INFO +1 -1
- {botapi_py-1.4.11 → botapi_py-1.4.12}/pyproject.toml +1 -1
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/types.py +46 -2
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/__init__.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/__init__.pyi +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/core.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/dispatchers/__init__.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/dispatchers/__init__.pyi +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/dispatchers/common.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/dispatchers/get_updates_handler.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/dispatchers/redis_pubsub_handler.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/enums.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/errors.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/methods.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/shortcuts.py +0 -0
- {botapi_py-1.4.11 → botapi_py-1.4.12}/src/botapi/utils.py +0 -0
|
@@ -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
|
'''
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|