Skip to content

Commit 5f6e525

Browse files
committed
Add support for nested structure, e.g. attachments.
> The optional attachments argument should contain a JSON-encoded array of > attachments. > > https://api.slack.com/methods/chat.postMessage This enables simpler calls like this: sc.api_call('chat.postMessage', {'attachments': [{'title': 'hello'}]})
1 parent 4fc299f commit 5f6e525

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

slackclient/_slackrequest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import requests
23

34

@@ -6,7 +7,12 @@ class SlackRequest(object):
67
@staticmethod
78
def do(token, request="?", post_data=None, domain="slack.com"):
89
post_data = post_data or {}
9-
return requests.post(
10-
'https://{0}/api/{1}'.format(domain, request),
11-
data=dict(post_data, token=token),
12-
)
10+
11+
for k, v in post_data.items():
12+
if not isinstance(v, (str, unicode)):
13+
post_data[k] = json.dumps(v)
14+
15+
url = 'https://{0}/api/{1}'.format(domain, request)
16+
post_data['token'] = token
17+
18+
return requests.post(url, data=post_data)

0 commit comments

Comments
 (0)