From ef3975b9d65db1168ecd603e23f75496f9e3d490 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Mon, 3 Feb 2025 15:32:45 +0900 Subject: [PATCH] Add channels param to files.upload v2 method (#1641) --- slack_sdk/web/async_client.py | 27 +++++++-------------------- slack_sdk/web/client.py | 27 +++++++-------------------- slack_sdk/web/legacy_client.py | 27 +++++++-------------------- 3 files changed, 21 insertions(+), 60 deletions(-) diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py index 914cdc34..b7ea4077 100644 --- a/slack_sdk/web/async_client.py +++ b/slack_sdk/web/async_client.py @@ -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 @@ -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.") @@ -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, @@ -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, @@ -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( diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py index 85923004..55e9763d 100644 --- a/slack_sdk/web/client.py +++ b/slack_sdk/web/client.py @@ -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 @@ -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.") @@ -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, @@ -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, @@ -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( diff --git a/slack_sdk/web/legacy_client.py b/slack_sdk/web/legacy_client.py index b1b46d42..18f74563 100644 --- a/slack_sdk/web/legacy_client.py +++ b/slack_sdk/web/legacy_client.py @@ -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 @@ -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.") @@ -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, @@ -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, @@ -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(