import React from 'react'; import Chat from '../Chat/Chat'; import ChatbotError from '../ChatbotError/ChatbotError'; import IConfig from '../../interfaces/IConfig'; import { getCustomStyles, getCustomComponents, getBotName, getCustomMessages, isConstructor, } from './utils'; import useChatbot from '../../hooks/useChatbot'; import { IMessage } from '../../interfaces/IMessages'; import { createChatBotMessage } from '../..'; interface IChatbotProps { actionProvider: any; messageParser: any; config: IConfig; headerText?: string; placeholderText?: string; saveMessages?: (ref: any) => any; messageHistory?: IMessage[] | string; validator?: (input: string) => Boolean; runInitialMessagesWithHistory?: Boolean; disableScrollToBottom?: boolean; } const Chatbot = ({ actionProvider, messageParser, config, headerText, placeholderText, saveMessages, messageHistory, runInitialMessagesWithHistory, disableScrollToBottom, validator, ...rest }: IChatbotProps) => { const { configurationError, invalidPropsError, ActionProvider, MessageParser, widgetRegistry, messageContainerRef, actionProv, messagePars, state, setState, } = useChatbot({ config, actionProvider, messageParser, messageHistory, saveMessages, runInitialMessagesWithHistory, ...rest, }); if (configurationError) { return ; } if (invalidPropsError.length) { return ; } const customStyles = getCustomStyles(config); const customComponents = getCustomComponents(config); const botName = getBotName(config); const customMessages = getCustomMessages(config); if (isConstructor(ActionProvider) && isConstructor(MessageParser)) { return ( ); } else { return ( ); } }; export default Chatbot;