Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />

<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
17 changes: 17 additions & 0 deletions src/Chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const Chatbot: React.FC = () => {
setIdleTimeoutSeconds(data.idle_timeout_seconds);
if (data.welcome_message) {
setBotIntroMessage(data.welcome_message);
localStorage.setItem('defaultWelcomeMsg', JSON.stringify(data.welcome_message));
}
if (data.sample_intros) {
const questionsList = data.sample_intros.intros;
Expand All @@ -98,6 +99,7 @@ const Chatbot: React.FC = () => {
.slice(0, 3); // Select the first 3 elements
console.log('selectedQuestionSuggestions: ', selectedQuestionSuggestions);
setBotIntroSuggestions(selectedQuestionSuggestions);
localStorage.setItem('defaultQuestionSuggestions', JSON.stringify(selectedQuestionSuggestions));
}
}

Expand Down Expand Up @@ -152,8 +154,23 @@ const Chatbot: React.FC = () => {

useEffect(() => {
initializeChatbot();
// Retrieve data from local storage
const defaultWelcomeMsg = localStorage.getItem('defaultWelcomeMsg');
const defaultQuestionSuggestions = localStorage.getItem('defaultQuestionSuggestions');
if (defaultWelcomeMsg) {
setBotIntroMessage(JSON.parse(defaultWelcomeMsg));
}
if (defaultQuestionSuggestions) {
setBotIntroSuggestions(JSON.parse(defaultQuestionSuggestions));
}
}, []); // Run once on component mount

useEffect(() => {
if (botIntroSuggestions.length > 0) {
localStorage.setItem('defaultQuestionSuggestions', JSON.stringify(botIntroSuggestions));
}
}, [botIntroSuggestions]);

useEffect(() => {
// Display introductory message only if there are no existing messages
if (messages.length === 0) {
Expand Down