UNPKG

@botforge/widget

Version:

Official BotForge chatbot widget for easy integration into any website or web application

176 lines (168 loc) 5.22 kB
import * as React from 'react'; import React__default from 'react'; interface BotForgeMessage { id: string; content: string; sender: "user" | "bot"; timestamp: Date; type: "text" | "image" | "file"; metadata?: any; isError?: boolean; } interface BotForgeMessageData { id?: string; content?: string; sender?: "user" | "bot"; timestamp?: string; type?: "text" | "image" | "file"; metadata?: any; options?: any[]; } interface BotForgeTheme { primaryColor?: string; backgroundColor?: string; textColor?: string; borderRadius?: string; fontFamily?: string; buttonSize?: "small" | "medium" | "large"; chatHeight?: string; chatWidth?: string; headerColor?: string; userMessageColor?: string; botMessageColor?: string; } interface BotForgePosition { bottom?: string; right?: string; left?: string; top?: string; } interface BotForgeUser { id?: string; name?: string; email?: string; avatar?: string; metadata?: Record<string, any>; } interface BotForgeEvents { onOpen?: () => void; onClose?: () => void; onMessage?: (message: BotForgeMessage) => void; onUserMessage?: (message: BotForgeMessage) => void; onBotMessage?: (message: BotForgeMessage) => void; onError?: (error: Error) => void; onReady?: () => void; onTyping?: () => void; onStopTyping?: () => void; } interface BotForgeConfig { chatbotId: string; apiUrl?: string; anonKey?: string; theme?: BotForgeTheme; position?: BotForgePosition; autoOpen?: boolean; showBranding?: boolean; user?: BotForgeUser; events?: BotForgeEvents; enableFileUpload?: boolean; enableEmoji?: boolean; enableTypingIndicator?: boolean; maxMessages?: number; greeting?: string; placeholder?: string; title?: string; subtitle?: string; language?: string; debug?: boolean; } interface BotForgeAPI { open: () => void; close: () => void; toggle: () => void; sendMessage: (message: string) => Promise<void>; setUser: (user: BotForgeUser) => void; isOpen: () => boolean; destroy: () => void; updateConfig: (config: Partial<BotForgeConfig>) => void; } interface BotForgeWidgetProps extends BotForgeConfig { className?: string; style?: React__default.CSSProperties; } declare const BotForgeWidget: React__default.ForwardRefExoticComponent<BotForgeWidgetProps & React__default.RefAttributes<BotForgeAPI>>; declare global { interface Window { BotForge: { initBotForge: (config: BotForgeConfig) => BotForgeAPI; version: string; }; } } declare const initBotForge: (config: BotForgeConfig) => BotForgeAPI; declare class BotForgeAPIClient { private baseUrl; private anonKey; private chatbotId; private conversationId; private userIdentifier; private debug; private isInitializing; private retryCount; private maxRetries; private isOfflineMode; private connectionCheckInterval; constructor(chatbotId: string, apiUrl?: string, anonKey?: string, debug?: boolean); private log; private startConnectionMonitoring; private checkConnection; private makeRequest; initializeConversation(): Promise<{ conversationId: string; userIdentifier: string; welcomeMessage?: BotForgeMessage; followUpMessage?: BotForgeMessage; }>; sendMessage(content: string, type?: "text" | "file"): Promise<{ userMessage: BotForgeMessage; botMessage: BotForgeMessage; }>; getChatbotFlow(): Promise<any>; setUserIdentifier(userIdentifier: string): void; getConversationId(): string | null; getUserIdentifier(): string | null; isOffline(): boolean; reset(): void; destroy(): void; } declare const generateUserIdentifier: () => string; interface UseBotForgeAPIProps { chatbotId: string; apiUrl?: string; anonKey?: string; user?: BotForgeUser; debug?: boolean; onError?: (error: Error) => void; onMessage?: (message: BotForgeMessage) => void; onConnectionChange?: (isConnected: boolean) => void; } declare const useBotForgeAPI: ({ chatbotId, apiUrl, anonKey, user, debug, onError, onMessage, onConnectionChange, }: UseBotForgeAPIProps) => { isConnected: boolean; isLoading: boolean; conversationId: string | null; userIdentifier: string | null; error: Error | null; isInitialized: boolean; setIsLoading: React.Dispatch<React.SetStateAction<boolean>>; initializeConversation: () => Promise<BotForgeMessage | null>; sendMessage: (content: string, type?: "text" | "file") => Promise<{ userMessage: BotForgeMessage; botMessage: BotForgeMessage; }>; updateUser: (newUser: BotForgeUser) => void; getChatbotFlow: () => Promise<any>; resetConversation: () => void; }; declare const version = "1.0.12"; export { BotForgeAPIClient, BotForgeWidget, generateUserIdentifier, initBotForge, useBotForgeAPI, version }; export type { BotForgeAPI, BotForgeConfig, BotForgeEvents, BotForgeMessage, BotForgeMessageData, BotForgePosition, BotForgeTheme, BotForgeUser };