A client for Slack’s Web API
This client provides an alias for each Web API method. Each method is a convenience wrapper for calling the apiCall
method using the method name as the first parameter.
Constructs a new instance of the WebClient
class
Parameters:
Name | Type | Required | Description |
---|---|---|---|
token | string |
✗ | An API token to authenticate/authorize with Slack (usually start with |
opts | WebClientOptions |
✗ | See options. |
Options:
Name | Type | |
---|---|---|
agent | Agent |
|
headers | object |
|
logger | Logger |
|
logLevel | LogLevel |
|
maxRequestConcurrency | number |
|
rejectRateLimitedCalls | boolean |
|
retryConfig | RetryOptions |
|
slackApiUrl | string |
|
tls | TLSOptions |
Name | Type | Description |
---|---|---|
slackApiUrl | string |
The base URL for reaching Slack's Web API. Consider changing this value for testing purposes. |
token | string |
An API token to authenticate/authorize with Slack (usually start with |
Generic method for calling a Web API method
Parameters:
Name | Type | Required | Description |
---|---|---|---|
method | string |
✓ | the Web API method to call https://api.slack.com/methods |
options | WebAPICallOptions |
✗ | options |
Returns Promise<WebAPICallResult>
Iterate over the result pages of a cursor-paginated Web API method. This method can return two types of values, depending on which arguments are used. When up to two parameters are used, the return value is an async iterator which can be used as the iterable in a for-await-of loop. When three or four parameters are used, the return value is a promise that resolves at the end of iteration. The third parameter, shouldStop
, is a function that is called with each page
and can end iteration by returning true
. The fourth parameter, reduce
, is a function that is called with three arguments: accumulator
, page
, and index
. The accumulator
is a value of any type you choose, but it will contain undefined
when reduce
is called for the first time. The page
argument and index
arguments are exactly what they say they are. The reduce
function’s return value will be passed in as accumulator
the next time its called, and the returned promise will resolve to the last value of accumulator
.
The for-await-of syntax is part of ES2018. It is available natively in Node starting with v10.0.0. You may be able to use it in earlier JavaScript runtimes by transpiling your source with a tool like Babel. However, the transpiled code will likely sacrifice performance.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
method | string |
✓ | the cursor-paginated Web API method to call https://api.slack.com/docs/pagination |
options | WebAPICallOptions |
✗ | options |
Returns AsyncIterable<WebAPICallResult>
Parameters:
Name | Type | Required | |
---|---|---|---|
method | string |
✓ | |
options | WebAPICallOptions |
✓ | |
shouldStop | PaginatePredicate |
✓ |
Returns Promise<void>
Parameters:
Name | Type | Required | |
---|---|---|---|
method | string |
✓ | |
options | WebAPICallOptions |
✓ | |
shouldStop | PaginatePredicate |
✓ | |
reduce | PageReducer<A> |
✗ |
Returns Promise<A>
Appends the app metadata into the User-Agent value
Parameters:
Name | Type | Required | |
---|---|---|---|
{ name, version } | object |
✓ |
Returns void
A dictionary of codes for errors produced by this package
All errors produced by this package adhere to this interface
Name | Type | |
---|---|---|
code | ErrorCode |
Name | Type | |
---|---|---|
cursor | string |
|
limit | number |
Name | Type | |
---|---|---|
include_locale | boolean |
Generic method definition
Options to create retry policies. Extends from https://github.com/tim-kos/node-retry.
Name | Type | |
---|---|---|
highlight | boolean |
|
query | string |
|
sort_dir | 'asc' | 'desc' |
|
sort | 'score' | 'timestamp' |
Name | Type | |
---|---|---|
inclusive | boolean |
|
latest | string |
|
oldest | string |
Name | Type | |
---|---|---|
token | string |
Name | Type | |
---|---|---|
count | number |
|
page | number |
Name | Type | |
---|---|---|
error | string |
|
ok | boolean |
|
response_metadata | object |
Name | Type | |
---|---|---|
body | any |
|
code | ErrorCode.HTTPError |
|
headers | IncomingHttpHeaders |
|
statusCode | number |
|
statusMessage | string |
Name | Type | |
---|---|---|
code | ErrorCode.PlatformError |
|
data | WebAPICallResult & {
error: string;
} |
Name | Type | |
---|---|---|
code | ErrorCode.RateLimitedError |
|
retryAfter | number |
Name | Type | |
---|---|---|
code | ErrorCode.RequestError |
|
original | Error |
Name | Type | |
---|---|---|
agent | Agent |
|
headers | object |
|
logger | Logger |
|
logLevel | LogLevel |
|
maxRequestConcurrency | number |
|
rejectRateLimitedCalls | boolean |
|
retryConfig | RetryOptions |
|
slackApiUrl | string |
|
tls | TLSOptions |
R extends (accumulator: (infer A) | undefined, page: WebAPICallResult, index: number) => infer A ? A : never
SecureContextOptions, 'pfx' | 'key' | 'passphrase' | 'cert' | 'ca'>
WebAPIRequestError | WebAPIHTTPError | WebAPIRateLimitedError
One of: