import EventEmitter = require('eventemitter3'); import { AgentOption, TLSOptions } from './util'; import { CodedError, ErrorCode } from './errors'; import { LogLevel, LoggingFunc } from './logger'; import { RetryOptions } from './retry-policies'; import Method, * as methods from './methods'; /** * A client for Slack's Web API * * This client provides an alias for each {@link https://api.slack.com/methods|Web API method}. Each method is * a convenience wrapper for calling the {@link WebClient#apiCall} method using the method name as the first parameter. */ export declare class WebClient extends EventEmitter { /** * Authentication and authorization token for accessing Slack Web API (usually begins with `xoxp`, `xoxb`, or `xoxa`) */ readonly token?: string; /** * The base URL for reaching Slack's Web API. Consider changing this value for testing purposes. */ readonly slackApiUrl: string; /** * Configuration for retry operations. See {@link https://github.com/tim-kos/node-retry|node-retry} for more details. */ private retryConfig; /** * Queue of requests in which a maximum of {@link WebClientOptions.maxRequestConcurrency} can concurrently be * in-flight. */ private requestQueue; /** * An agent used to manage TCP connections for requests. Most commonly used to implement proxy support. See * npm packages `tunnel` and `https-proxy-agent` for information on how to construct a proxy agent. */ private agentConfig?; /** * Configuration for custom TLS handling */ private tlsConfig; /** * The name used to prefix all logging generated from this object */ private static loggerName; /** * This object's logger instance */ private logger; /** * The value for the User-Agent HTTP header (used for instrumentation). */ private userAgent; /** * @param token - An API token to authenticate/authorize with Slack (usually start with `xoxp`, `xoxb`, or `xoxa`) */ constructor(token?: string, {slackApiUrl, logger, logLevel, maxRequestConcurrency, retryConfig, agent, tls}?: WebClientOptions); /** * Generic method for calling a Web API method * * @param method the Web API method to call {@see https://api.slack.com/methods} * @param options options * @param callback callback if you don't want a promise returned */ apiCall(method: string, options?: WebAPICallOptions): Promise; apiCall(method: string, options: WebAPICallOptions, callback: WebAPIResultCallback): void; /** * api method family */ readonly api: { test: Method; }; /** * apps method family */ readonly apps: { permissions: { info: Method; request: Method; }; }; /** * auth method family */ readonly auth: { revoke: Method; test: Method; }; /** * bots method family */ readonly bots: { info: Method; }; /** * channels method family */ readonly channels: { archive: Method; create: Method; history: Method; info: Method; invite: Method; join: Method; kick: Method; leave: Method; list: Method; mark: Method; rename: Method; replies: Method; setPurpose: Method; setTopic: Method; unarchive: Method; }; /** * chat method family */ readonly chat: { delete: Method; getPermalink: Method; meMessage: Method; postEphemeral: Method; postMessage: Method; unfurl: Method; update: Method; }; /** * conversations method family */ readonly conversations: { archive: Method; close: Method; create: Method; history: Method; info: Method; invite: Method; join: Method; kick: Method; leave: Method; list: Method; members: Method; open: Method; rename: Method; replies: Method; setPurpose: Method; setTopic: Method; unarchive: Method; }; /** * dialog method family */ readonly dialog: { open: Method; }; /** * dnd method family */ readonly dnd: { endDnd: Method; endSnooze: Method; info: Method; setSnooze: Method; teamInfo: Method; }; /** * emoji method family */ readonly emoji: { list: Method; }; /** * files method family */ readonly files: { delete: Method; info: Method; list: Method; revokePublicURL: Method; sharedPublicURL: Method; upload: Method; comments: { add: Method; delete: Method; edit: Method; }; }; /** * groups method family */ readonly groups: { archive: Method; create: Method; createChild: Method; history: Method; info: Method; invite: Method; kick: Method; leave: Method; list: Method; mark: Method; open: Method; rename: Method; replies: Method; setPurpose: Method; setTopic: Method; unarchive: Method; }; /** * im method family */ readonly im: { close: Method; history: Method; list: Method; mark: Method; open: Method; replies: Method; }; /** * migration method family */ readonly migration: { exchange: Method; }; /** * mpim method family */ readonly mpim: { close: Method; history: Method; list: Method; mark: Method; open: Method; replies: Method; }; /** * oauth method family */ readonly oauth: { access: Method; token: Method; }; /** * pins method family */ readonly pins: { add: Method; list: Method; remove: Method; }; /** * reactions method family */ readonly reactions: { add: Method; get: Method; list: Method; remove: Method; }; /** * reminders method family */ readonly reminders: { add: Method; complete: Method; delete: Method; info: Method; list: Method; }; /** * rtm method family */ readonly rtm: { connect: Method; start: Method; }; /** * search method family */ readonly search: { all: Method; files: Method; messages: Method; }; /** * stars method family */ readonly stars: { add: Method; list: Method; remove: Method; }; /** * team method family */ readonly team: { accessLogs: Method; billableInfo: Method; info: Method; integrationLogs: Method; profile: { get: Method; }; }; /** * usergroups method family */ readonly usergroups: { create: Method; disable: Method; enable: Method; list: Method; update: Method; users: { list: Method; update: Method; }; }; /** * users method family */ readonly users: { conversations: Method; deletePhoto: Method; getPresence: Method; identity: Method; info: Method; list: Method; lookupByEmail: Method; setActive: Method; setPhoto: Method; setPresence: Method; profile: { get: Method; set: Method; }; }; /** * Transforms options into an object suitable for got to use as a body. This can be one of two things: * - A FormCanBeURLEncoded object, which is just a key-value object where the values have been flattened and * got can serialize it into application/x-www-form-urlencoded content type. * - A BodyCanBeFormMultipart: when the options includes a file, and got must use multipart/form-data content type. * * @param options arguments for the Web API method */ private serializeApiCallOptions(options); /** * Processes an HTTP response into a WebAPICallResult by performing JSON parsing on the body and merging relevent * HTTP headers into the object. * @param response */ private buildResult(response); } export default WebClient; export interface WebClientOptions { slackApiUrl?: string; logger?: LoggingFunc; logLevel?: LogLevel; maxRequestConcurrency?: number; retryConfig?: RetryOptions; agent?: AgentOption; tls?: TLSOptions; } export interface WebAPICallOptions { } export interface WebAPICallResult { ok: boolean; error?: string; scopes?: string[]; acceptedScopes?: string[]; retryAfter?: number; response_metadata?: { warnings?: string[]; }; } export interface WebAPIResultCallback { (error: WebAPICallError, result: WebAPICallResult): void; } export declare type WebAPICallError = WebAPIPlatformError | WebAPIRequestError | WebAPIReadError | WebAPIHTTPError; export interface WebAPIPlatformError extends CodedError { code: ErrorCode.PlatformError; data: WebAPICallResult & { error: string; }; } export interface WebAPIRequestError extends CodedError { code: ErrorCode.RequestError; original: Error; } export interface WebAPIReadError extends CodedError { code: ErrorCode.ReadError; original: Error; } export interface WebAPIHTTPError extends CodedError { code: ErrorCode.HTTPError; original: Error; }