Skip to content

Commit

Permalink
Add channels param to files.upload v2 method (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored Feb 3, 2025
1 parent c77b863 commit ef3975b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 60 deletions.
27 changes: 7 additions & 20 deletions slack_sdk/web/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3757,6 +3757,7 @@ async def files_upload_v2(
# To upload multiple files at a time
file_uploads: Optional[List[Dict[str, Any]]] = None,
channel: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
request_file_info: bool = True, # since v3.23, this flag is no longer necessary
Expand All @@ -3778,20 +3779,8 @@ async def files_upload_v2(
raise e.SlackRequestError("You cannot specify both the file and the content argument.")

# deprecated arguments:
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
filetype = kwargs.get("filetype")

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

Expand Down Expand Up @@ -3845,15 +3834,10 @@ async def files_upload_v2(
raise e.SlackRequestError(message)

# step3: files.completeUploadExternal with all the sets of (file_id + title)
channel_to_share = channel
if channels is not None:
if isinstance(channels, str):
channel_to_share = channels.split(",")[0]
else:
channel_to_share = channels[0]
completion = await self.files_completeUploadExternal(
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
channel_id=channel_to_share,
channel_id=channel,
channels=channels,
initial_comment=initial_comment,
thread_ts=thread_ts,
**kwargs,
Expand Down Expand Up @@ -3889,6 +3873,7 @@ async def files_completeUploadExternal(
*,
files: List[Dict[str, str]],
channel_id: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
**kwargs,
Expand All @@ -3905,6 +3890,8 @@ async def files_completeUploadExternal(
"thread_ts": thread_ts,
}
)
if channels:
kwargs["channels"] = ",".join(channels)
return await self.api_call("files.completeUploadExternal", params=kwargs)

async def functions_completeSuccess(
Expand Down
27 changes: 7 additions & 20 deletions slack_sdk/web/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3747,6 +3747,7 @@ def files_upload_v2(
# To upload multiple files at a time
file_uploads: Optional[List[Dict[str, Any]]] = None,
channel: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
request_file_info: bool = True, # since v3.23, this flag is no longer necessary
Expand All @@ -3768,20 +3769,8 @@ def files_upload_v2(
raise e.SlackRequestError("You cannot specify both the file and the content argument.")

# deprecated arguments:
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
filetype = kwargs.get("filetype")

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

Expand Down Expand Up @@ -3835,15 +3824,10 @@ def files_upload_v2(
raise e.SlackRequestError(message)

# step3: files.completeUploadExternal with all the sets of (file_id + title)
channel_to_share = channel
if channels is not None:
if isinstance(channels, str):
channel_to_share = channels.split(",")[0]
else:
channel_to_share = channels[0]
completion = self.files_completeUploadExternal(
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
channel_id=channel_to_share,
channel_id=channel,
channels=channels,
initial_comment=initial_comment,
thread_ts=thread_ts,
**kwargs,
Expand Down Expand Up @@ -3879,6 +3863,7 @@ def files_completeUploadExternal(
*,
files: List[Dict[str, str]],
channel_id: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
**kwargs,
Expand All @@ -3895,6 +3880,8 @@ def files_completeUploadExternal(
"thread_ts": thread_ts,
}
)
if channels:
kwargs["channels"] = ",".join(channels)
return self.api_call("files.completeUploadExternal", params=kwargs)

def functions_completeSuccess(
Expand Down
27 changes: 7 additions & 20 deletions slack_sdk/web/legacy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3759,6 +3759,7 @@ def files_upload_v2(
# To upload multiple files at a time
file_uploads: Optional[List[Dict[str, Any]]] = None,
channel: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
request_file_info: bool = True, # since v3.23, this flag is no longer necessary
Expand All @@ -3780,20 +3781,8 @@ def files_upload_v2(
raise e.SlackRequestError("You cannot specify both the file and the content argument.")

# deprecated arguments:
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
filetype = kwargs.get("filetype")

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

Expand Down Expand Up @@ -3847,15 +3836,10 @@ def files_upload_v2(
raise e.SlackRequestError(message)

# step3: files.completeUploadExternal with all the sets of (file_id + title)
channel_to_share = channel
if channels is not None:
if isinstance(channels, str):
channel_to_share = channels.split(",")[0]
else:
channel_to_share = channels[0]
completion = self.files_completeUploadExternal(
files=[{"id": f["file_id"], "title": f["title"]} for f in files],
channel_id=channel_to_share,
channel_id=channel,
channels=channels,
initial_comment=initial_comment,
thread_ts=thread_ts,
**kwargs,
Expand Down Expand Up @@ -3891,6 +3875,7 @@ def files_completeUploadExternal(
*,
files: List[Dict[str, str]],
channel_id: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
**kwargs,
Expand All @@ -3907,6 +3892,8 @@ def files_completeUploadExternal(
"thread_ts": thread_ts,
}
)
if channels:
kwargs["channels"] = ",".join(channels)
return self.api_call("files.completeUploadExternal", params=kwargs)

def functions_completeSuccess(
Expand Down

0 comments on commit ef3975b

Please sign in to comment.