{"id":15825,"library":"slack-web-api-client","title":"Slack Web API Client","description":"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.","status":"active","version":"1.1.11","language":"javascript","source_language":"en","source_url":"https://github.com/slack-edge/slack-web-api-client","tags":["javascript","Slack","ChatBot","TypeScript","Node.js","Deno","Cloudflare Workers","typescript"],"install":[{"cmd":"npm install slack-web-api-client","lang":"bash","label":"npm"},{"cmd":"yarn add slack-web-api-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add slack-web-api-client","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary class for interacting with the Slack Web API. Use ESM import for modern TypeScript/JavaScript projects.","wrong":"const SlackAPIClient = require('slack-web-api-client').SlackAPIClient;","symbol":"SlackAPIClient","correct":"import { SlackAPIClient } from 'slack-web-api-client';"},{"note":"Import this class for handling specific errors thrown by the client. The client throws this error by default on API failures (when `ok: false`).","wrong":"import SlackAPIError from 'slack-web-api-client/errors';","symbol":"SlackAPIError","correct":"import { SlackAPIError } from 'slack-web-api-client';"},{"note":"Type definition for the optional configuration object passed to the SlackAPIClient constructor.","wrong":"import { Options } from 'slack-web-api-client';","symbol":"WebClientOptions","correct":"import { WebClientOptions } from 'slack-web-api-client';"}],"quickstart":{"code":"import { SlackAPIClient } from \"slack-web-api-client\";\n\n// Ensure SLACK_BOT_TOKEN is set in your environment\nconst token = process.env.SLACK_BOT_TOKEN ?? '';\n\nconst client = new SlackAPIClient(token, {\n  // Log level can be set to 'DEBUG', 'INFO' (default), 'WARN', 'ERROR'\n  logLevel: \"INFO\", \n  // By default, the client throws SlackAPIError for API failures (ok: false)\n  throwSlackAPIError: true\n});\n\nasync function postGreeting() {\n  if (!token) {\n    console.error('SLACK_BOT_TOKEN environment variable is not set.');\n    return;\n  }\n  try {\n    const response = await client.chat.postMessage({\n      channel: \"#general\", // Replace with your desired channel ID or name\n      text: \":wave: Hello from slack-web-api-client!\",\n      blocks: [\n        {\n          \"type\": \"section\",\n          \"text\": {\n            \"type\": \"mrkdwn\",\n            \"text\": \"Hey there! I just posted this message using the `slack-web-api-client` library. :rocket:\"\n          }\n        },\n        {\n          \"type\": \"actions\",\n          \"elements\": [\n            {\n              \"type\": \"button\",\n              \"text\": {\n                \"type\": \"plain_text\",\n                \"text\": \"View GitHub\"\n              },\n              \"url\": \"https://github.com/slack-edge/slack-web-api-client\"\n            }\n          ]\n        }\n      ]\n    });\n    console.log('Message posted:', response.ts);\n  } catch (error) {\n    if (error instanceof SlackAPIClient) {\n      console.error('Slack API Error:', error.code, error.response);\n    } else {\n      console.error('An unexpected error occurred:', error);\n    }\n  }\n}\n\npostGreeting();","lang":"typescript","description":"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."},"warnings":[{"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.","message":"By 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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`).","message":"While 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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`).","cause":"The Slack API token provided to the client is missing, invalid, or has insufficient scopes.","error":"SlackAPIError: The request to the Slack API failed. (response: { ok: false, error: 'invalid_auth' })"},{"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.","cause":"This error typically indicates that the `SlackAPIClient` instance was not properly initialized or the method chain is incorrect.","error":"TypeError: client.chat is not a function"}],"ecosystem":"npm"}