Skip to content

Commit edc04aa

Browse files
authored
Fix #1424 Add file input block element support (#1425)
1 parent 774b0e1 commit edc04aa

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

slack_sdk/models/blocks/block_elements.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,55 @@ def __init__(
16241624
self.dispatch_action_config = dispatch_action_config
16251625

16261626

1627+
# -------------------------------------------------
1628+
# File Input Element
1629+
# -------------------------------------------------
1630+
1631+
1632+
class FileInputElement(InputInteractiveElement):
1633+
type = "file_input"
1634+
1635+
@property
1636+
def attributes(self) -> Set[str]:
1637+
return super().attributes.union(
1638+
{
1639+
"filetypes",
1640+
"max_files",
1641+
}
1642+
)
1643+
1644+
def __init__(
1645+
self,
1646+
*,
1647+
action_id: Optional[str] = None,
1648+
filetypes: Optional[List[str]] = None,
1649+
max_files: Optional[int] = None,
1650+
**others: dict,
1651+
):
1652+
"""
1653+
https://api.slack.com/reference/block-kit/block-elements#file_input
1654+
1655+
Args:
1656+
action_id (required): An identifier for the input value when the parent modal is submitted.
1657+
You can use this when you receive a view_submission payload to identify the value of the input element.
1658+
Should be unique among all other action_ids in the containing block. Maximum length is 255 characters.
1659+
filetypes: An array of valid file extensions that will be accepted for this element.
1660+
All file extensions will be accepted if filetypes is not specified.
1661+
This validation is provided for convenience only,
1662+
and you should perform your own file type validation based on what you expect to receive.
1663+
max_files: Maximum number of files that can be uploaded for this file_input element.
1664+
Minimum of 1, maximum of 10. Defaults to 10 if not specified.
1665+
"""
1666+
super().__init__(
1667+
type=self.type,
1668+
action_id=action_id,
1669+
)
1670+
show_unknown_key_warning(self, others)
1671+
1672+
self.filetypes = filetypes
1673+
self.max_files = max_files
1674+
1675+
16271676
# -------------------------------------------------
16281677
# Radio Buttons Select
16291678
# -------------------------------------------------

tests/slack_sdk/models/test_elements.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
UrlInputElement,
3636
WorkflowButtonElement,
3737
RichTextInputElement,
38+
FileInputElement,
3839
)
3940
from . import STRING_3001_CHARS, STRING_301_CHARS
4041

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

12011202

1203+
# -------------------------------------------------
1204+
# File Input Element
1205+
# -------------------------------------------------
1206+
1207+
1208+
class FileInputElementTests(unittest.TestCase):
1209+
def test_element(self):
1210+
input = {
1211+
"type": "file_input",
1212+
"action_id": "file_input-action",
1213+
"filetypes": ["pdf", "txt"],
1214+
"max_files": 3,
1215+
}
1216+
self.assertDictEqual(input, FileInputElement(**input).to_dict())
1217+
1218+
12021219
# -------------------------------------------------
12031220
# Radio Buttons
12041221
# -------------------------------------------------

0 commit comments

Comments
 (0)