From 4cf0c1a845e0fadfe7038be2a64448c2ac8957be Mon Sep 17 00:00:00 2001 From: ansh Date: Fri, 12 Jul 2024 22:58:06 +0530 Subject: [PATCH] chatbot messages update --- src/components/Chatbot.jsx | 2 +- src/utils/actionProvider.js | 133 +++++++++++++----------------------- src/utils/messageParser.js | 121 +++++++++++++++++++------------- 3 files changed, 122 insertions(+), 134 deletions(-) diff --git a/src/components/Chatbot.jsx b/src/components/Chatbot.jsx index 74055e9..42ac18f 100644 --- a/src/components/Chatbot.jsx +++ b/src/components/Chatbot.jsx @@ -36,4 +36,4 @@ const ChatbotComponent = () => { ); }; -export default ChatbotComponent; +export default ChatbotComponent; \ No newline at end of file diff --git a/src/utils/actionProvider.js b/src/utils/actionProvider.js index 1e8e3b7..eb105bb 100644 --- a/src/utils/actionProvider.js +++ b/src/utils/actionProvider.js @@ -1,88 +1,49 @@ -class ActionProvider { - constructor(createChatBotMessage, setStateFunc) { - this.createChatBotMessage = createChatBotMessage; - this.setState = setStateFunc; +class MessageParser { + constructor(actionProvider) { + this.actionProvider = actionProvider; + } + + parse(message) { + const lowercase = message.toLowerCase(); + + if (lowercase.includes("what")&&lowercase.includes("is")) { + this.actionProvider.handleWhat(); + } + else if (lowercase.includes("how")&&lowercase.includes("work")) { + this.actionProvider.handleHow(); + } + else if (lowercase.includes("who")&&((lowercase.includes("created"))||(lowercase.includes("made")))) { + this.actionProvider.handleCreate(); + } + else if (lowercase.includes("thank you")||lowercase.includes("thanks")) { + this.actionProvider.handleThanks(); + } + else if (lowercase.includes("goodbye")||lowercase.includes("bye")) { + this.actionProvider.handleBye(); + } + else if (lowercase.includes("what")&&((lowercase.includes("do"))||(lowercase.includes("can")))&&lowercase.includes("you")) { + this.actionProvider.handleSelf(); + } + else if (lowercase.includes("contact")) { + this.actionProvider.handleContact(); + } + else if (((lowercase.includes("doesn't"))||(lowercase.includes("does not"))||(lowercase.includes("don't"))||(lowercase.includes("do not")))) { + this.actionProvider.handleWork(); + } + else if (lowercase.includes("hello")) { + this.actionProvider.handleHello(); + } + else if (lowercase.includes("okay")) { + this.actionProvider.handleOkay(); + } + else if(lowercase.includes("How are you?")){ + this.actionProvider.handleCare(); + } + else{ + this.actionProvider.handleDefault(); } - - handleHello = () => { - const message = this.createChatBotMessage("Hello, Welcome to TimeWarp Website!"); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleWhat = () => { - const message = this.createChatBotMessage("TimeWarp is an opensource webapp that allows users to explore historical versions of their current location virtually"); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleHow = () => { - const message = this.createChatBotMessage("Using augmented reality and historical maps, users can see how their surroundings looked in different time periods and learn about the history of the area. You can learn more in the demo section."); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleCreate = () => { - const message = this.createChatBotMessage("This was created by Akshat Chaube, Himank Gupta, Naman Gupta and Shreya Prasad."); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleThanks = () => { - const message = this.createChatBotMessage("You're welcome!"); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleBye = () => { - const message = this.createChatBotMessage("Goodbye, Have a great day!"); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleSelf = () => { - const message = this.createChatBotMessage("I can tell you more about this project. What would you like to know?"); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleContact = () => { - const message = this.createChatBotMessage("You can get contact information in the footer, or leave a message in the contact section."); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleWork = () => { - const message = this.createChatBotMessage("Please wait as more functionalities are added. In the meantime, you can leave your comments in the contact section and check out our GitHub (link in footer). Thank you for your patience!"); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleOkay = () => { - const message = this.createChatBotMessage("Anything else I can help you with?"); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - handleDefault = () => { - const message = this.createChatBotMessage("Please rephrase your query."); - this.setState((prev) => ({ - ...prev, - messages: [...prev.messages, message], - })); - }; - + } - - export default ActionProvider; - \ No newline at end of file +} + +export default MessageParser; \ No newline at end of file diff --git a/src/utils/messageParser.js b/src/utils/messageParser.js index c5292b2..8d78292 100644 --- a/src/utils/messageParser.js +++ b/src/utils/messageParser.js @@ -1,47 +1,74 @@ -class MessageParser { - constructor(actionProvider) { - this.actionProvider = actionProvider; - } - - parse(message) { - const lowercase = message.toLowerCase(); - - if (lowercase.includes("what")&&lowercase.includes("is")) { - this.actionProvider.handleWhat(); - } - else if (lowercase.includes("how")&&lowercase.includes("work")) { - this.actionProvider.handleHow(); - } - else if (lowercase.includes("who")&&((lowercase.includes("created"))||(lowercase.includes("made")))) { - this.actionProvider.handleCreate(); - } - else if (lowercase.includes("thank you")||lowercase.includes("thanks")) { - this.actionProvider.handleThanks(); - } - else if (lowercase.includes("goodbye")||lowercase.includes("bye")) { - this.actionProvider.handleBye(); - } - else if (lowercase.includes("what")&&((lowercase.includes("do"))||(lowercase.includes("can")))&&lowercase.includes("you")) { - this.actionProvider.handleSelf(); - } - else if (lowercase.includes("contact")) { - this.actionProvider.handleContact(); - } - else if (((lowercase.includes("doesn't"))||(lowercase.includes("does not"))||(lowercase.includes("don't"))||(lowercase.includes("do not")))) { - this.actionProvider.handleWork(); - } - else if (lowercase.includes("hello")) { - this.actionProvider.handleHello(); - } - else if (lowercase.includes("okay")) { - this.actionProvider.handleOkay(); - } - else{ - this.actionProvider.handleDefault(); - } - - } - } - - export default MessageParser; - \ No newline at end of file +class ActionProvider { + constructor(createChatBotMessage, setStateFunc) { + this.createChatBotMessage = createChatBotMessage; + this.setState = setStateFunc; + } + + handleWhat() { + const message = this.createChatBotMessage("I'm not sure what you are asking about. Can you provide more details?"); + this.addMessageToState(message); + } + + handleHow() { + const message = this.createChatBotMessage("I can explain how it works. Please provide more context."); + this.addMessageToState(message); + } + + handleCreate() { + const message = this.createChatBotMessage("I was created by a team of developers."); + this.addMessageToState(message); + } + handleCare(){ + const message = this.createChatBotMessage("I am Fine."); + this.addMessageToState(message); + } + + handleThanks() { + const message = this.createChatBotMessage("You're welcome! If you have any more questions, feel free to ask."); + this.addMessageToState(message); + } + + handleBye() { + const message = this.createChatBotMessage("Goodbye! Have a great day."); + this.addMessageToState(message); + } + + handleSelf() { + const message = this.createChatBotMessage("I am a chatbot designed to assist you with various questions and tasks."); + this.addMessageToState(message); + } + + handleContact() { + const message = this.createChatBotMessage("You can contact us via email at support@example.com."); + this.addMessageToState(message); + } + + handleWork() { + const message = this.createChatBotMessage("I'm sorry to hear that something isn't working. Can you provide more details so I can assist you better?"); + this.addMessageToState(message); + } + + handleHello() { + const message = this.createChatBotMessage("Hello! How can I assist you today?"); + this.addMessageToState(message); + } + + handleOkay() { + const message = this.createChatBotMessage("Okay! Let me know if there's anything else I can help with."); + this.addMessageToState(message); + } + + handleDefault() { + const message = this.createChatBotMessage("I'm not sure I understand. Could you please clarify?"); + this.addMessageToState(message); + } + + addMessageToState(message) { + this.setState((prevState) => ({ + ...prevState, + messages: [...prevState.messages, message], + })); + } +} + +export default ActionProvider; \ No newline at end of file