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
( # skipcq: PYL-R1710
self,
api_method: str,
*,
http_verb: str = "POST",
files: dict = None,
data: Union[dict, FormData] = None,
params: dict = None,
json: dict = None, # skipcq: PYL-W0621
headers: dict = None,
auth: dict = None,
)
| 68 | self._event_loop = loop |
| 69 | |
| 70 | def api_call( # skipcq: PYL-R1710 |
| 71 | self, |
| 72 | api_method: str, |
| 73 | *, |
| 74 | http_verb: str = "POST", |
| 75 | files: dict = None, |
| 76 | data: Union[dict, FormData] = None, |
| 77 | params: dict = None, |
| 78 | json: dict = None, # skipcq: PYL-W0621 |
| 79 | headers: dict = None, |
| 80 | auth: dict = None, |
| 81 | ) -> Union[asyncio.Future, SlackResponse]: |
| 82 | """Create a request and execute the API call to Slack. |
| 83 | |
| 84 | Args: |
| 85 | api_method (str): The target Slack API method. |
| 86 | e.g. 'chat.postMessage' |
| 87 | http_verb (str): HTTP Verb. e.g. 'POST' |
| 88 | files (dict): Files to multipart upload. |
| 89 | e.g. {image OR file: file_object OR file_path} |
| 90 | data: The body to attach to the request. If a dictionary is |
| 91 | provided, form-encoding will take place. |
| 92 | e.g. {'key1': 'value1', 'key2': 'value2'} |
| 93 | params (dict): The URL parameters to append to the URL. |
| 94 | e.g. {'key1': 'value1', 'key2': 'value2'} |
| 95 | json (dict): JSON for the body to attach to the request |
| 96 | (if files or data is not specified). |
| 97 | e.g. {'key1': 'value1', 'key2': 'value2'} |
| 98 | headers (dict): Additional request headers |
| 99 | auth (dict): A dictionary that consists of client_id and client_secret |
| 100 | |
| 101 | Returns: |
| 102 | (SlackResponse) |
| 103 | The server's response to an HTTP request. Data |
| 104 | from the response can be accessed like a dict. |
| 105 | If the response included 'next_cursor' it can |
| 106 | be iterated on to execute subsequent requests. |
| 107 | |
| 108 | Raises: |
| 109 | SlackApiError: The following Slack API call failed: |
| 110 | 'chat.postMessage'. |
| 111 | SlackRequestError: Json data can only be submitted as |
| 112 | POST requests. |
| 113 | """ |
| 114 | |
| 115 | api_url = _get_url(self.base_url, api_method) |
| 116 | headers = headers or {} |
| 117 | headers.update(self.headers) |
| 118 | |
| 119 | req_args = _build_req_args( |
| 120 | token=self.token, |
| 121 | http_verb=http_verb, |
| 122 | files=files, |
| 123 | data=data, |
| 124 | params=params, |
| 125 | json=json, # skipcq: PYL-W0621 |
| 126 | headers=headers, |
| 127 | auth=auth, |