Skip to content

Commit 19d5052

Browse files
authored
Fix WebClient#files_upload does not send channels since v3.10.0 (#1106)
1 parent 550ee24 commit 19d5052

File tree

3 files changed

+41
-38
lines changed

3 files changed

+41
-38
lines changed

slack_sdk/web/async_client.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,29 +2848,30 @@ async def files_upload(
28482848
"You cannot specify both the file and the content argument."
28492849
)
28502850

2851-
if file:
2852-
if "filename" not in kwargs and isinstance(file, str):
2853-
# use the local filename if filename is missing
2854-
kwargs["filename"] = file.split(os.path.sep)[-1]
2855-
return await self.api_call(
2856-
"files.upload", files={"file": file}, data=kwargs
2857-
)
2858-
data = kwargs.copy()
2859-
data.update(
2851+
if isinstance(channels, (list, Tuple)):
2852+
kwargs.update({"channels": ",".join(channels)})
2853+
else:
2854+
kwargs.update({"channels": channels})
2855+
kwargs.update(
28602856
{
2861-
"content": content,
28622857
"filename": filename,
28632858
"filetype": filetype,
28642859
"initial_comment": initial_comment,
28652860
"thread_ts": thread_ts,
28662861
"title": title,
28672862
}
28682863
)
2869-
if isinstance(channels, (list, Tuple)):
2870-
kwargs.update({"channels": ",".join(channels)})
2864+
if file:
2865+
if "filename" not in kwargs and isinstance(file, str):
2866+
# use the local filename if filename is missing
2867+
if kwargs.get("filename") is None:
2868+
kwargs["filename"] = file.split(os.path.sep)[-1]
2869+
return await self.api_call(
2870+
"files.upload", files={"file": file}, data=kwargs
2871+
)
28712872
else:
2872-
kwargs.update({"channels": channels})
2873-
return await self.api_call("files.upload", data=data)
2873+
kwargs["content"] = content
2874+
return await self.api_call("files.upload", data=kwargs)
28742875

28752876
# --------------------------
28762877
# Deprecated: groups.*

slack_sdk/web/client.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,27 +2797,28 @@ def files_upload(
27972797
"You cannot specify both the file and the content argument."
27982798
)
27992799

2800-
if file:
2801-
if "filename" not in kwargs and isinstance(file, str):
2802-
# use the local filename if filename is missing
2803-
kwargs["filename"] = file.split(os.path.sep)[-1]
2804-
return self.api_call("files.upload", files={"file": file}, data=kwargs)
2805-
data = kwargs.copy()
2806-
data.update(
2800+
if isinstance(channels, (list, Tuple)):
2801+
kwargs.update({"channels": ",".join(channels)})
2802+
else:
2803+
kwargs.update({"channels": channels})
2804+
kwargs.update(
28072805
{
2808-
"content": content,
28092806
"filename": filename,
28102807
"filetype": filetype,
28112808
"initial_comment": initial_comment,
28122809
"thread_ts": thread_ts,
28132810
"title": title,
28142811
}
28152812
)
2816-
if isinstance(channels, (list, Tuple)):
2817-
kwargs.update({"channels": ",".join(channels)})
2813+
if file:
2814+
if "filename" not in kwargs and isinstance(file, str):
2815+
# use the local filename if filename is missing
2816+
if kwargs.get("filename") is None:
2817+
kwargs["filename"] = file.split(os.path.sep)[-1]
2818+
return self.api_call("files.upload", files={"file": file}, data=kwargs)
28182819
else:
2819-
kwargs.update({"channels": channels})
2820-
return self.api_call("files.upload", data=data)
2820+
kwargs["content"] = content
2821+
return self.api_call("files.upload", data=kwargs)
28212822

28222823
# --------------------------
28232824
# Deprecated: groups.*

slack_sdk/web/legacy_client.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,27 +2808,28 @@ def files_upload(
28082808
"You cannot specify both the file and the content argument."
28092809
)
28102810

2811-
if file:
2812-
if "filename" not in kwargs and isinstance(file, str):
2813-
# use the local filename if filename is missing
2814-
kwargs["filename"] = file.split(os.path.sep)[-1]
2815-
return self.api_call("files.upload", files={"file": file}, data=kwargs)
2816-
data = kwargs.copy()
2817-
data.update(
2811+
if isinstance(channels, (list, Tuple)):
2812+
kwargs.update({"channels": ",".join(channels)})
2813+
else:
2814+
kwargs.update({"channels": channels})
2815+
kwargs.update(
28182816
{
2819-
"content": content,
28202817
"filename": filename,
28212818
"filetype": filetype,
28222819
"initial_comment": initial_comment,
28232820
"thread_ts": thread_ts,
28242821
"title": title,
28252822
}
28262823
)
2827-
if isinstance(channels, (list, Tuple)):
2828-
kwargs.update({"channels": ",".join(channels)})
2824+
if file:
2825+
if "filename" not in kwargs and isinstance(file, str):
2826+
# use the local filename if filename is missing
2827+
if kwargs.get("filename") is None:
2828+
kwargs["filename"] = file.split(os.path.sep)[-1]
2829+
return self.api_call("files.upload", files={"file": file}, data=kwargs)
28292830
else:
2830-
kwargs.update({"channels": channels})
2831-
return self.api_call("files.upload", data=data)
2831+
kwargs["content"] = content
2832+
return self.api_call("files.upload", data=kwargs)
28322833

28332834
# --------------------------
28342835
# Deprecated: groups.*

0 commit comments

Comments
 (0)