MCPcopy
hub / github.com/slackapi/python-slack-sdk / WebClient

Class WebClient

slack_sdk/web/client.py:29–6005  ·  view source on GitHub ↗

A WebClient allows apps to communicate with the Slack Platform's Web API. https://docs.slack.dev/reference/methods The Slack Web API is an interface for querying information from and enacting change in a Slack workspace. This client handles constructing and sending HTTP requests t

Source from the content-addressed store, hash-verified

27
28
29class WebClient(BaseClient):
30 """A WebClient allows apps to communicate with the Slack Platform's Web API.
31
32 https://docs.slack.dev/reference/methods
33
34 The Slack Web API is an interface for querying information from
35 and enacting change in a Slack workspace.
36
37 This client handles constructing and sending HTTP requests to Slack
38 as well as parsing any responses received into a `SlackResponse`.
39
40 Attributes:
41 token (str): A string specifying an `xoxp-*` or `xoxb-*` token.
42 base_url (str): A string representing the Slack API base URL.
43 Default is `'https://slack.com/api/'`
44 timeout (int): The maximum number of seconds the client will wait
45 to connect and receive a response from Slack.
46 Default is 30 seconds.
47 ssl (SSLContext): An [`ssl.SSLContext`][1] instance, helpful for specifying
48 your own custom certificate chain.
49 proxy (str): String representing a fully-qualified URL to a proxy through
50 which to route all requests to the Slack API. Even if this parameter
51 is not specified, if any of the following environment variables are
52 present, they will be loaded into this parameter: `HTTPS_PROXY`,
53 `https_proxy`, `HTTP_PROXY` or `http_proxy`.
54 headers (dict): Additional request headers to attach to all requests.
55
56 Methods:
57 `api_call`: Constructs a request and executes the API call to Slack.
58
59 Example of recommended usage:
60 ```python
61 import os
62 from slack_sdk import WebClient
63
64 client = WebClient(token=os.environ['SLACK_API_TOKEN'])
65 response = client.chat_postMessage(
66 channel='#random',
67 text="Hello world!")
68 assert response["ok"]
69 assert response["message"]["text"] == "Hello world!"
70 ```
71
72 Example manually creating an API request:
73 ```python
74 import os
75 from slack_sdk import WebClient
76
77 client = WebClient(token=os.environ['SLACK_API_TOKEN'])
78 response = client.api_call(
79 api_method='chat.postMessage',
80 json={'channel': '#random','text': "Hello world!"}
81 )
82 assert response["ok"]
83 assert response["message"]["text"] == "Hello world!"
84 ```
85
86 Note:

Callers 15

oauth_callbackFunction · 0.90
uploading_files.pyFile · 0.90
proxy.pyFile · 0.90
slack_appFunction · 0.90
oauth_callbackFunction · 0.90
slack_appFunction · 0.90
oauth_callbackFunction · 0.90
slack_appFunction · 0.90
oauth_callbackFunction · 0.90
steps_from_apps.pyFile · 0.90
oauth_callbackFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_issue_558Method · 0.72
test_cpu_usageMethod · 0.72
test_issue_611Method · 0.72
test_issue_605Method · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72