import { SlackAPIClient } from "slack-web-api-client"; import { SlackAppEnv, SlackEdgeAppEnv, SlackSocketModeAppEnv } from "./app-env"; import { Assistant, AssistantBotMessageHandler, AssistantThreadContextChangedHandler, AssistantThreadStartedHandler, AssistantUserMessageHandler } from "./assistant/assistant"; import { AssistantThreadContextStore } from "./assistant/thread-context-store"; import { Authorize } from "./authorization/authorize"; import { AuthorizeErrorHandler } from "./authorization/authorize-error-handler"; import { ExecutionContext } from "./execution-context"; import { BlockActionAckHandler, BlockActionLazyHandler, BlockSuggestionAckHandler, EventLazyHandler, GlobalShortcutAckHandler, GlobalShortcutLazyHandler, MessageEventLazyHandler, MessageShortcutAckHandler, MessageShortcutLazyHandler, ShortcutAckHandler, ShortcutLazyHandler, SlashCommandAckHandler, SlashCommandLazyHandler, SourceSpecifiedBlockActionAckHandler, SourceSpecifiedBlockActionLazyHandler, ViewAckHandler, ViewClosedAckHandler, ViewClosedLazyHandler, ViewLazyHandler, ViewSubmissionAckHandler, ViewSubmissionLazyHandler, AppRateLimitedLazyHandler } from "./handler/handler"; import { Middleware, PreAuthorizeMiddleware } from "./middleware/middleware"; import { BlockAction, BlockElementActions, BlockElementTypes } from "./request/payload/block-action"; import { AnySlackEvent, AnySlackEventWithChannelId, SupportedEventType } from "./request/payload/event"; import { SlackRequest, SlackRequestWithChannelId } from "./request/request"; import { SocketModeClient } from "./socket-mode/socket-mode-client"; /** * Options for initializing SlackApp instance. */ export interface SlackAppOptions { /** * Passed env variables for configuring the app. */ env: E; /** * The function that resolves the OAuth token associated with an incoming request. */ authorize?: Authorize; /** * The hoook that handles authorization failure. */ authorizeErrorHandler?: AuthorizeErrorHandler; /** * The endpoint routes to handle requests from Slack's API server. * When this app connects to Slack through Socket Mode, this setting won't be used. */ routes?: { events: string; }; /** * True when Socket Mode is enabled. */ socketMode?: boolean; /** * When this is set to true, all lazy listeners are invoked after the ack function completion. * The default is set to false. */ startLazyListenerAfterAck?: boolean; /** * When this is set to false, the built-in ignoringSelfEvents middleware is disabled. * The default is set to true. */ ignoreSelfEvents?: boolean; /** * When this is set to false, the built-in ignoringSelfEvents middleware does not block this app's assistant bot message event. * The default is set to true. */ ignoreSelfAssistantMessageEvents?: boolean; /** * Your custom assistant thread context store implementation. */ assistantThreadContextStore?: AssistantThreadContextStore; } /** * The class representing a Slack app process that handles requests from Slack's API server. */ export declare class SlackApp { #private; /** * Passed env variables for configuring the app. */ env: E; /** * The singleton SlackAPIClient instance that embodies a bot token. * SlackOAuthApp initializes this property without a token. */ client: SlackAPIClient; /** * The function that resolves the OAuth token associated with an incoming request. */ authorize: Authorize; /** * The hoook that handles authorization failure. */ authorizeErrorHandler: AuthorizeErrorHandler; /** * The endpoint routes to handle requests from Slack's API server. * When this app connects to Slack through Socket Mode, this setting won't be used. */ routes: { events: string | undefined; }; /** * The credential used for verifying a request's signature. */ signingSecret: string; /** * The app-level token for Socket Mode. * When Socket Mode is not enabled, this can be undefined. */ appLevelToken: string | undefined; /** * True when Socket Mode is enabled. */ socketMode: boolean; /** * The underlying Socket Mode client * that manages WebSocket connections and dispatches messages from Slack. */ socketModeClient: SocketModeClient | undefined; /** * When this is set to true, all lazy listeners are invoked after the ack function completion. * The default is set to false. */ startLazyListenerAfterAck: boolean; /** * When this is set to false, the built-in ignoringSelfEvents middleware is disabled. * The default is set to true. */ ignoreSelfEvents: boolean; /** * The custom middleware that are called before authorize() function. */ preAuthorizeMiddleware: PreAuthorizeMiddleware[]; /** * The custom middleware that are called after authorize() function. */ postAuthorizeMiddleware: Middleware[]; eventsToSkipAuthorize: string[]; /** * Your custom assistant thread context store implementation. */ assistantThreadContextStore?: AssistantThreadContextStore; constructor(options: SlackAppOptions); /** * Registers a pre-authorize middleware. * @param middleware middleware * @returns this instance */ beforeAuthorize(middleware: PreAuthorizeMiddleware): SlackApp; /** * Registers a post-authorize middleware. This naming is for consistency with bolt-js. * @param middleware middleware * @returns this instance */ middleware(middleware: Middleware): SlackApp; /** * Registers a post-authorize middleware. This naming is for consistency with bolt-js. * @param middleware middleware * @returns this instance */ use(middleware: Middleware): SlackApp; /** * Registers a post-authorize middleware. * @param middleware middleware * @returns this instance */ afterAuthorize(middleware: Middleware): SlackApp; /** * Registers a listener that handles slash command executions. * @param pattern the pattern to match slash command name * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ command(pattern: StringOrRegExp, ack: SlashCommandAckHandler, lazy?: SlashCommandLazyHandler): SlackApp; /** * Registers a listener that handles custom function calls within Workflow Builder. * Please be aware that this feature is still in beta as of April 2024. * @param callbackId the pattern to match callback_id in a payload * @param lazy lazy function that can do anything asynchronously * @returns this instance */ function(callbackId: FunctionExecutedEventCallbackIdPattern, lazy: EventLazyHandler<"function_executed", E>): this; /** * Registers a listener that handles Events API request. * @param event the pattern to match event type in a payload * @param lazy lazy function that can do anything asynchronously * @returns this instance */ event(event: Type, lazy: EventLazyHandler): SlackApp; assistant(assistant: Assistant): SlackApp; assistantThreadStarted(lazy: AssistantThreadStartedHandler): SlackApp; assistantThreadContextChanged(lazy: AssistantThreadContextChangedHandler): SlackApp; assistantUserMessage(lazy: AssistantUserMessageHandler): SlackApp; assistantBotMessage(lazy: AssistantBotMessageHandler): SlackApp; /** * Registers a listener that handles all newly posted message events. * @param lazy lazy function that can do anything asynchronously * @returns this instance */ anyMessage(lazy: MessageEventLazyHandler): SlackApp; /** * Registers a listener that handles newly posted message events that matches the pattern. * @param pattern the pattern to match a message event's text * @param lazy lazy function that can do anything asynchronously * @returns this instance */ message(pattern: MessageEventPattern, lazy: MessageEventLazyHandler): SlackApp; /** * Registers a listener that handles global/message shortcut executions. * @param callbackId the pattern to match callback_id in a payload * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ shortcut(callbackId: StringOrRegExp, ack: ShortcutAckHandler, lazy?: ShortcutLazyHandler): SlackApp; /** * Registers a listener that handles global shortcut executions. * @param callbackId the pattern to match callback_id in a payload * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ globalShortcut(callbackId: StringOrRegExp, ack: GlobalShortcutAckHandler, lazy?: GlobalShortcutLazyHandler): SlackApp; /** * Registers a listener that handles message shortcut executions. * @param callbackId the pattern to match callback_id in a payload * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ messageShortcut(callbackId: StringOrRegExp, ack: MessageShortcutAckHandler, lazy?: MessageShortcutLazyHandler): SlackApp; /** * Registers a listener that handles type: "block_actions" requests. * @param constraints the constraints to match block_id/action_id in a payload * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ action> = BlockAction>>(constraints: StringOrRegExp | { type: T; block_id?: string; action_id: string; }, ack: BlockActionAckHandler | SourceSpecifiedBlockActionAckHandler, lazy?: BlockActionLazyHandler | SourceSpecifiedBlockActionLazyHandler): SlackApp; /** * Registers a listener that handles type: "block_suggestion" requests. * Note that your app must return the options/option_groups within 3 seconds, * so slack-edge intentionally does not accept lazy here. * @param constraints the constraints to match block_id/action_id in a payload * @param ack ack function that must complete within 3 seconds * @returns this instance */ options(constraints: StringOrRegExp | { block_id?: string; action_id: string; }, ack: BlockSuggestionAckHandler): SlackApp; /** * Registers a listener that handles type: "view_submission"/"view_closed" requests. * @param callbackId the constraints to match callback_id in a payload * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ view(callbackId: StringOrRegExp, ack: ViewAckHandler, lazy?: ViewLazyHandler): SlackApp; /** * Registers a listener that handles type: "view_submission" requests. * @param callbackId the constraints to match callback_id in a payload * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ viewSubmission(callbackId: StringOrRegExp, ack: ViewSubmissionAckHandler, lazy?: ViewSubmissionLazyHandler): SlackApp; /** * Registers a listener that handles type: "view_closed" requests. * @param callbackId the constraints to match callback_id in a payload * @param ack ack function that must complete within 3 seconds * @param lazy lazy function that can do anything asynchronously * @returns this instance */ viewClosed(callbackId: StringOrRegExp, ack: ViewClosedAckHandler, lazy?: ViewClosedLazyHandler): SlackApp; /** * Registers a single listener that handles type: "app_rate_limited" requests. * @param lazy lazy function that can do anything asynchronously * @returns this instance */ appRateLimited(lazy: AppRateLimitedLazyHandler): SlackApp; /** * Handles an http request and returns a response to it. * @param request request * @param ctx execution context * @returns response */ run(request: Request, ctx?: ExecutionContext): Promise; /** * Establishes a WebSocket connection for Socket Mode. */ connect(): Promise; /** * Disconnect a WebSocket connection for Socket Mode. */ disconnect(): Promise; /** * Handles an HTTP request from Slack's API server and returns a response to it. * @param request request * @param ctx execution context * @returns response */ handleEventRequest(request: Request, ctx: ExecutionContext): Promise; } export type StringOrRegExp = string | RegExp; export type MessageEventPattern = string | RegExp | undefined; /** * Events API request */ export type EventRequest = Extract extends never ? SlackRequest> : SlackRequestWithChannelId>; /** * Events API: "function_executed" event for custom functions in Workflow Builder */ export type FunctionExecutedEventCallbackIdPattern = string | RegExp | undefined; /** * Events API: "message" event */ export type MessageEventRequest = SlackRequestWithChannelId>; export type MessageEventSubtypes = undefined | "bot_message" | "thread_broadcast" | "file_share"; /** * Handler function for "message" events */ export type MessageEventHandler = (req: MessageEventRequest) => Promise; /** * Singleton lazy listener that does not do anything */ export declare const noopLazyHandler: () => Promise; //# sourceMappingURL=app.d.ts.map