UNPKG

@candoa/chatbot

Version:

Headless React chatbot widget with TypeScript, TailwindCSS support. Customizable AI chat component with hooks for modern React applications.

90 lines (86 loc) 2.68 kB
import * as react_jsx_runtime from 'react/jsx-runtime'; import * as react from 'react'; import { ComponentType } from 'react'; type Message = { id: string; text: string; isUser: boolean; timestamp: Date; }; type ChatbotState = { isOpen: boolean; messages: Message[]; error: string | null; isTyping: boolean; hasActiveConversation: boolean; conversationId: string | null; humanTakenOver: boolean; hasUnreadMessages: boolean; }; type ChatbotActions = { setIsOpen: (isOpen: boolean) => void; sendMessage: (message: string) => Promise<void>; clearMessages: () => void; clearError: () => void; loadConversation: (conversationId: string) => Promise<void>; markAsRead: () => void; }; declare function useChatbot(projectId: string, options?: { title?: string; greetings?: string[]; icon?: ComponentType<{ className?: string; }>; initialConversationId?: string; apiUrl?: string; isDev?: boolean; }): { state: { isOpen: boolean; messages: Message[]; error: string | null; isTyping: boolean; hasActiveConversation: boolean; conversationId: string | null; humanTakenOver: boolean; hasUnreadMessages: boolean; }; actions: { setIsOpen: react.Dispatch<react.SetStateAction<boolean>>; sendMessage: (text: string) => Promise<void>; clearMessages: () => void; clearError: () => void; loadConversation: (convoId: string) => Promise<void>; markAsRead: () => void; }; }; interface ChatbotRenderProps { isOpen: boolean; messages: Message[]; error: string | null; isTyping: boolean; hasActiveConversation: boolean; conversationId: string | null; humanTakenOver: boolean; hasUnreadMessages: boolean; onSendMessage: (message: string) => Promise<void>; onToggleOpen: () => void; onClose: () => void; onClearMessages: () => void; onClearError: () => void; onLoadConversation: (conversationId: string) => Promise<void>; onMarkAsRead: () => void; } type ChatbotWidgetProps = { projectId: string; title?: string; icon?: ComponentType<{ className?: string; }>; greetings?: string[]; apiUrl?: string; isDev?: boolean; children: (props: ChatbotRenderProps) => React.ReactNode; }; declare const ChatbotWidget: ({ projectId, title, icon, greetings, apiUrl, isDev, children, }: ChatbotWidgetProps) => react_jsx_runtime.JSX.Element; export { type ChatbotActions, type ChatbotRenderProps, type ChatbotState, ChatbotWidget, type ChatbotWidgetProps, type Message, useChatbot };