From 6401bf387950aff80986341e1e25d2fe0e87cf42 Mon Sep 17 00:00:00 2001 From: Ashvin Panicker Date: Wed, 27 Mar 2024 16:06:18 +0530 Subject: [PATCH 1/6] add local storage --- src/Chatbot.tsx | 12 ++++++++++++ src/index.tsx | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Chatbot.tsx b/src/Chatbot.tsx index 13dede5..eea1db7 100644 --- a/src/Chatbot.tsx +++ b/src/Chatbot.tsx @@ -87,8 +87,10 @@ 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) { + alert('found'); const questionsList = data.sample_intros.intros; // Select 3 suggested questions randomly from the list if (questionsList >= 3) { @@ -98,6 +100,7 @@ const Chatbot: React.FC = () => { .slice(0, 3); // Select the first 3 elements console.log('selectedQuestionSuggestions: ', selectedQuestionSuggestions); setBotIntroSuggestions(selectedQuestionSuggestions); + localStorage.setItem('defaultQuestionSuggestions', JSON.stringify(botIntroSuggestions)); } } @@ -152,6 +155,15 @@ 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(() => { diff --git a/src/index.tsx b/src/index.tsx index edfd0b9..bcb8d1e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,9 +6,9 @@ import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); root.render( - - - , + // + , + // , ); // If you want to start measuring performance in your app, pass a function From 59d8f3e0b1c8c99fef701f565ddc56edb0341d90 Mon Sep 17 00:00:00 2001 From: Ashvin Panicker Date: Wed, 27 Mar 2024 16:11:25 +0530 Subject: [PATCH 2/6] add back strict mode --- src/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index bcb8d1e..edfd0b9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,9 +6,9 @@ import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); root.render( - // - , - // , + + + , ); // If you want to start measuring performance in your app, pass a function From ccc730f3a224af46807a92d922910f02aaf7abdd Mon Sep 17 00:00:00 2001 From: Ashvin Panicker Date: Sun, 31 Mar 2024 10:54:37 +0530 Subject: [PATCH 3/6] local storage fix --- src/Chatbot.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Chatbot.tsx b/src/Chatbot.tsx index eea1db7..2dc0119 100644 --- a/src/Chatbot.tsx +++ b/src/Chatbot.tsx @@ -90,7 +90,6 @@ const Chatbot: React.FC = () => { localStorage.setItem('defaultWelcomeMsg', JSON.stringify(data.welcome_message)); } if (data.sample_intros) { - alert('found'); const questionsList = data.sample_intros.intros; // Select 3 suggested questions randomly from the list if (questionsList >= 3) { @@ -100,7 +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(botIntroSuggestions)); + localStorage.setItem('defaultQuestionSuggestions', JSON.stringify(selectedQuestionSuggestions)); } } @@ -166,6 +165,12 @@ const Chatbot: React.FC = () => { } }, []); // 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) { From 038707c44063c583f8f1572193add2e4f0b6f047 Mon Sep 17 00:00:00 2001 From: Ashvin Panicker Date: Sun, 31 Mar 2024 10:57:09 +0530 Subject: [PATCH 4/6] chat widget dynamic link --- public/chat-widget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/chat-widget.js b/public/chat-widget.js index e6c9fb1..6747934 100644 --- a/public/chat-widget.js +++ b/public/chat-widget.js @@ -1,6 +1,6 @@ (function () { - const iframeURL = 'https://test-hgqq.onrender.com'; - + const iframeURL = REACT_APP_HOSTED_LOCATION; + console.log(iframeURL); const styleElement = document.createElement('style'); styleElement.textContent = ` #floating-button-247 { From 8e97c321993a059e2720a3506d9f814b65624ac4 Mon Sep 17 00:00:00 2001 From: Ashvin Panicker Date: Sun, 31 Mar 2024 11:21:28 +0530 Subject: [PATCH 5/6] test env hosted location --- public/chat-widget.js | 2 +- public/index.html | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/chat-widget.js b/public/chat-widget.js index 6747934..3ca6dc0 100644 --- a/public/chat-widget.js +++ b/public/chat-widget.js @@ -1,5 +1,5 @@ (function () { - const iframeURL = REACT_APP_HOSTED_LOCATION; + const iframeURL = document.querySelector('[property="chatbot-hosted-url"]').content; console.log(iframeURL); const styleElement = document.createElement('style'); styleElement.textContent = ` diff --git a/public/index.html b/public/index.html index d79d7a7..6450177 100644 --- a/public/index.html +++ b/public/index.html @@ -6,7 +6,10 @@ + + +