Skip to main content
Module

x/slack_bolt/deps.ts>WebClient

TypeScript framework to build Slack apps in a flash with the latest platform features. Deno port of @slack/bolt
Latest
class WebClient
extends Methods
Re-export
import { WebClient } from "https://deno.land/x/slack_bolt@1.0.0/deps.ts";

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 WebClient#apiCall method using the method name as the first parameter.

Constructors

new
WebClient(token?: string, unnamed 1?: WebClientOptions)

Properties

private
axiodConfig: { baseURL: string; headers: { User-Agent: string; }; transformRequest: ((options: Data, headers?: IHeaderData | undefined) => Data)[]; validateStatus: () => boolean; }
private
logger: Logger

This object's logger instance

private
rejectRateLimitedCalls: boolean

Preference for immediately rejecting API calls which result in a rate-limited response

private
requestQueue: PQueue

Queue of requests in which a maximum of WebClientOptions.maxRequestConcurrency can concurrently be in-flight.

private
retryConfig: RetryOptions

Configuration for retry operations. See node-retry for more details.

private
optional
teamId: string

This object's teamId value

readonly
slackApiUrl: string

The base URL for reaching Slack's Web API. Consider changing this value for testing purposes.

readonly
optional
token: string

Authentication and authorization token for accessing Slack Web API (usually begins with xoxp or xoxb)

Methods

private
buildResult(response: IAxiodResponse): WebAPICallResult

Processes an HTTP response into a WebAPICallResult by performing JSON parsing on the body and merging relevent HTTP headers into the object.

private
makeRequest(
url: string,
body: IData,
headers?: IHeaderData,
): Promise<IAxiodResponse>

Low-level function to make a single API request. handles queuing, retries, and http-level errors

private
serializeApiCallOptions(options: Data, headers?: IHeaderData): Data

Transforms options (a simple key-value object) into an acceptable value for a body. This can be either a string, used when posting with a content-type of url-encoded. Or, it can be a readable stream, used when the options contain a binary (a stream or a buffer) and the upload should be done with content-type multipart/form-data.

apiCall(method: string, options?: WebAPICallOptions): Promise<WebAPICallResult>

Generic method for calling a Web API method

paginate(method: string, options?: WebAPICallOptions): AsyncIterable<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.

paginate(
method: string,
options: WebAPICallOptions,
shouldStop: PaginatePredicate,
): Promise<void>
paginate<R extends PageReducer, A extends PageAccumulator<R>>(
method: string,
options: WebAPICallOptions,
shouldStop: PaginatePredicate,
reduce?: PageReducer<A>,
): Promise<A>

Static Properties

private
loggerName: string

The name used to prefix all logging generated from this object