Official library for using the Slack Platform's Web API
npx @tessl/cli install tessl/npm-slack--web-api@7.10.0The @slack/web-api package is the official Node.js SDK for interacting with Slack's Web API. It provides a comprehensive WebClient class that handles authentication, automatic retries, rate limiting, pagination, and error management for accessing over 200 Slack API methods. The library supports modern TypeScript with full type safety and includes robust features for production use.
npm install @slack/web-apiimport { WebClient } from "@slack/web-api";For CommonJS:
const { WebClient } = require("@slack/web-api");Additional imports for error handling and configuration:
import {
WebClient,
WebAPICallError,
ErrorCode,
LogLevel
} from "@slack/web-api";import { WebClient } from "@slack/web-api";
// Initialize client with bot token
const web = new WebClient(process.env.SLACK_BOT_TOKEN);
// Post a message
const result = await web.chat.postMessage({
channel: '#general',
text: 'Hello world!'
});
// Get user info
const userInfo = await web.users.info({
user: 'U1234567890'
});
// List conversations
const conversations = await web.conversations.list({
types: 'public_channel,private_channel'
});The Slack Web API library is built around several key components:
chat.*, users.*, conversations.*)Core WebClient initialization and configuration options for authentication, networking, and behavior customization.
class WebClient {
constructor(token?: string, options?: WebClientOptions);
}
interface WebClientOptions {
slackApiUrl?: string;
logger?: Logger;
logLevel?: LogLevel;
maxRequestConcurrency?: number;
retryConfig?: RetryOptions;
agent?: Agent;
tls?: TLSOptions;
timeout?: number;
rejectRateLimitedCalls?: boolean;
headers?: Record<string, string>;
teamId?: string;
}Essential WebClient methods for making API calls, handling pagination, and uploading files.
apiCall(method: string, options?: Record<string, unknown>): Promise<WebAPICallResult>;
paginate(method: string, options?: Record<string, unknown>): AsyncIterable<WebAPICallResult>;
filesUploadV2(options: FilesUploadV2Arguments): Promise<WebAPICallResult>;Send, update, delete, and schedule messages in Slack channels and direct messages.
chat.postMessage(options: ChatPostMessageArguments): Promise<ChatPostMessageResponse>;
chat.update(options: ChatUpdateArguments): Promise<ChatUpdateResponse>;
chat.delete(options: ChatDeleteArguments): Promise<ChatDeleteResponse>;
chat.scheduleMessage(options: ChatScheduleMessageArguments): Promise<ChatScheduleMessageResponse>;Create, manage, and interact with Slack channels, groups, and direct messages.
conversations.create(options: ConversationsCreateArguments): Promise<ConversationsCreateResponse>;
conversations.list(options?: ConversationsListArguments): Promise<ConversationsListResponse>;
conversations.info(options: ConversationsInfoArguments): Promise<ConversationsInfoResponse>;
conversations.members(options: ConversationsMembersArguments): Promise<ConversationsMembersResponse>;Retrieve user information, manage user profiles, and handle user presence.
users.info(options: UsersInfoArguments): Promise<UsersInfoResponse>;
users.list(options?: UsersListArguments): Promise<UsersListResponse>;
users.profile.get(options?: UsersProfileGetArguments): Promise<UsersProfileGetResponse>;
users.profile.set(options: UsersProfileSetArguments): Promise<UsersProfileSetResponse>;Upload files, manage file permissions, and interact with Slack's file storage system.
files.uploadV2(options: FilesUploadV2Arguments): Promise<WebAPICallResult>;
files.info(options: FilesInfoArguments): Promise<FilesInfoResponse>;
files.list(options?: FilesListArguments): Promise<FilesListResponse>;
files.delete(options: FilesDeleteArguments): Promise<FilesDeleteResponse>;Enterprise Grid administration including user management, team settings, and policy enforcement.
admin.users.invite(options: AdminUsersInviteArguments): Promise<AdminUsersInviteResponse>;
admin.conversations.create(options: AdminConversationsCreateArguments): Promise<AdminConversationsCreateResponse>;
admin.teams.create(options: AdminTeamsCreateArguments): Promise<AdminTeamsCreateResponse>;Handle OAuth flows, token management, and authentication verification.
auth.test(): Promise<AuthTestResponse>;
oauth.v2.access(options: OauthV2AccessArguments): Promise<OauthV2AccessResponse>;
oauth.v2.exchange(options: OauthV2ExchangeArguments): Promise<OauthV2ExchangeResponse>;Open, update, and manage interactive modals and home tabs for rich user interfaces.
views.open(options: ViewsOpenArguments): Promise<ViewsOpenResponse>;
views.push(options: ViewsPushArguments): Promise<ViewsPushResponse>;
views.update(options: ViewsUpdateArguments): Promise<ViewsUpdateResponse>;
views.publish(options: ViewsPublishArguments): Promise<ViewsPublishResponse>;Add, remove, and retrieve emoji reactions on messages, files, and file comments.
reactions.add(options: ReactionsAddArguments): Promise<ReactionsAddResponse>;
reactions.get(options: ReactionsGetArguments): Promise<ReactionsGetResponse>;
reactions.list(options?: ReactionsListArguments): Promise<ReactionsListResponse>;
reactions.remove(options: ReactionsRemoveArguments): Promise<ReactionsRemoveResponse>;Search for messages, files, and content across the Slack workspace with flexible query options.
search.all(options: SearchAllArguments): Promise<SearchAllResponse>;
search.files(options: SearchFilesArguments): Promise<SearchFilesResponse>;
search.messages(options: SearchMessagesArguments): Promise<SearchMessagesResponse>;Pin and unpin messages in channels, and retrieve lists of pinned items.
pins.add(options: PinsAddArguments): Promise<PinsAddResponse>;
pins.list(options: PinsListArguments): Promise<PinsListResponse>;
pins.remove(options: PinsRemoveArguments): Promise<PinsRemoveResponse>;Create, manage, and configure user groups for organizing team members and permissions.
usergroups.create(options: UsergroupsCreateArguments): Promise<UsergroupsCreateResponse>;
usergroups.disable(options: UsergroupsDisableArguments): Promise<UsergroupsDisableResponse>;
usergroups.enable(options: UsergroupsEnableArguments): Promise<UsergroupsEnableResponse>;
usergroups.list(options?: UsergroupsListArguments): Promise<UsergroupsListResponse>;
usergroups.update(options: UsergroupsUpdateArguments): Promise<UsergroupsUpdateResponse>;
usergroups.users.list(options: UsergroupsUsersListArguments): Promise<UsergroupsUsersListResponse>;
usergroups.users.update(options: UsergroupsUsersUpdateArguments): Promise<UsergroupsUsersUpdateResponse>;Comprehensive error types and handling strategies for different failure scenarios.
enum ErrorCode {
RequestError = 'slack_webapi_request_error',
HTTPError = 'slack_webapi_http_error',
PlatformError = 'slack_webapi_platform_error',
RateLimitedError = 'slack_webapi_rate_limited_error'
}
interface WebAPICallError extends CodedError {
code: ErrorCode;
}interface WebAPICallResult {
ok: boolean;
error?: string;
response_metadata?: {
warnings?: string[];
next_cursor?: string;
scopes?: string[];
};
}
interface CodedError extends NodeJS.ErrnoException {
code: ErrorCode;
}
type PageReducer<A = any> = (accumulator: A | undefined, page: WebAPICallResult) => A;
type PaginatePredicate = (page: WebAPICallResult) => boolean;