Registry / communication / slack-web-api-client

slack-web-api-client

JSON →
library1.1.11jsnpmunverified

The `slack-web-api-client` is a fetch-based, type-safe client library for interacting with the Slack Web API, designed for broad runtime compatibility across environments like Node.js, Deno, and Cloudflare Workers. Currently stable at version 1.1.11, it is part of the `slack-edge` ecosystem and is utilized internally by the `slack-edge` library itself. A key differentiator is its "zero additional dependencies" approach, minimizing install footprint and potential conflicts, which simplifies integration and reduces supply chain risks. It provides strong TypeScript types for all API responses and Block Kit elements, significantly enhancing the developer experience with predictive coding and robust error checking. The project appears to be actively maintained, with updates available via `npm i slack-web-api-client@latest`. Its fetch-based implementation makes it highly portable, a significant advantage over clients relying on Node.js-specific HTTP modules.

npm install slack-web-api-client
INSTALL
IMPORT
SIG · SLACK-WEB-API-CLIE
S
slack-web-api-client
communicationjavascriptv1.1.11
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SlackAPIClient
import { SlackAPIClient } from 'slack-web-api-client';
const SlackAPIClient = require('slack-web-api-client').SlackAPIClient;
Primary class for interacting with the Slack Web API. Use ESM import for modern TypeScript/JavaScript projects.
SlackAPIError
import { SlackAPIError } from 'slack-web-api-client';
import SlackAPIError from 'slack-web-api-client/errors';
Import this class for handling specific errors thrown by the client. The client throws this error by default on API failures (when `ok: false`).
WebClientOptions
import { WebClientOptions } from 'slack-web-api-client';
import { Options } from 'slack-web-api-client';
Type definition for the optional configuration object passed to the SlackAPIClient constructor.

This quickstart demonstrates how to instantiate the SlackAPIClient, configure it, and use it to post a message with Block Kit to a specified Slack channel, including basic error handling.

import { SlackAPIClient } from "slack-web-api-client"; // Ensure SLACK_BOT_TOKEN is set in your environment const token = process.env.SLACK_BOT_TOKEN ?? ''; const client = new SlackAPIClient(token, { // Log level can be set to 'DEBUG', 'INFO' (default), 'WARN', 'ERROR' logLevel: "INFO", // By default, the client throws SlackAPIError for API failures (ok: false) throwSlackAPIError: true }); async function postGreeting() { if (!token) { console.error('SLACK_BOT_TOKEN environment variable is not set.'); return; } try { const response = await client.chat.postMessage({ channel: "#general", // Replace with your desired channel ID or name text: ":wave: Hello from slack-web-api-client!", blocks: [ { "type": "section", "text": { "type": "mrkdwn", "text": "Hey there! I just posted this message using the `slack-web-api-client` library. :rocket:" } }, { "type": "actions", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "View GitHub" }, "url": "https://github.com/slack-edge/slack-web-api-client" } ] } ] }); console.log('Message posted:', response.ts); } catch (error) { if (error instanceof SlackAPIClient) { console.error('Slack API Error:', error.code, error.response); } else { console.error('An unexpected error occurred:', error); } } } postGreeting();
Debug
Known issues
gotchaBy default, the `SlackAPIClient` is configured to throw a `SlackAPIError` when a Slack API call returns `ok: false` in its response. Developers accustomed to checking the `ok` property directly or receiving a structured error object without an exception might find this behavior unexpected.
fix
To handle API failures without exceptions, set `throwSlackAPIError: false` in the client's constructor options: `new SlackAPIClient(token, { throwSlackAPIError: false })`. Alternatively, wrap your API calls in `try...catch` blocks to catch `SlackAPIError` instances.
affects: >=1.0.0
gotchaThe client requires a valid Slack Bot Token (e.g., `xoxb-YOUR_TOKEN`) or User Token (e.g., `xoxp-YOUR_TOKEN`) for authentication. Using an invalid, expired, or improperly scoped token will result in API errors.
fix
Ensure the `process.env.SLACK_BOT_TOKEN` (or equivalent) environment variable is correctly set with a valid token and that the associated bot or user has the necessary OAuth scopes for the API methods you are calling.
affects: >=1.0.0
gotchaWhile the library is fetch-based and designed for various runtimes, specific runtime environments (like Cloudflare Workers or Deno) may require slightly different setup or polyfills for `process.env` access, depending on how environment variables are exposed.
fix
Consult the specific runtime's documentation for handling environment variables. For Deno, refer to the Deno-specific README provided by the library. For Cloudflare Workers, use Worker-native ways to access secrets (e.g., `env.SLACK_BOT_TOKEN`).
affects: >=1.0.0
Errors
Common errors & fixes
SlackAPIError: The request to the Slack API failed. (response: { ok: false, error: 'invalid_auth' })
The Slack API token provided to the client is missing, invalid, or has insufficient scopes.
fix
Verify that your `SLACK_BOT_TOKEN` environment variable (or hardcoded token) is correctly set and starts with `xoxb-` or `xoxp-`. Ensure your Slack app has the necessary OAuth scopes for the API method being called (e.g., `chat:write` for `chat.postMessage`).
TypeError: client.chat is not a function
This error typically indicates that the `SlackAPIClient` instance was not properly initialized or the method chain is incorrect.
fix
Double-check that `new SlackAPIClient(token)` was called with a valid token. Confirm that the API method path (e.g., `chat.postMessage`) matches the Slack Web API documentation and the client's exposed methods.
Upgrade
Version history
1.1.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
slack-web-api-client — npm install slack-web-api-client · libregistry