aspirechat
Version:
A highly customizable React chatbot component with extensive configuration options
64 lines (63 loc) • 1.82 kB
TypeScript
export interface ChatButtonOption {
id: string;
text: string;
value: string;
action?: string;
nextFlow?: string;
}
export interface ChatMessage {
id: string;
text: string;
type: "user" | "bot" | "system";
timestamp: number;
buttons?: ChatButtonOption[];
html?: boolean;
metadata?: Record<string, any>;
}
export interface ChatFlow {
id: string;
messages: Omit<ChatMessage, "id" | "timestamp">[];
options?: ChatButtonOption[];
}
export interface ChatState {
messages: ChatMessage[];
isTyping: boolean;
isOpen: boolean;
isMinimized: boolean;
currentFlow: string | null;
availableOptions: ChatButtonOption[];
}
export interface ChatOptions {
initialMessages?: ChatMessage[];
persistKey?: string;
flows?: Record<string, ChatFlow>;
initialFlow?: string;
typingDelay?: number;
initiallyOpen?: boolean;
}
export declare function useChat(options?: ChatOptions): {
messages: ChatMessage[];
isTyping: boolean;
isOpen: boolean;
isMinimized: boolean;
availableOptions: ChatButtonOption[];
currentFlow: string | null;
addMessage: (message: Omit<ChatMessage, "id" | "timestamp">) => {
id: string;
timestamp: number;
text: string;
type: "user" | "bot" | "system";
buttons?: ChatButtonOption[] | undefined;
html?: boolean | undefined;
metadata?: Record<string, any> | undefined;
};
updateMessage: (id: string, updates: Partial<Omit<ChatMessage, "id">>) => void;
clearMessages: () => void;
toggleChat: () => void;
openChat: () => void;
closeChat: () => void;
minimizeChat: () => void;
maximizeChat: () => void;
startFlow: (flowId: string) => void;
handleButtonClick: (option: ChatButtonOption) => void;
};