Skip to content

Commit e69ba32

Browse files
authored
feat: add highlight_type to files.completeUploadExternal and files_upload_v2 (#1875)
1 parent beecde2 commit e69ba32

5 files changed

Lines changed: 20 additions & 6 deletions

File tree

slack_sdk/web/async_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4036,6 +4036,7 @@ async def files_upload_v2(
40364036
content: Optional[Union[str, bytes]] = None,
40374037
title: Optional[str] = None,
40384038
alt_txt: Optional[str] = None,
4039+
highlight_type: Optional[str] = None,
40394040
snippet_type: Optional[str] = None,
40404041
# To upload multiple files at a time
40414042
file_uploads: Optional[List[Dict[str, Any]]] = None,
@@ -4080,6 +4081,7 @@ async def files_upload_v2(
40804081
"content": content,
40814082
"title": title,
40824083
"alt_txt": alt_txt,
4084+
"highlight_type": highlight_type,
40834085
"snippet_type": snippet_type,
40844086
}
40854087
)
@@ -4118,7 +4120,7 @@ async def files_upload_v2(
41184120

41194121
# step3: files.completeUploadExternal with all the sets of (file_id + title)
41204122
completion = await self.files_completeUploadExternal(
4121-
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
4123+
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
41224124
channel_id=channel,
41234125
channels=channels,
41244126
initial_comment=initial_comment,
@@ -4154,7 +4156,7 @@ async def files_getUploadURLExternal(
41544156
async def files_completeUploadExternal(
41554157
self,
41564158
*,
4157-
files: List[Dict[str, str]],
4159+
files: List[Dict[str, Optional[str]]],
41584160
channel_id: Optional[str] = None,
41594161
channels: Optional[List[str]] = None,
41604162
initial_comment: Optional[str] = None,

slack_sdk/web/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4026,6 +4026,7 @@ def files_upload_v2(
40264026
content: Optional[Union[str, bytes]] = None,
40274027
title: Optional[str] = None,
40284028
alt_txt: Optional[str] = None,
4029+
highlight_type: Optional[str] = None,
40294030
snippet_type: Optional[str] = None,
40304031
# To upload multiple files at a time
40314032
file_uploads: Optional[List[Dict[str, Any]]] = None,
@@ -4070,6 +4071,7 @@ def files_upload_v2(
40704071
"content": content,
40714072
"title": title,
40724073
"alt_txt": alt_txt,
4074+
"highlight_type": highlight_type,
40734075
"snippet_type": snippet_type,
40744076
}
40754077
)
@@ -4108,7 +4110,7 @@ def files_upload_v2(
41084110

41094111
# step3: files.completeUploadExternal with all the sets of (file_id + title)
41104112
completion = self.files_completeUploadExternal(
4111-
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
4113+
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
41124114
channel_id=channel,
41134115
channels=channels,
41144116
initial_comment=initial_comment,
@@ -4144,7 +4146,7 @@ def files_getUploadURLExternal(
41444146
def files_completeUploadExternal(
41454147
self,
41464148
*,
4147-
files: List[Dict[str, str]],
4149+
files: List[Dict[str, Optional[str]]],
41484150
channel_id: Optional[str] = None,
41494151
channels: Optional[List[str]] = None,
41504152
initial_comment: Optional[str] = None,

slack_sdk/web/internal_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ def _to_v2_file_upload_item(upload_file: Dict[str, Any]) -> Dict[str, Optional[A
378378
"length": len(data),
379379
"title": title,
380380
"alt_txt": upload_file.get("alt_txt"),
381+
"highlight_type": upload_file.get("highlight_type"),
381382
"snippet_type": upload_file.get("snippet_type"),
382383
}
383384

slack_sdk/web/legacy_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,6 +3961,7 @@ def files_upload_v2(
39613961
content: Optional[Union[str, bytes]] = None,
39623962
title: Optional[str] = None,
39633963
alt_txt: Optional[str] = None,
3964+
highlight_type: Optional[str] = None,
39643965
snippet_type: Optional[str] = None,
39653966
# To upload multiple files at a time
39663967
file_uploads: Optional[List[Dict[str, Any]]] = None,
@@ -4005,6 +4006,7 @@ def files_upload_v2(
40054006
"content": content,
40064007
"title": title,
40074008
"alt_txt": alt_txt,
4009+
"highlight_type": highlight_type,
40084010
"snippet_type": snippet_type,
40094011
}
40104012
)
@@ -4043,7 +4045,7 @@ def files_upload_v2(
40434045

40444046
# step3: files.completeUploadExternal with all the sets of (file_id + title)
40454047
completion = self.files_completeUploadExternal(
4046-
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
4048+
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
40474049
channel_id=channel,
40484050
channels=channels,
40494051
initial_comment=initial_comment,
@@ -4079,7 +4081,7 @@ def files_getUploadURLExternal(
40794081
def files_completeUploadExternal(
40804082
self,
40814083
*,
4082-
files: List[Dict[str, str]],
4084+
files: List[Dict[str, Optional[str]]],
40834085
channel_id: Optional[str] = None,
40844086
channels: Optional[List[str]] = None,
40854087
initial_comment: Optional[str] = None,

tests/slack_sdk/web/test_internal_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def test_files_upload_v2_issue_1356(self):
133133
file_io_item = _to_v2_file_upload_item({"file": file_io, "filename": "foo.txt"})
134134
assert file_io_item.get("filename") == "foo.txt"
135135

136+
def test_to_v2_file_upload_item_passes_through_highlight_type(self):
137+
item = _to_v2_file_upload_item({"content": "test", "filename": "image.png", "highlight_type": "png"})
138+
assert item.get("highlight_type") == "png"
139+
140+
item_without = _to_v2_file_upload_item({"content": "test", "filename": "image.png"})
141+
assert item_without.get("highlight_type") is None
142+
136143
def test_to_v2_file_upload_item_can_accept_file_as_path(self):
137144
filepath = "tests/slack_sdk/web/test_internal_utils.py"
138145
upload_item_str = _to_v2_file_upload_item({"file": filepath})

0 commit comments

Comments
 (0)