Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions slack_sdk/web/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4036,6 +4036,7 @@ async def files_upload_v2(
content: Optional[Union[str, bytes]] = None,
title: Optional[str] = None,
alt_txt: Optional[str] = None,
highlight_type: Optional[str] = None,
snippet_type: Optional[str] = None,
# To upload multiple files at a time
file_uploads: Optional[List[Dict[str, Any]]] = None,
Expand Down Expand Up @@ -4080,6 +4081,7 @@ async def files_upload_v2(
"content": content,
"title": title,
"alt_txt": alt_txt,
"highlight_type": highlight_type,
"snippet_type": snippet_type,
}
)
Expand Down Expand Up @@ -4118,7 +4120,7 @@ async def files_upload_v2(

# step3: files.completeUploadExternal with all the sets of (file_id + title)
completion = await self.files_completeUploadExternal(
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
channel_id=channel,
channels=channels,
initial_comment=initial_comment,
Expand Down Expand Up @@ -4154,7 +4156,7 @@ async def files_getUploadURLExternal(
async def files_completeUploadExternal(
self,
*,
files: List[Dict[str, str]],
files: List[Dict[str, Optional[str]]],
channel_id: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
Expand Down
6 changes: 4 additions & 2 deletions slack_sdk/web/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4026,6 +4026,7 @@ def files_upload_v2(
content: Optional[Union[str, bytes]] = None,
title: Optional[str] = None,
alt_txt: Optional[str] = None,
highlight_type: Optional[str] = None,
snippet_type: Optional[str] = None,
# To upload multiple files at a time
file_uploads: Optional[List[Dict[str, Any]]] = None,
Expand Down Expand Up @@ -4070,6 +4071,7 @@ def files_upload_v2(
"content": content,
"title": title,
"alt_txt": alt_txt,
"highlight_type": highlight_type,
"snippet_type": snippet_type,
}
)
Expand Down Expand Up @@ -4108,7 +4110,7 @@ def files_upload_v2(

# step3: files.completeUploadExternal with all the sets of (file_id + title)
completion = self.files_completeUploadExternal(
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
channel_id=channel,
channels=channels,
initial_comment=initial_comment,
Expand Down Expand Up @@ -4144,7 +4146,7 @@ def files_getUploadURLExternal(
def files_completeUploadExternal(
self,
*,
files: List[Dict[str, str]],
files: List[Dict[str, Optional[str]]],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📣 note: This becomes less strict as highlight_type is an optional value for files argument! It's also removed if left to the value None below.

channel_id: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
Expand Down
1 change: 1 addition & 0 deletions slack_sdk/web/internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def _to_v2_file_upload_item(upload_file: Dict[str, Any]) -> Dict[str, Optional[A
"length": len(data),
"title": title,
"alt_txt": upload_file.get("alt_txt"),
"highlight_type": upload_file.get("highlight_type"),
"snippet_type": upload_file.get("snippet_type"),
}

Expand Down
6 changes: 4 additions & 2 deletions slack_sdk/web/legacy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3961,6 +3961,7 @@ def files_upload_v2(
content: Optional[Union[str, bytes]] = None,
title: Optional[str] = None,
alt_txt: Optional[str] = None,
highlight_type: Optional[str] = None,
snippet_type: Optional[str] = None,
# To upload multiple files at a time
file_uploads: Optional[List[Dict[str, Any]]] = None,
Expand Down Expand Up @@ -4005,6 +4006,7 @@ def files_upload_v2(
"content": content,
"title": title,
"alt_txt": alt_txt,
"highlight_type": highlight_type,
"snippet_type": snippet_type,
}
)
Expand Down Expand Up @@ -4043,7 +4045,7 @@ def files_upload_v2(

# step3: files.completeUploadExternal with all the sets of (file_id + title)
completion = self.files_completeUploadExternal(
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
channel_id=channel,
channels=channels,
initial_comment=initial_comment,
Expand Down Expand Up @@ -4079,7 +4081,7 @@ def files_getUploadURLExternal(
def files_completeUploadExternal(
self,
*,
files: List[Dict[str, str]],
files: List[Dict[str, Optional[str]]],
channel_id: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
Expand Down
7 changes: 7 additions & 0 deletions tests/slack_sdk/web/test_internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def test_files_upload_v2_issue_1356(self):
file_io_item = _to_v2_file_upload_item({"file": file_io, "filename": "foo.txt"})
assert file_io_item.get("filename") == "foo.txt"

def test_to_v2_file_upload_item_passes_through_highlight_type(self):
item = _to_v2_file_upload_item({"content": "test", "filename": "image.png", "highlight_type": "png"})
assert item.get("highlight_type") == "png"

item_without = _to_v2_file_upload_item({"content": "test", "filename": "image.png"})
assert item_without.get("highlight_type") is None

def test_to_v2_file_upload_item_can_accept_file_as_path(self):
filepath = "tests/slack_sdk/web/test_internal_utils.py"
upload_item_str = _to_v2_file_upload_item({"file": filepath})
Expand Down