|
3 | 3 | import re
|
4 | 4 | import warnings
|
5 | 5 | from abc import ABCMeta
|
6 |
| -from typing import Iterator, List, Optional, Set, Type, Union, Sequence, Dict, Any |
| 6 | +from typing import Any, Dict, Iterator, List, Optional, Sequence, Set, Type, Union |
7 | 7 |
|
8 | 8 | from slack_sdk.models import show_unknown_key_warning
|
9 |
| -from slack_sdk.models.basic_objects import ( |
10 |
| - JsonObject, |
11 |
| - JsonValidator, |
12 |
| - EnumValidator, |
| 9 | +from slack_sdk.models.basic_objects import EnumValidator, JsonObject, JsonValidator |
| 10 | + |
| 11 | +from .basic_components import ( |
| 12 | + ButtonStyles, |
| 13 | + ConfirmObject, |
| 14 | + DispatchActionConfig, |
| 15 | + FeedbackButtonObject, |
| 16 | + MarkdownTextObject, |
| 17 | + Option, |
| 18 | + OptionGroup, |
| 19 | + PlainTextObject, |
| 20 | + SlackFile, |
| 21 | + TextObject, |
| 22 | + Workflow, |
13 | 23 | )
|
14 |
| -from .basic_components import ButtonStyles, Workflow, SlackFile |
15 |
| -from .basic_components import ConfirmObject |
16 |
| -from .basic_components import DispatchActionConfig |
17 |
| -from .basic_components import MarkdownTextObject |
18 |
| -from .basic_components import Option |
19 |
| -from .basic_components import OptionGroup |
20 |
| -from .basic_components import PlainTextObject |
21 |
| -from .basic_components import TextObject |
22 |
| - |
23 | 24 |
|
24 | 25 | # -------------------------------------------------
|
25 | 26 | # Block Elements
|
@@ -539,6 +540,43 @@ def _validate_initial_date_time_valid(self) -> bool:
|
539 | 540 | return self.initial_date_time is None or (0 <= self.initial_date_time <= 9999999999)
|
540 | 541 |
|
541 | 542 |
|
| 543 | +# ------------------------------------------------- |
| 544 | +# Feedback Buttons Element |
| 545 | +# ------------------------------------------------- |
| 546 | + |
| 547 | + |
| 548 | +class FeedbackButtonsElement(InteractiveElement): |
| 549 | + type = "feedback_buttons" |
| 550 | + |
| 551 | + @property |
| 552 | + def attributes(self) -> Set[str]: # type: ignore[override] |
| 553 | + return super().attributes.union({"positive_button", "negative_button"}) |
| 554 | + |
| 555 | + def __init__( |
| 556 | + self, |
| 557 | + *, |
| 558 | + action_id: Optional[str] = None, |
| 559 | + positive_button: Union[dict, FeedbackButtonObject], |
| 560 | + negative_button: Union[dict, FeedbackButtonObject], |
| 561 | + **others: dict, |
| 562 | + ): |
| 563 | + """Buttons to indicate positive or negative feedback. |
| 564 | +
|
| 565 | + Args: |
| 566 | + action_id (required): An identifier for this action. |
| 567 | + You can use this when you receive an interaction payload to identify the source of the action. |
| 568 | + Should be unique among all other action_ids in the containing block. |
| 569 | + Maximum length for this field is 255 characters. |
| 570 | + positive_button (required): A button to indicate positive feedback. |
| 571 | + negative_button (required): A button to indicate negative feedback. |
| 572 | + """ |
| 573 | + super().__init__(action_id=action_id, type=self.type) |
| 574 | + show_unknown_key_warning(self, others) |
| 575 | + |
| 576 | + self.positive_button = FeedbackButtonObject.parse(positive_button) |
| 577 | + self.negative_button = FeedbackButtonObject.parse(negative_button) |
| 578 | + |
| 579 | + |
542 | 580 | # -------------------------------------------------
|
543 | 581 | # Image
|
544 | 582 | # -------------------------------------------------
|
@@ -587,6 +625,59 @@ def _validate_alt_text_length(self) -> bool:
|
587 | 625 | return len(self.alt_text) <= self.alt_text_max_length # type: ignore[arg-type]
|
588 | 626 |
|
589 | 627 |
|
| 628 | +# ------------------------------------------------- |
| 629 | +# Icon Button Element |
| 630 | +# ------------------------------------------------- |
| 631 | + |
| 632 | + |
| 633 | +class IconButtonElement(InteractiveElement): |
| 634 | + type = "icon_button" |
| 635 | + |
| 636 | + @property |
| 637 | + def attributes(self) -> Set[str]: # type: ignore[override] |
| 638 | + return super().attributes.union({"icon", "text", "accessibility_label", "value", "visible_to_user_ids", "confirm"}) |
| 639 | + |
| 640 | + def __init__( |
| 641 | + self, |
| 642 | + *, |
| 643 | + action_id: Optional[str] = None, |
| 644 | + icon: str, |
| 645 | + text: Union[str, dict, TextObject], |
| 646 | + accessibility_label: Optional[str] = None, |
| 647 | + value: Optional[str] = None, |
| 648 | + visible_to_user_ids: Optional[List[str]] = None, |
| 649 | + confirm: Optional[Union[dict, ConfirmObject]] = None, |
| 650 | + **others: dict, |
| 651 | + ): |
| 652 | + """An icon button to perform actions. |
| 653 | +
|
| 654 | + Args: |
| 655 | + action_id: An identifier for this action. |
| 656 | + You can use this when you receive an interaction payload to identify the source of the action. |
| 657 | + Should be unique among all other action_ids in the containing block. |
| 658 | + Maximum length for this field is 255 characters. |
| 659 | + icon (required): The icon to show (e.g., 'trash'). |
| 660 | + text (required): Defines an object containing some text. |
| 661 | + accessibility_label: A label for longer descriptive text about a button element. |
| 662 | + This label will be read out by screen readers instead of the button text object. |
| 663 | + Maximum length for this field is 75 characters. |
| 664 | + value: The button value. |
| 665 | + Maximum length for this field is 2000 characters. |
| 666 | + visible_to_user_ids: User IDs for which the icon appears. |
| 667 | + Maximum length for this field is 10 user IDs. |
| 668 | + confirm: A confirm object that defines an optional confirmation dialog after the button is clicked. |
| 669 | + """ |
| 670 | + super().__init__(action_id=action_id, type=self.type) |
| 671 | + show_unknown_key_warning(self, others) |
| 672 | + |
| 673 | + self.icon = icon |
| 674 | + self.text = TextObject.parse(text, PlainTextObject.type) |
| 675 | + self.accessibility_label = accessibility_label |
| 676 | + self.value = value |
| 677 | + self.visible_to_user_ids = visible_to_user_ids |
| 678 | + self.confirm = ConfirmObject.parse(confirm) if confirm else None |
| 679 | + |
| 680 | + |
590 | 681 | # -------------------------------------------------
|
591 | 682 | # Static Select
|
592 | 683 | # -------------------------------------------------
|
|
0 commit comments