* Generic method for calling a Web API method * * @param method the Web API method to call {@see https://api.slack.com/methods} * @param options options
(method: string, options?: WebAPICallOptions)
| 138 | * @param options options |
| 139 | */ |
| 140 | public async apiCall(method: string, options?: WebAPICallOptions): Promise<WebAPICallResult> { |
| 141 | this.logger.debug('apiCall() start'); |
| 142 | |
| 143 | if (typeof options === 'string' || typeof options === 'number' || typeof options === 'boolean') { |
| 144 | throw new TypeError(`Expected an options argument but instead received a ${typeof options}`); |
| 145 | } |
| 146 | |
| 147 | const response = await this.makeRequest(method, Object.assign( |
| 148 | { token: this.token }, |
| 149 | options, |
| 150 | )); |
| 151 | const result = this.buildResult(response); |
| 152 | |
| 153 | // log warnings in response metadata |
| 154 | if (result.response_metadata !== undefined && result.response_metadata.warnings !== undefined) { |
| 155 | result.response_metadata.warnings.forEach(this.logger.warn.bind(this.logger)); |
| 156 | } |
| 157 | |
| 158 | if (!result.ok) { |
| 159 | throw platformErrorFromResult(result as (WebAPICallResult & { error: string; })); |
| 160 | } |
| 161 | |
| 162 | return result; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Iterate over the result pages of a cursor-paginated Web API method. This method can return two types of values, |
no test coverage detected