-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add download and upload files methods * test: add and refactor tests * docs: add release changes * chore: fix pyproject.toml
- Loading branch information
Showing
40 changed files
with
1,250 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""Mixin for shortcut for files resource requests.""" | ||
|
||
from typing import Optional | ||
from uuid import UUID | ||
|
||
from botx.bots.mixins.requests.call_protocol import BotXMethodCallProtocol | ||
from botx.clients.clients.async_client import AsyncClient | ||
from botx.clients.methods.v3.files.download import DownloadFile | ||
from botx.clients.methods.v3.files.upload import UploadFile | ||
from botx.clients.types.upload_file import UploadingFileMeta | ||
from botx.models.files import File, MetaFile | ||
from botx.models.messages.sending.credentials import SendingCredentials | ||
|
||
|
||
class FilesRequestsMixin: | ||
"""Mixin for shortcut for files resource requests.""" | ||
|
||
client: AsyncClient | ||
|
||
async def upload_file( # noqa: WPS211 | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
sending_file: File, | ||
group_chat_id: UUID, | ||
*, | ||
duration: Optional[int] = None, | ||
caption: Optional[str] = None, | ||
) -> MetaFile: | ||
"""Upload file to the chat. | ||
Arguments: | ||
credentials: credentials for making request. | ||
sending_file: file to upload. | ||
group_chat_id: ID of the chat that accepts the file. | ||
duration: duration of the voice or the video. | ||
caption: file caption. | ||
Returns: | ||
File metadata. | ||
""" | ||
return await self.call_method( | ||
UploadFile( | ||
group_chat_id=group_chat_id, | ||
file=sending_file, | ||
meta=UploadingFileMeta( | ||
duration=duration, | ||
caption=caption, | ||
), | ||
), | ||
credentials=credentials, | ||
) | ||
|
||
async def download_file( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
file_id: UUID, | ||
group_chat_id: UUID, | ||
*, | ||
is_preview: bool = False, | ||
) -> File: | ||
"""Download file from the chat. | ||
Arguments: | ||
credentials: credentials for making request. | ||
file_id: ID of the file. | ||
group_chat_id: ID of the chat that accepts the file. | ||
is_preview: get preview or file. | ||
Returns: | ||
Downloaded file. | ||
""" | ||
return await self.call_method( | ||
DownloadFile( | ||
file_id=file_id, | ||
group_chat_id=group_chat_id, | ||
is_preview=is_preview, | ||
), | ||
credentials=credentials, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Definition for built-in error handlers for responses from BotX API.""" |
Oops, something went wrong.
7e2cef0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://pybotx.netlify.app as production
🚀 Deployed on https://6126317e6745b9c0d0fac6a4--pybotx.netlify.app