UNPKG

@slack/bolt

Version:

A framework for building Slack apps, fast.

58 lines 3 kB
import type { FunctionExecutedEvent } from '@slack/types'; import { type FunctionsCompleteErrorResponse, type FunctionsCompleteSuccessResponse, WebClient, type WebClientOptions } from '@slack/web-api'; import type { AllMiddlewareArgs, AnyMiddlewareArgs, Context, Middleware, SlackEventMiddlewareArgs } from './types'; /** Interfaces */ interface FunctionCompleteArguments { outputs?: Record<string, any>; } export type FunctionCompleteFn = (params?: FunctionCompleteArguments) => Promise<FunctionsCompleteSuccessResponse>; interface FunctionFailArguments { error: string; } export type FunctionFailFn = (params: FunctionFailArguments) => Promise<FunctionsCompleteErrorResponse>; export interface CustomFunctionExecuteMiddlewareArgs extends SlackEventMiddlewareArgs<'function_executed'> { inputs: FunctionExecutedEvent['inputs']; complete: FunctionCompleteFn; fail: FunctionFailFn; } /** Types */ export type SlackCustomFunctionMiddlewareArgs = CustomFunctionExecuteMiddlewareArgs; type CustomFunctionExecuteMiddleware = Middleware<CustomFunctionExecuteMiddlewareArgs>[]; export type CustomFunctionMiddleware = Middleware<CustomFunctionExecuteMiddlewareArgs>[]; export type AllCustomFunctionMiddlewareArgs<T extends SlackCustomFunctionMiddlewareArgs = SlackCustomFunctionMiddlewareArgs> = T & AllMiddlewareArgs; /** Class */ export declare class CustomFunction { /** Function callback_id */ callbackId: string; private appWebClientOptions; private middleware; constructor(callbackId: string, middleware: CustomFunctionExecuteMiddleware, clientOptions: WebClientOptions); getMiddleware(): Middleware<AnyMiddlewareArgs>; private matchesConstraints; private processEvent; private getFunctionMiddleware; /** * Factory for `complete()` utility */ static createFunctionComplete(context: Context, client: WebClient): FunctionCompleteFn; /** * Factory for `fail()` utility */ static createFunctionFail(context: Context, client: WebClient): FunctionFailFn; } /** Helper Functions */ export declare function validate(callbackId: string, middleware: CustomFunctionExecuteMiddleware): void; /** * `processFunctionMiddleware()` invokes each listener middleware */ export declare function processFunctionMiddleware(args: AllCustomFunctionMiddlewareArgs, middleware: CustomFunctionMiddleware): Promise<void>; export declare function isFunctionEvent(args: AnyMiddlewareArgs): args is AllCustomFunctionMiddlewareArgs; /** * `enrichFunctionArgs()` takes in a function's args and: * 1. removes the next() passed in from App-level middleware processing * - events will *not* continue down global middleware chain to subsequent listeners * 2. augments args with step lifecycle-specific properties/utilities * */ export declare function enrichFunctionArgs(args: AllCustomFunctionMiddlewareArgs, webClientOptions: WebClientOptions): AllCustomFunctionMiddlewareArgs; export {}; //# sourceMappingURL=CustomFunction.d.ts.map