Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made chatbot more conversational #361

Merged
merged 1 commit into from
Jul 6, 2024
Merged
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
73 changes: 72 additions & 1 deletion src/utils/actionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,83 @@ class ActionProvider {
}

handleHello = () => {
const message = this.createChatBotMessage("Hello.Welcome to TimeWarp Website?");
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;
Expand Down
33 changes: 32 additions & 1 deletion src/utils/messageParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,40 @@ class MessageParser {
parse(message) {
const lowercase = message.toLowerCase();

if (lowercase.includes("hello")) {
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();
}

}
}

Expand Down