Create a request and execute the API call to Slack. Args: api_method (str): The target Slack API method. e.g. 'chat.postMessage' http_verb (str): HTTP Verb. e.g. 'POST' files (dict): Files to multipart upload. e.g. {image O
(
self,
api_method: str,
*,
http_verb: str = "POST",
files: Optional[dict] = None,
data: Optional[dict] = None,
params: Optional[dict] = None,
json: Optional[dict] = None,
headers: Optional[dict] = None,
auth: Optional[dict] = None,
)
| 104 | # api call |
| 105 | |
| 106 | def api_call( |
| 107 | self, |
| 108 | api_method: str, |
| 109 | *, |
| 110 | http_verb: str = "POST", |
| 111 | files: Optional[dict] = None, |
| 112 | data: Optional[dict] = None, |
| 113 | params: Optional[dict] = None, |
| 114 | json: Optional[dict] = None, |
| 115 | headers: Optional[dict] = None, |
| 116 | auth: Optional[dict] = None, |
| 117 | ) -> SlackResponse: |
| 118 | """Create a request and execute the API call to Slack. |
| 119 | |
| 120 | Args: |
| 121 | api_method (str): The target Slack API method. |
| 122 | e.g. 'chat.postMessage' |
| 123 | http_verb (str): HTTP Verb. e.g. 'POST' |
| 124 | files (dict): Files to multipart upload. |
| 125 | e.g. {image OR file: file_object OR file_path} |
| 126 | data: The body to attach to the request. If a dictionary is |
| 127 | provided, form-encoding will take place. |
| 128 | e.g. {'key1': 'value1', 'key2': 'value2'} |
| 129 | params (dict): The URL parameters to append to the URL. |
| 130 | e.g. {'key1': 'value1', 'key2': 'value2'} |
| 131 | json (dict): JSON for the body to attach to the request |
| 132 | (if files or data is not specified). |
| 133 | e.g. {'key1': 'value1', 'key2': 'value2'} |
| 134 | headers (dict): Additional request headers |
| 135 | auth (dict): A dictionary that consists of client_id and client_secret |
| 136 | |
| 137 | Returns: |
| 138 | (SlackResponse) |
| 139 | The server's response to an HTTP request. Data |
| 140 | from the response can be accessed like a dict. |
| 141 | If the response included 'next_cursor' it can |
| 142 | be iterated on to execute subsequent requests. |
| 143 | |
| 144 | Raises: |
| 145 | SlackApiError: The following Slack API call failed: |
| 146 | 'chat.postMessage'. |
| 147 | SlackRequestError: Json data can only be submitted as |
| 148 | POST requests. |
| 149 | """ |
| 150 | |
| 151 | api_url = _get_url(self.base_url, api_method) |
| 152 | headers = headers or {} |
| 153 | headers.update(self.headers) |
| 154 | req_args = _build_req_args( |
| 155 | token=self.token, |
| 156 | http_verb=http_verb, |
| 157 | files=files, # type: ignore[arg-type] |
| 158 | data=data, # type: ignore[arg-type] |
| 159 | default_params=self.default_params, |
| 160 | params=params, # type: ignore[arg-type] |
| 161 | json=json, # type: ignore[arg-type] |
| 162 | headers=headers, |
| 163 | auth=auth, # type: ignore[arg-type] |
no test coverage detected