Skip to content

Commit

Permalink
Normalize message and handle empty input in MessageParser component i…
Browse files Browse the repository at this point in the history
…n chatbot [[Bug] Chatbot Message Sent Without Text #555]
  • Loading branch information
RealNickey committed Jul 20, 2024
1 parent 0dc0ff0 commit 96c59d3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Components/ChatBot/MessageParser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import React from 'react';
const MessageParser = ({ children, actions }) => {

const parse = (message) => {
message = message.toLowerCase().trim(); // Added trim to remove leading/trailing spaces
message = message.toLowerCase().trim(); // Normalize the message

// Check if the message is empty after trimming
if (message === '') {
actions.defaultResponse(); // Handle empty input
return; // Return early to stop further processing
}

if (
message.includes('company') ||
Expand All @@ -13,10 +19,8 @@ const MessageParser = ({ children, actions }) => {
message.includes('startconnect-hub') ||
message.includes('startconnect') ||
message.includes('site')

) {
actions.companyDetails();

} else if (
message.includes('hello') ||
message.includes('hi') ||
Expand Down Expand Up @@ -57,7 +61,7 @@ const MessageParser = ({ children, actions }) => {
message.includes('tell more')
) {
actions.handleMore();
}else if (
}else if (
message.includes('graet') ||
message.includes('okay') ||
message.includes('fine') ||
Expand All @@ -75,9 +79,8 @@ const MessageParser = ({ children, actions }) => {
} else {
actions.defaultResponse();
}
}

return (
};
return (
<div>
{React.Children.map(children, (child) => {
return React.cloneElement(child, {
Expand Down

0 comments on commit 96c59d3

Please sign in to comment.