Skip to content

Commit ef3975b

Browse files
authored
Add channels param to files.upload v2 method (#1641)
1 parent c77b863 commit ef3975b

File tree

3 files changed

+21
-60
lines changed

3 files changed

+21
-60
lines changed

slack_sdk/web/async_client.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,6 +3757,7 @@ async def files_upload_v2(
37573757
# To upload multiple files at a time
37583758
file_uploads: Optional[List[Dict[str, Any]]] = None,
37593759
channel: Optional[str] = None,
3760+
channels: Optional[List[str]] = None,
37603761
initial_comment: Optional[str] = None,
37613762
thread_ts: Optional[str] = None,
37623763
request_file_info: bool = True, # since v3.23, this flag is no longer necessary
@@ -3778,20 +3779,8 @@ async def files_upload_v2(
37783779
raise e.SlackRequestError("You cannot specify both the file and the content argument.")
37793780

37803781
# deprecated arguments:
3781-
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
3782+
filetype = kwargs.get("filetype")
37823783

3783-
if channels is not None:
3784-
warnings.warn(
3785-
"Although the channels parameter is still supported for smooth migration from legacy files.upload, "
3786-
"we recommend using the new channel parameter with a single str value instead for more clarity."
3787-
)
3788-
if (isinstance(channels, (list, tuple)) and len(channels) > 1) or (
3789-
isinstance(channels, str) and len(channels.split(",")) > 1
3790-
):
3791-
raise e.SlackRequestError(
3792-
"Sharing files with multiple channels is no longer supported in v2. "
3793-
"Share files in each channel separately instead."
3794-
)
37953784
if filetype is not None:
37963785
warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.")
37973786

@@ -3845,15 +3834,10 @@ async def files_upload_v2(
38453834
raise e.SlackRequestError(message)
38463835

38473836
# step3: files.completeUploadExternal with all the sets of (file_id + title)
3848-
channel_to_share = channel
3849-
if channels is not None:
3850-
if isinstance(channels, str):
3851-
channel_to_share = channels.split(",")[0]
3852-
else:
3853-
channel_to_share = channels[0]
38543837
completion = await self.files_completeUploadExternal(
38553838
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
3856-
channel_id=channel_to_share,
3839+
channel_id=channel,
3840+
channels=channels,
38573841
initial_comment=initial_comment,
38583842
thread_ts=thread_ts,
38593843
**kwargs,
@@ -3889,6 +3873,7 @@ async def files_completeUploadExternal(
38893873
*,
38903874
files: List[Dict[str, str]],
38913875
channel_id: Optional[str] = None,
3876+
channels: Optional[List[str]] = None,
38923877
initial_comment: Optional[str] = None,
38933878
thread_ts: Optional[str] = None,
38943879
**kwargs,
@@ -3905,6 +3890,8 @@ async def files_completeUploadExternal(
39053890
"thread_ts": thread_ts,
39063891
}
39073892
)
3893+
if channels:
3894+
kwargs["channels"] = ",".join(channels)
39083895
return await self.api_call("files.completeUploadExternal", params=kwargs)
39093896

39103897
async def functions_completeSuccess(

slack_sdk/web/client.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,6 +3747,7 @@ def files_upload_v2(
37473747
# To upload multiple files at a time
37483748
file_uploads: Optional[List[Dict[str, Any]]] = None,
37493749
channel: Optional[str] = None,
3750+
channels: Optional[List[str]] = None,
37503751
initial_comment: Optional[str] = None,
37513752
thread_ts: Optional[str] = None,
37523753
request_file_info: bool = True, # since v3.23, this flag is no longer necessary
@@ -3768,20 +3769,8 @@ def files_upload_v2(
37683769
raise e.SlackRequestError("You cannot specify both the file and the content argument.")
37693770

37703771
# deprecated arguments:
3771-
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
3772+
filetype = kwargs.get("filetype")
37723773

3773-
if channels is not None:
3774-
warnings.warn(
3775-
"Although the channels parameter is still supported for smooth migration from legacy files.upload, "
3776-
"we recommend using the new channel parameter with a single str value instead for more clarity."
3777-
)
3778-
if (isinstance(channels, (list, tuple)) and len(channels) > 1) or (
3779-
isinstance(channels, str) and len(channels.split(",")) > 1
3780-
):
3781-
raise e.SlackRequestError(
3782-
"Sharing files with multiple channels is no longer supported in v2. "
3783-
"Share files in each channel separately instead."
3784-
)
37853774
if filetype is not None:
37863775
warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.")
37873776

@@ -3835,15 +3824,10 @@ def files_upload_v2(
38353824
raise e.SlackRequestError(message)
38363825

38373826
# step3: files.completeUploadExternal with all the sets of (file_id + title)
3838-
channel_to_share = channel
3839-
if channels is not None:
3840-
if isinstance(channels, str):
3841-
channel_to_share = channels.split(",")[0]
3842-
else:
3843-
channel_to_share = channels[0]
38443827
completion = self.files_completeUploadExternal(
38453828
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
3846-
channel_id=channel_to_share,
3829+
channel_id=channel,
3830+
channels=channels,
38473831
initial_comment=initial_comment,
38483832
thread_ts=thread_ts,
38493833
**kwargs,
@@ -3879,6 +3863,7 @@ def files_completeUploadExternal(
38793863
*,
38803864
files: List[Dict[str, str]],
38813865
channel_id: Optional[str] = None,
3866+
channels: Optional[List[str]] = None,
38823867
initial_comment: Optional[str] = None,
38833868
thread_ts: Optional[str] = None,
38843869
**kwargs,
@@ -3895,6 +3880,8 @@ def files_completeUploadExternal(
38953880
"thread_ts": thread_ts,
38963881
}
38973882
)
3883+
if channels:
3884+
kwargs["channels"] = ",".join(channels)
38983885
return self.api_call("files.completeUploadExternal", params=kwargs)
38993886

39003887
def functions_completeSuccess(

slack_sdk/web/legacy_client.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,6 +3759,7 @@ def files_upload_v2(
37593759
# To upload multiple files at a time
37603760
file_uploads: Optional[List[Dict[str, Any]]] = None,
37613761
channel: Optional[str] = None,
3762+
channels: Optional[List[str]] = None,
37623763
initial_comment: Optional[str] = None,
37633764
thread_ts: Optional[str] = None,
37643765
request_file_info: bool = True, # since v3.23, this flag is no longer necessary
@@ -3780,20 +3781,8 @@ def files_upload_v2(
37803781
raise e.SlackRequestError("You cannot specify both the file and the content argument.")
37813782

37823783
# deprecated arguments:
3783-
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
3784+
filetype = kwargs.get("filetype")
37843785

3785-
if channels is not None:
3786-
warnings.warn(
3787-
"Although the channels parameter is still supported for smooth migration from legacy files.upload, "
3788-
"we recommend using the new channel parameter with a single str value instead for more clarity."
3789-
)
3790-
if (isinstance(channels, (list, tuple)) and len(channels) > 1) or (
3791-
isinstance(channels, str) and len(channels.split(",")) > 1
3792-
):
3793-
raise e.SlackRequestError(
3794-
"Sharing files with multiple channels is no longer supported in v2. "
3795-
"Share files in each channel separately instead."
3796-
)
37973786
if filetype is not None:
37983787
warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.")
37993788

@@ -3847,15 +3836,10 @@ def files_upload_v2(
38473836
raise e.SlackRequestError(message)
38483837

38493838
# step3: files.completeUploadExternal with all the sets of (file_id + title)
3850-
channel_to_share = channel
3851-
if channels is not None:
3852-
if isinstance(channels, str):
3853-
channel_to_share = channels.split(",")[0]
3854-
else:
3855-
channel_to_share = channels[0]
38563839
completion = self.files_completeUploadExternal(
38573840
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
3858-
channel_id=channel_to_share,
3841+
channel_id=channel,
3842+
channels=channels,
38593843
initial_comment=initial_comment,
38603844
thread_ts=thread_ts,
38613845
**kwargs,
@@ -3891,6 +3875,7 @@ def files_completeUploadExternal(
38913875
*,
38923876
files: List[Dict[str, str]],
38933877
channel_id: Optional[str] = None,
3878+
channels: Optional[List[str]] = None,
38943879
initial_comment: Optional[str] = None,
38953880
thread_ts: Optional[str] = None,
38963881
**kwargs,
@@ -3907,6 +3892,8 @@ def files_completeUploadExternal(
39073892
"thread_ts": thread_ts,
39083893
}
39093894
)
3895+
if channels:
3896+
kwargs["channels"] = ",".join(channels)
39103897
return self.api_call("files.completeUploadExternal", params=kwargs)
39113898

39123899
def functions_completeSuccess(

0 commit comments

Comments
 (0)