-
Notifications
You must be signed in to change notification settings - Fork 850
feat(models): add feedback_buttons and icon_button blocks as context_actions block elements #1750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
64a0718
feat(models): add feedback_buttons and icon_button blocks as context_…
zimeg 25635d5
test: feedback buttons object
zimeg e9a97f1
chore: lint
zimeg 49229e1
test: fix expected types
zimeg 92982cd
fix: unwrap feedback button object text value
zimeg 9741906
fix: parse as plain text and stingified to text object
zimeg 44b040d
test: fix typechecks and unit tests
zimeg 88f2d86
Merge branch 'ai-apps' into zimeg-feat-models-feedback-buttons
zimeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,13 +1,10 @@ | ||
| import copy | ||
| import logging | ||
| import warnings | ||
| from typing import List, Optional, Set, Union, Sequence, Dict, Any | ||
| from typing import Any, Dict, List, Optional, Sequence, Set, Union | ||
|
|
||
| from slack_sdk.models import show_unknown_key_warning | ||
| from slack_sdk.models.basic_objects import ( | ||
| JsonObject, | ||
| JsonValidator, | ||
| ) | ||
| from slack_sdk.models.basic_objects import JsonObject, JsonValidator | ||
| from slack_sdk.models.messages import Link | ||
|
|
||
| ButtonStyles = {"danger", "primary"} | ||
|
|
@@ -526,6 +523,66 @@ def to_dict(self) -> Dict[str, Any]: | |
| return json | ||
|
|
||
|
|
||
| class FeedbackButtonObject(JsonObject): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗣️ note: This isn't a well defined block according to the API but it's added for nested block values using these typings. |
||
| attributes: Set[str] = set() | ||
|
|
||
| text_max_length = 75 | ||
| value_max_length = 2000 | ||
|
|
||
| @classmethod | ||
| def parse(cls, feedback_button: Union["FeedbackButtonObject", Dict[str, Any]]): | ||
| if feedback_button: | ||
| if isinstance(feedback_button, FeedbackButtonObject): | ||
| return feedback_button | ||
| elif isinstance(feedback_button, dict): | ||
| return FeedbackButtonObject(**feedback_button) | ||
| else: | ||
| # Not yet implemented: show some warning here | ||
| return None | ||
| return None | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| text: Union[str, Dict[str, Any], PlainTextObject], | ||
| accessibility_label: Optional[str] = None, | ||
| value: str, | ||
| **others: Dict[str, Any], | ||
| ): | ||
| """ | ||
| A feedback button element object for either positive or negative feedback. | ||
|
|
||
| Args: | ||
| text (required): An object containing some text. Maximum length for this field is 75 characters. | ||
| accessibility_label: A label for longer descriptive text about a button element. This label will be read out by | ||
| screen readers instead of the button `text` object. | ||
| value (required): The button value. Maximum length for this field is 2000 characters. | ||
| """ | ||
| self._text: Optional[TextObject] = PlainTextObject.parse(text, default_type=PlainTextObject.type) | ||
| self._accessibility_label: Optional[str] = accessibility_label | ||
| self._value: Optional[str] = value | ||
| show_unknown_key_warning(self, others) | ||
|
|
||
| @JsonValidator(f"text attribute cannot exceed {text_max_length} characters") | ||
| def text_length(self) -> bool: | ||
| return self._text is None or len(self._text.text) <= self.text_max_length | ||
|
|
||
| @JsonValidator(f"value attribute cannot exceed {value_max_length} characters") | ||
| def value_length(self) -> bool: | ||
| return self._value is None or len(self._value) <= self.value_max_length | ||
|
|
||
| def to_dict(self) -> Dict[str, Any]: | ||
| self.validate_json() | ||
| json: Dict[str, Union[str, dict]] = {} | ||
| if self._text: | ||
| json["text"] = self._text.to_dict() | ||
| if self._accessibility_label: | ||
| json["accessibility_label"] = self._accessibility_label | ||
| if self._value: | ||
| json["value"] = self._value | ||
| return json | ||
|
|
||
|
|
||
| class WorkflowTrigger(JsonObject): | ||
| attributes = {"trigger"} | ||
|
|
||
|
|
||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🪓 note: Automatic import sorting and grouping captures most of these changes!