@@ -20,6 +20,7 @@ import { APIService } from "../../constants/APIConstant";
2020import MessageParser from "./MessageParser.jsx" ;
2121import ActionProvider from "./ActionProvider.jsx" ;
2222import Chatbot from "react-chatbot-kit" ;
23+ import { connect } from "react-redux" ;
2324import { createChatBotMessage } from "react-chatbot-kit" ;
2425import {
2526 PageHeader ,
@@ -50,14 +51,52 @@ const PandaSvg = () => (
5051
5152const PandaIcon = ( props ) => < Icon component = { PandaSvg } { ...props } /> ;
5253
53- const ChatBotComponent = ( ) => {
54+ const ChatBotComponent = ( props ) => {
5455 const [ chatbotState , setChatbotState ] = useState ( {
55- messages : [ ] ,
5656 openapiKey : localStorage . getItem ( "openapi_key" ) ,
5757 initializing : false ,
5858 initializationRequired : false ,
59+ accessToken : props . accessToken ,
60+ isLoggedIn : props . isLoggedIn ,
61+ role : props . role ,
5962 } ) ;
6063
64+ useEffect ( ( ) => {
65+ const fetchInit = async ( ) => {
66+ const stateUrl = APIService . CHATBOT_SERVICE + "genai/state" ;
67+ let initRequired = false ;
68+ // Wait for the response
69+ await superagent
70+ . get ( stateUrl )
71+ . set ( "Accept" , "application/json" )
72+ . set ( "Content-Type" , "application/json" )
73+ . then ( ( res ) => {
74+ console . log ( "I response:" , res . body ) ;
75+ if ( res . status === 200 ) {
76+ if ( res . body ?. initialized === "true" ) {
77+ initRequired = false ;
78+ } else {
79+ initRequired = true ;
80+ }
81+ }
82+ } )
83+ . catch ( ( err ) => {
84+ console . log ( "Error prefetch: " , err ) ;
85+ } ) ;
86+ console . log ( "Initialization required:" , initRequired ) ;
87+ setChatbotState ( ( prev ) => ( {
88+ ...prev ,
89+ initializationRequired : initRequired ,
90+ } ) ) ;
91+ } ;
92+ fetchInit ( ) ;
93+ } , [ ] ) ;
94+
95+ const config_chatbot = {
96+ ...config ,
97+ state : chatbotState ,
98+ } ;
99+
61100 const [ showBot , toggleBot ] = useState ( false ) ;
62101
63102 const saveMessages = ( messages , HTMLString ) => {
@@ -73,14 +112,15 @@ const ChatBotComponent = () => {
73112 localStorage . removeItem ( "chat_messages" ) ;
74113 } ;
75114
115+ console . log ( "Config state" , config_chatbot ) ;
76116 return (
77117 < Row >
78118 < Col xs = { 10 } >
79119 < div className = "app-chatbot-container" >
80120 < div style = { { maxWidth : "500px" } } >
81121 { showBot && (
82122 < Chatbot
83- config = { config }
123+ config = { config_chatbot }
84124 botAvator = {
85125 < Icon
86126 icon = { PandaIcon }
@@ -102,7 +142,7 @@ const ChatBotComponent = () => {
102142 background : "#0a5e9c" ,
103143 borderRadius : "0px" ,
104144 } }
105- href = "#"
145+ href = "## "
106146 onClick = { ( ) => clearHistory ( ) }
107147 >
108148 < DeleteOutlined />
@@ -115,7 +155,7 @@ const ChatBotComponent = () => {
115155 background : "#0a5e9c" ,
116156 borderRadius : "0px" ,
117157 } }
118- href = "#"
158+ href = "## "
119159 onClick = { ( ) => toggleBot ( ( prev ) => ! prev ) }
120160 >
121161 < CloseSquareOutlined />
0 commit comments