Skip to content

Commit

Permalink
Fix slackapi#1424 Add file input block element support
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Nov 15, 2023
1 parent 774b0e1 commit 5f867af
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
49 changes: 49 additions & 0 deletions slack_sdk/models/blocks/block_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,55 @@ def __init__(
self.dispatch_action_config = dispatch_action_config


# -------------------------------------------------
# File Input Element
# -------------------------------------------------


class FileInputElement(InputInteractiveElement):
type = "file_input"

@property
def attributes(self) -> Set[str]:
return super().attributes.union(
{
"filetypes",
"max_files",
}
)

def __init__(
self,
*,
action_id: Optional[str] = None,
filetypes: Optional[List[str]] = False,
max_files: Optional[int] = None,
**others: dict,
):
"""
https://api.slack.com/reference/block-kit/block-elements#file_input
Args:
action_id (required): An identifier for the input value when the parent modal is submitted.
You can use this when you receive a view_submission payload to identify the value of the input element.
Should be unique among all other action_ids in the containing block. Maximum length is 255 characters.
filetypes: An array of valid file extensions that will be accepted for this element.
All file extensions will be accepted if filetypes is not specified.
This validation is provided for convenience only,
and you should perform your own file type validation based on what you expect to receive.
max_files: Maximum number of files that can be uploaded for this file_input element.
Minimum of 1, maximum of 10. Defaults to 10 if not specified.
"""
super().__init__(
type=self.type,
action_id=action_id,
)
show_unknown_key_warning(self, others)

self.filetypes = filetypes
self.max_files = max_files


# -------------------------------------------------
# Radio Buttons Select
# -------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions tests/slack_sdk/models/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
UrlInputElement,
WorkflowButtonElement,
RichTextInputElement,
FileInputElement,
)
from . import STRING_3001_CHARS, STRING_301_CHARS

Expand Down Expand Up @@ -1199,6 +1200,22 @@ def test_focus_on_load(self):
self.assertDictEqual(input, NumberInputElement(**input).to_dict())


# -------------------------------------------------
# File Input Element
# -------------------------------------------------


class FileInputElementTests(unittest.TestCase):
def test_element(self):
input = {
"type": "file_input",
"action_id": "file_input-action",
"filetypes": ["pdf", "txt"],
"max_files": 3,
}
self.assertDictEqual(input, FileInputElement(**input).to_dict())


# -------------------------------------------------
# Radio Buttons
# -------------------------------------------------
Expand Down

0 comments on commit 5f867af

Please sign in to comment.