slack-edge
Version:
Slack app development framework for edge functions with streamlined TypeScript support
163 lines • 6.28 kB
TypeScript
import { AuthorizeResult } from "../authorization/authorize-result";
import { SlackAPIClient, ChatPostMessageRequest, ChatPostMessageResponse, WebhookParams, AssistantThreadsSetStatusResponse, AssistantThreadsSetSuggestedPromptsResponse, AssistantThreadsSetTitleResponse } from "slack-web-api-client";
import { AssistantThreadContextStore } from "../assistant/thread-context-store";
import { AssistantThreadContext } from "../assistant/thread-context";
/**
* SlackApp context object that provides data available before performing authorize()
*/
export interface PreAuthorizeSlackAppContext {
isEnterpriseInstall?: boolean;
enterpriseId?: string;
teamId?: string;
userId?: string;
actorEnterpriseId?: string;
actorTeamId?: string;
actorUserId?: string;
botId?: string;
botUserId?: string;
responseUrl?: string;
channelId?: string;
threadTs?: string;
isAssistantThreadEvent: boolean;
triggerId?: string;
functionExecutionId?: string;
functionBotAccessToken?: string;
custom: {
[key: string]: any;
};
}
/**
* respond() utility for easily utilizing response_url to post a channel message.
*/
export type Respond = (params: WebhookParams) => Promise<Response>;
/**
* SlackApp context object that provides data available after performing authorize()
*/
export type SlackAppContext = {
client: SlackAPIClient;
botToken: string;
botId: string;
botUserId: string;
userToken?: string;
authorizeResult: AuthorizeResult;
} & PreAuthorizeSlackAppContext;
/**
* SlackApp context object that provides channelId and say() utility
*/
export type SlackAppContextWithChannelId = {
channelId: string;
say: (params: Omit<ChatPostMessageRequest, "channel">) => Promise<ChatPostMessageResponse>;
} & SlackAppContext;
export type SlackAppContextWithAssistantUtilities = SlackAppContextWithChannelId & {
setStatus: (args: {
status: string;
}) => Promise<AssistantThreadsSetStatusResponse>;
setSuggestedPrompts: (args: {
title?: string;
prompts: ({
title: string;
message: string;
} | string)[];
}) => Promise<AssistantThreadsSetSuggestedPromptsResponse>;
setTitle: (args: {
title: string;
}) => Promise<AssistantThreadsSetTitleResponse>;
threadContextStore: AssistantThreadContextStore;
saveThreadContextStore: (newContext: AssistantThreadContext) => Promise<void>;
threadContext?: AssistantThreadContext;
channelId: string;
threadTs: string;
isAssitantThreadEvent: true;
};
/**
* SlackApp context object that provides channelId and respond() utility.
*/
export type SlackAppContextWithRespond = {
channelId: string;
respond: Respond;
} & SlackAppContext;
/**
* SlackApp context object that may provide respond() utility.
*/
export type SlackAppContextWithOptionalRespond = {
respond?: Respond;
} & SlackAppContext;
/**
* Internal method that sets a context object's basic properties.
*/
export declare function builtBaseContext(body: Record<string, any>): PreAuthorizeSlackAppContext;
/**
* Extracts is_enterprise_install: boolean property from payload.
* @param body the whole request payload data
* @returns is_enterprise_install if exists
*/
export declare function extractIsEnterpriseInstall(body: Record<string, any>): boolean | undefined;
/**
* Extracts enterprise_id: string property from payload.
* @param body the whole request payload data
* @returns enterprise_id if exists
*/
export declare function extractEnterpriseId(body: Record<string, any>): string | undefined;
/**
* Extracts team_id: string property from payload.
* @param body the whole request payload data
* @returns team_id if exists
*/
export declare function extractTeamId(body: Record<string, any>): string | undefined;
/**
* Extracts user_id: string property from payload.
* @param body the whole request payload data
* @returns user_id if exists
*/
export declare function extractUserId(body: Record<string, any>): string | undefined;
/**
* Extracts enterprise_id of the organization to which the actor of the event belongs.
* @param body the whole request payload data
* @returns enterprise_id if exists
*/
export declare function extractActorEnterpriseId(body: Record<string, any>): string | undefined;
/**
* Extracts team_id of the workspace to which the actor of the event belongs.
* @param body the whole request payload data
* @returns team_id if exists
*/
export declare function extractActorTeamId(body: Record<string, any>): string | undefined;
/**
* Extracts user_id of the actor of the event belongs.
* @param body the whole request payload data
* @returns user_id if exists
*/
export declare function extractActorUserId(body: Record<string, any>): string | undefined;
/**
* Extracts response_url: string property from payload.
* @param body the whole request payload data
* @returns response_url if exists
*/
export declare function extractResponseUrl(body: Record<string, any>): string | undefined;
/**
* Extracts channel_id: string property from payload.
* @param body the whole request payload data
* @returns channel_id if exists
*/
export declare function extractChannelId(body: Record<string, any>): string | undefined;
export declare function isAssitantThreadEvent(body: Record<string, any>): boolean;
export declare function extractThreadTs(body: Record<string, any>): string | undefined;
/**
* Extracts trigger_id/interactivity_pointer property from payload.
* @param body the whole request payload data
* @returns trigger_id if exists
*/
export declare function extractTriggerId(body: Record<string, any>): string | undefined;
/**
* Extracts function_execution_id property from payload.
* @param body the whole request payload data
* @returns function_execution_id if exists
*/
export declare function extractFunctionExecutionId(body: Record<string, any>): string | undefined;
/**
* Extracts JIT bot_access_token property for a custom function invocation from payload.
* @param body the whole request payload data
* @returns function's JIT bot_access_token if exists
*/
export declare function extractFunctionBotAccessToken(body: Record<string, any>): string | undefined;
//# sourceMappingURL=context.d.ts.map