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
| 27 | |
| 28 | |
| 29 | class 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: |
no outgoing calls