-
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.
Feature/internal bot notification (#159)
* feat: internal bot notification * feat: internal bot notification * feat: internal bot notification * feat: internal bot notification * chore: update packages and fix some comments and docstrings * test: internal bot notification sending * test: internal bot notification handling * chore: version bump, changelog * chore: fix mkdocs * chore: version to 0.22.0 * fix: wrong data shape in message builder * fix: lint
- Loading branch information
Showing
29 changed files
with
763 additions
and
349 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
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,47 @@ | ||
"""Mixin for shortcut for internal bot notification resource requests.""" | ||
|
||
from typing import Any, Dict, List, Optional | ||
from uuid import UUID | ||
|
||
from botx.bots.mixins.requests.call_protocol import BotXMethodCallProtocol | ||
from botx.clients.methods.v4.notifications.internal_bot_notification import ( | ||
InternalBotNotification, | ||
) | ||
from botx.clients.types.message_payload import InternalBotNotificationPayload | ||
from botx.models.messages.sending.credentials import SendingCredentials | ||
|
||
|
||
class InternalBotNotificationRequestsMixin: | ||
"""Mixin for shortcut for internal bot notification resource requests.""" | ||
|
||
async def internal_bot_notification( # noqa: WPS211 | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
group_chat_id: UUID, | ||
text: str, | ||
sender: Optional[str] = None, | ||
recipients: Optional[List[UUID]] = None, | ||
opts: Optional[Dict[str, Any]] = None, | ||
) -> UUID: | ||
"""Send internal bot notifications into chat. | ||
Arguments: | ||
credentials: credentials for making request. | ||
group_chat_id: ID of chats into which message should be sent. | ||
text: notification text. | ||
sender: information about notification sender. | ||
recipients: List of recipients' UUIDs (send to all if None) | ||
opts: additional user-defined data to send | ||
Returns: | ||
Sync ID of sent notification. | ||
""" | ||
return await self.call_method( | ||
InternalBotNotification( | ||
group_chat_id=group_chat_id, | ||
recipients=recipients, | ||
data=InternalBotNotificationPayload(message=text, sender=sender), | ||
opts=opts or {}, | ||
), | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Definition for V4 API methods for BotX API.""" |
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 methods for notifications resource.""" |
29 changes: 29 additions & 0 deletions
29
botx/clients/methods/v4/notifications/internal_bot_notification.py
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,29 @@ | ||
"""Method for sending internal bot notification.""" | ||
from typing import Any, Dict, List, Optional | ||
from uuid import UUID | ||
|
||
from botx.clients.methods.base import AuthorizedBotXMethod | ||
from botx.clients.methods.extractors import extract_generated_sync_id | ||
from botx.clients.types.message_payload import InternalBotNotificationPayload | ||
from botx.clients.types.response_results import InternalBotNotificationResult | ||
|
||
|
||
class InternalBotNotification(AuthorizedBotXMethod[UUID]): | ||
"""Method for sending internal bot notification.""" | ||
|
||
__url__ = "/api/v4/botx/notifications/internal" | ||
__method__ = "POST" | ||
__returning__ = InternalBotNotificationResult | ||
__result_extractor__ = extract_generated_sync_id | ||
|
||
#: IDs of chats for new notification. | ||
group_chat_id: UUID | ||
|
||
#: HUIDs of bots that should receive notifications (None for all bots in chat). | ||
recipients: Optional[List[UUID]] = None | ||
|
||
# notification payload | ||
data: InternalBotNotificationPayload # noqa: WPS110 | ||
|
||
#: extra options for message. | ||
opts: Dict[str, Any] = {} |
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
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,28 @@ | ||
"""Endpoints for notification resource.""" | ||
|
||
from starlette.requests import Request | ||
from starlette.responses import Response | ||
|
||
from botx.clients.methods.v4.notifications.internal_bot_notification import ( | ||
InternalBotNotification, | ||
) | ||
from botx.testing.botx_mock.asgi.messages import add_message_to_collection | ||
from botx.testing.botx_mock.asgi.responses import ( | ||
generate_internal_bot_notification_response, | ||
) | ||
from botx.testing.botx_mock.binders import bind_implementation_to_method | ||
|
||
|
||
@bind_implementation_to_method(InternalBotNotification) | ||
async def post_internal_bot_notification(request: Request) -> Response: | ||
"""Handle pushed notification request. | ||
Arguments: | ||
request: HTTP request from Starlette. | ||
Returns: | ||
Response with sync_id of pushed message. | ||
""" | ||
payload = InternalBotNotification.parse_obj(await request.json()) | ||
add_message_to_collection(request, payload) | ||
return generate_internal_bot_notification_response(payload) |
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
Oops, something went wrong.
371b631
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://61234e991980fc617efe0de5--pybotx.netlify.app