Skip to content

Commit e55f79a

Browse files
committed
fix(slack): use channel= kwarg for files_upload_v2 (closes #102)
slack-sdk's files_upload_v2 takes channel=, not channel_id=. Passing channel_id= collides with the kwarg slack-sdk adds internally when it forwards to files_completeUploadExternal, raising TypeError on every upload. Adds a regression test pinning the kwarg name. https://claude.ai/code/session_01WArZSuq5JFJwM9ecwqthhX
1 parent 08c42fa commit e55f79a

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/chat_sdk/adapters/slack/adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ async def _upload_files(
26822682
)
26832683

26842684
client = self._get_client()
2685-
kwargs: dict[str, Any] = {"channel_id": channel, "file_uploads": file_uploads}
2685+
kwargs: dict[str, Any] = {"channel": channel, "file_uploads": file_uploads}
26862686
if thread_ts:
26872687
kwargs["thread_ts"] = thread_ts
26882688

tests/test_slack_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,32 @@ async def test_file_only_post_returns_file_id(self):
236236
# chat_postMessage should not have been called
237237
assert len(client.get_calls("chat_postMessage")) == chat_post_calls_before
238238

239+
@pytest.mark.asyncio
240+
async def test_file_upload_uses_channel_kwarg_not_channel_id(self):
241+
"""Regression: slack-sdk's files_upload_v2 takes ``channel=``, not ``channel_id=``.
242+
243+
Passing ``channel_id=`` collides with the kwarg slack-sdk adds internally
244+
when it forwards to files_completeUploadExternal, raising a TypeError on
245+
every upload. See issue #102.
246+
"""
247+
adapter, client, _ = await _init_adapter()
248+
client.set_response("files_upload_v2", {"ok": True, "files": [{"files": [{"id": "F999"}]}]})
249+
250+
from chat_sdk.types import FileUpload, PostableMarkdown
251+
252+
msg = PostableMarkdown(
253+
markdown="",
254+
files=[FileUpload(data=b"hello", filename="test.txt")],
255+
)
256+
await adapter.post_message("slack:C789:1234567890.000000", msg)
257+
258+
upload_calls = client.get_calls("files_upload_v2")
259+
assert len(upload_calls) == 1
260+
kwargs = upload_calls[0]["kwargs"]
261+
assert kwargs["channel"] == "C789"
262+
assert "channel_id" not in kwargs
263+
assert kwargs["thread_ts"] == "1234567890.000000"
264+
239265
@pytest.mark.asyncio
240266
async def test_thread_reply(self):
241267
"""postMessage to a thread should include thread_ts."""

0 commit comments

Comments
 (0)