Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add channels param to files.upload v2 method #1641

Merged
merged 1 commit into from
Feb 3, 2025
Merged
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
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 @@
# 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 @@
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")

Check warning on line 3782 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3782

Added line #L3782 was not covered by tests

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 @@
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 @@
*,
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 @@
"thread_ts": thread_ts,
}
)
if channels:
kwargs["channels"] = ",".join(channels)

Check warning on line 3894 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3894

Added line #L3894 was not covered by tests
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 @@
# 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 @@
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")

Check warning on line 3772 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3772

Added line #L3772 was not covered by tests

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 @@
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 @@
*,
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 @@
"thread_ts": thread_ts,
}
)
if channels:
kwargs["channels"] = ",".join(channels)

Check warning on line 3884 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3884

Added line #L3884 was not covered by tests
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 @@
# 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 @@
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")

Check warning on line 3784 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3784

Added line #L3784 was not covered by tests

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 @@
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 @@
*,
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 @@
"thread_ts": thread_ts,
}
)
if channels:
kwargs["channels"] = ",".join(channels)

Check warning on line 3896 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3896

Added line #L3896 was not covered by tests
return self.api_call("files.completeUploadExternal", params=kwargs)

def functions_completeSuccess(
Expand Down
Loading