Skip to content

Commit b85bbbf

Browse files
authored
Accept plural fields (user_ids, channels, types) as Lists (#274)
* Updated docs to add rate limiting references * Convert plural field values to strings if needed * Added test for converting plural fields to CSV
1 parent 7e89198 commit b85bbbf

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

slackclient/slackrequest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ def do(self, token, request="?", post_data=None, domain="slack.com", timeout=Non
7676
# Only do this for requests that are UPLOADING files; downloading files
7777
# use the 'file' argument to point to a File ID.
7878
post_data = post_data or {}
79+
80+
# Check for plural fields and convert them to comma-separated strings if needed
81+
for field in {'channels', 'users', 'types'} & set(post_data.keys()):
82+
if isinstance(post_data[field], list):
83+
post_data[field] = ",".join(post_data[field])
84+
85+
# Move singular file objects into `files`
7986
upload_requests = ['files.upload']
8087

8188
files = None

tests/test_slackrequest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ def test_auth_header(mocker):
4242
assert "Bearer xoxb-123" in kwargs['headers']['Authorization']
4343

4444

45+
def test_plural_field(mocker):
46+
requests = mocker.patch('slackclient.slackrequest.requests')
47+
request = SlackRequest()
48+
49+
request.do('xoxb-123','conversations.open', {'users': ['U123', 'U234', 'U345']})
50+
args, kwargs = requests.post.call_args
51+
52+
assert requests.post.call_count == 1
53+
assert 'https://slack.com/api/conversations.open' == args[0]
54+
assert kwargs['data'] == '{"users": "U123,U234,U345"}'
55+
56+
4557
def test_post_file(mocker):
4658
requests = mocker.patch('slackclient.slackrequest.requests')
4759
request = SlackRequest()

0 commit comments

Comments
 (0)