slack-edge
Version:
Slack app development framework for edge functions with streamlined TypeScript support
79 lines • 3.34 kB
TypeScript
import { SlackAPIClient } from "slack-web-api-client";
import { AssistantThreadContext } from "./thread-context";
/**
* A unique key identifying an assistant thread.
* Combines channel ID and thread timestamp to uniquely identify a conversation.
*/
export type AssistantThreadKey = {
/** The channel ID where the assistant thread exists */
channel_id: string;
/** The timestamp of the thread's parent message */
thread_ts: string;
};
/**
* Interface for storing and retrieving assistant thread context data.
* Implementations of this interface can persist thread context to various backends
* (e.g., message metadata, databases, or in-memory stores).
*/
export interface AssistantThreadContextStore {
/**
* Saves the context data for an assistant thread.
* @param key - The unique identifier for the thread
* @param newContext - The context data to save
* @returns A promise that resolves when the save is complete
*/
save(key: AssistantThreadKey, newContext: AssistantThreadContext): Promise<void>;
/**
* Retrieves the context data for an assistant thread.
* @param key - The unique identifier for the thread
* @returns A promise that resolves to the context data, or undefined if not found
*/
find(key: AssistantThreadKey): Promise<AssistantThreadContext | undefined>;
}
/**
* Configuration options for the DefaultAssistantThreadContextStore.
*/
export interface DefaultAssistantThreadContextStoreOptions {
/** The Slack API client used to make API calls */
client: SlackAPIClient;
/** The bot user ID of the assistant app */
thisBotUserId: string;
}
/**
* Default implementation of AssistantThreadContextStore that persists context
* in message metadata of the bot's first reply in a thread.
*
* This implementation stores context by updating the metadata of the assistant's
* first reply message in the thread. The context can then be retrieved by reading
* the metadata from that same message.
*
* @example
* ```typescript
* const store = new DefaultAssistantThreadContextStore({
* client: slackClient,
* thisBotUserId: "U12345"
* });
* ```
*/
export declare class DefaultAssistantThreadContextStore implements AssistantThreadContextStore {
#private;
/**
* Creates a new DefaultAssistantThreadContextStore instance.
* @param options - Configuration options including the Slack API client and bot user ID
*/
constructor({ client, thisBotUserId }: DefaultAssistantThreadContextStoreOptions);
/**
* Saves the context data by updating the metadata of the bot's first reply in the thread.
* If no first reply exists yet, the save operation is skipped silently.
* @param key - The unique identifier for the thread (channel_id and thread_ts)
* @param newContext - The context data to save
*/
save(key: AssistantThreadKey, newContext: AssistantThreadContext): Promise<void>;
/**
* Retrieves the context data from the metadata of the bot's first reply in the thread.
* @param key - The unique identifier for the thread (channel_id and thread_ts)
* @returns The stored context data, or undefined if not found
*/
find(key: AssistantThreadKey): Promise<AssistantThreadContext | undefined>;
}
//# sourceMappingURL=thread-context-store.d.ts.map