CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-slack--web-api

Official library for using the Slack Platform's Web API

Pending
Overview
Eval results
Files

client-configuration.mddocs/

Client Configuration

WebClient initialization and configuration options for authentication, networking, and behavior customization.

Capabilities

WebClient Constructor

Creates a new WebClient instance with optional authentication token and configuration options.

/**
 * Creates a new WebClient instance
 * @param token - Slack bot or user token (starts with xoxb- or xoxp-)
 * @param options - Configuration options for the client
 */
class WebClient {
  constructor(token?: string, options?: WebClientOptions);
}

Usage Examples:

import { WebClient, LogLevel } from "@slack/web-api";

// Basic initialization with token
const web = new WebClient(process.env.SLACK_BOT_TOKEN);

// With configuration options
const web = new WebClient(process.env.SLACK_BOT_TOKEN, {
  logLevel: LogLevel.DEBUG,
  timeout: 30000,
  maxRequestConcurrency: 10
});

// Without token (must pass token with each call)
const web = new WebClient();
const result = await web.apiCall('auth.test', { token: 'xoxb-...' });

WebClientOptions Interface

Configuration options for customizing WebClient behavior.

interface WebClientOptions {
  /** Base URL for API requests (default: https://slack.com/api/) */
  slackApiUrl?: string;
  /** Custom logger instance */
  logger?: Logger;
  /** Logging verbosity level */
  logLevel?: LogLevel;
  /** Maximum concurrent requests (default: 100) */
  maxRequestConcurrency?: number;
  /** Retry policy configuration */
  retryConfig?: RetryOptions;
  /** HTTP agent for requests */
  agent?: Agent;
  /** TLS/SSL configuration */
  tls?: TLSOptions;
  /** Request timeout in milliseconds */
  timeout?: number;
  /** Whether to reject rate-limited calls instead of retrying */
  rejectRateLimitedCalls?: boolean;
  /** Default HTTP headers to include in all requests */
  headers?: Record<string, string>;
  /** Slack team/workspace ID */
  teamId?: string;
  /** Allow absolute URLs in method names (default: true) */
  allowAbsoluteUrls?: boolean;
  /** Include original error in exceptions (default: true) */
  attachOriginalToWebAPIRequestError?: boolean;
  /** Custom request interceptor function */
  requestInterceptor?: RequestInterceptor;
  /** Custom HTTP adapter configuration */
  adapter?: AdapterConfig;
}

Logging Configuration

Configure logging behavior for debugging and monitoring.

interface Logger {
  debug(...msgs: any[]): void;
  info(...msgs: any[]): void;
  warn(...msgs: any[]): void;
  error(...msgs: any[]): void;
  setLevel(level: LogLevel): void;
  setName(name: string): void;
}

enum LogLevel {
  ERROR = 'error',
  WARN = 'warn', 
  INFO = 'info',
  DEBUG = 'debug'
}

Usage Examples:

import { WebClient, LogLevel } from "@slack/web-api";

// Built-in logging levels
const web = new WebClient(token, {
  logLevel: LogLevel.DEBUG // Will log all requests and responses
});

// Custom logger
const customLogger = {
  debug: (msg) => console.log(`[DEBUG] ${msg}`),
  info: (msg) => console.log(`[INFO] ${msg}`),
  warn: (msg) => console.warn(`[WARN] ${msg}`),
  error: (msg) => console.error(`[ERROR] ${msg}`)
};

const web = new WebClient(token, { logger: customLogger });

Retry Configuration

Configure automatic retry behavior for failed requests.

interface RetryOptions {
  /** Number of retry attempts */
  retries?: number;
  /** Factor by which delay increases after each retry */
  factor?: number;
  /** Minimum delay between retries in milliseconds */
  minTimeout?: number;
  /** Maximum delay between retries in milliseconds */
  maxTimeout?: number;
  /** Whether to randomize retry delays */
  randomize?: boolean;
}

Pre-defined Retry Policies:

/** Default policy: 10 retries over approximately 30 minutes */
const tenRetriesInAboutThirtyMinutes: RetryOptions;

/** Shorter policy: 5 retries over 5 minutes */
const fiveRetriesInFiveMinutes: RetryOptions;

/** Fast policy for testing scenarios */
const rapidRetryPolicy: RetryOptions;

Usage Examples:

import { WebClient, retryPolicies } from "@slack/web-api";

// Use pre-defined policy
const web = new WebClient(token, {
  retryConfig: retryPolicies.fiveRetriesInFiveMinutes
});

// Custom retry configuration
const web = new WebClient(token, {
  retryConfig: {
    retries: 3,
    factor: 2,
    minTimeout: 1000,
    maxTimeout: 10000,
    randomize: true
  }
});

Network Configuration

Configure HTTP behavior including timeouts, agents, and TLS settings.

interface TLSOptions extends SecureContextOptions {
  /** Custom TLS/SSL configuration */
}

type RequestInterceptor = (config: RequestConfig) => RequestConfig;
type AdapterConfig = AxiosAdapter;

Usage Examples:

import { WebClient } from "@slack/web-api";
import { Agent } from "node:http";

// Custom HTTP agent with connection pooling
const agent = new Agent({
  keepAlive: true,
  maxSockets: 25
});

const web = new WebClient(token, {
  agent,
  timeout: 30000, // 30 second timeout
  headers: {
    'User-Agent': 'MySlackApp/1.0.0'
  }
});

// Request interceptor for custom headers
const web = new WebClient(token, {
  requestInterceptor: (config) => {
    config.headers['X-Request-ID'] = generateRequestID();
    return config;
  }
});

Rate Limiting Configuration

Configure how the client handles rate limiting from Slack's API.

/** Whether to reject rate-limited calls instead of automatically retrying */
rejectRateLimitedCalls?: boolean;

Usage Examples:

import { WebClient, WebClientEvent } from "@slack/web-api";

// Handle rate limiting manually
const web = new WebClient(token, {
  rejectRateLimitedCalls: true
});

// Listen for rate limit events
web.on(WebClientEvent.RATE_LIMITED, (retryAfter) => {
  console.log(`Rate limited. Retry after ${retryAfter} seconds`);
});

// Automatic retry (default behavior)
const web = new WebClient(token, {
  rejectRateLimitedCalls: false // Default
});

Types

enum WebClientEvent {
  RATE_LIMITED = 'rate_limited'
}

type RequestConfig = InternalAxiosRequestConfig;

Install with Tessl CLI

npx tessl i tessl/npm-slack--web-api

docs

admin-operations.md

authentication-oauth.md

chat-operations.md

client-configuration.md

conversation-management.md

core-api-methods.md

error-handling.md

file-operations.md

index.md

pins.md

reactions.md

search.md

user-groups.md

user-operations.md

views-modals.md

tile.json