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

added the chatbot for 24/7 Customer Support #149 #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
109 changes: 109 additions & 0 deletions chat.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* Add this to your existing CSS or create a new file styles.css */

#chatbot-logo {
position: fixed;
bottom: 20px;
right: 20px;
width: 60px;
height: 60px;
background-color: #FF5C5C;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 28px;
cursor: pointer;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

#chatbot-container {
position: fixed;
bottom: 20px;
right: 20px;
width: 350px;
background-color: #f1f1f1;
border: 1px solid #ccc;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
display: none; /* Initially hidden */
flex-direction: column;
height: 500px;
overflow: hidden;
}

#chatbot {
display: flex;
flex-direction: column;
height: 100%;
}

#chatbot-header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #FF5C5C;
color: white;
padding: 15px;
border-radius: 10px 10px 0 0;
font-size: 18px;
font-weight: bold;
}

#chatbot-close {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
}

#chatbot-messages {
flex: 1;
padding: 10px;
overflow-y: auto;
background-color: white;
}

#chatbot-input {
width: calc(100% - 70px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px 0 0 5px;
margin: 10px 0 10px 10px;
}

#chatbot-send {
width: 60px;
border: none;
background-color: #FF5C5C;
color: white;
padding: 10px;
cursor: pointer;
border-radius: 0 5px 5px 0;
margin: 10px 10px 10px 0;
font-weight: bold;
}


.user {
align-self: flex-end;
background-color: #0d0101;
color: white;
padding: 10px;
border-radius: 10px;
margin: 5px;
max-width: 70%;
word-wrap: break-word;
}

.bot {
align-self: flex-start;
background-color: #f1f1f1;
color: black;
padding: 10px;
border-radius: 10px;
margin: 5px;
max-width: 70%;
word-wrap: break-word;
}
30 changes: 30 additions & 0 deletions chat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Physi-c Tech</title>
<link rel="stylesheet" href="chat.css">
</head>
<body>
<!-- Existing content of the website -->

<!-- Chatbot logo -->
<div id="chatbot-logo" onclick="toggleChatbot()">πŸ’¬</div>

<!-- Chatbot interface -->
<div id="chatbot-container">
<div id="chatbot">
<div id="chatbot-header">
Chatbot
<button id="chatbot-close" onclick="toggleChatbot()">&times;</button>
</div>
<div id="chatbot-messages"></div>
<input type="text" id="chatbot-input" placeholder="Ask me something...">
<button id="chatbot-send">Send</button>
</div>
</div>

<script src="chat.js"></script>
</body>
</html>
79 changes: 79 additions & 0 deletions chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Add this to a new file chatbot.js

document.getElementById('chatbot-send').addEventListener('click', sendMessage);
document.getElementById('chatbot-input').addEventListener('keypress', function (e) {
if (e.key === 'Enter') sendMessage();
});

function toggleChatbot() {
const chatbotContainer = document.getElementById('chatbot-container');
const chatbotLogo = document.getElementById('chatbot-logo');
if (chatbotContainer.style.display === 'none' || chatbotContainer.style.display === '') {
chatbotContainer.style.display = 'flex';
chatbotLogo.style.display = 'none';
} else {
chatbotContainer.style.display = 'none';
chatbotLogo.style.display = 'flex';
}
}

function sendMessage() {
const inputField = document.getElementById('chatbot-input');
const message = inputField.value.trim();
if (message === '') return;

displayMessage('User', message);
inputField.value = '';

// Simple keyword-based responses
let response = 'Sorry, I did not understand that.';

if (message.toLowerCase().includes('goal of the game')) {
response = '"Physi-c-Tech" seems to be a play on words combining "physics" and "technology," , Where we create elements after adding two different elements.';
} else if (message.toLowerCase().includes('start a new game')) {
response = 'To start a new game, click on the "New Game" button in the home page. And if you want to continue from where you left just click on continue button.';
} else if (message.toLowerCase().includes('about section')) {
response = 'You can find the "About" section by clicking on the "About" link at the top of the page.';
} else if (message.toLowerCase().includes('Sound on or off')) {
response = 'If you want to on or off the sound then click on the sound button.';
} else if (message.toLowerCase().includes('game isn\'t loading')) {
response = 'If the game isn\'t loading, try refreshing the page or clearing your browser\'s cache. If the problem persists, contact support at [support email].';
} else if (message.toLowerCase().includes('report a bug')) {
window.location.href = 'https://github.com/ChromeGaming/Physi-c-Tech/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=%5BBug%5D%3A+';
return; // Stop further execution
} else if (message.toLowerCase().includes('feedback')) {
window.location.href = 'https://chromegaming.github.io/Physi-c-Tech/feedback.html';
return; // Stop further execution
}

displayMessage('Bot', response);
}

function displayMessage(sender, message) {
const messagesContainer = document.getElementById('chatbot-messages');
const messageElement = document.createElement('div');

// Create separate spans for sender and message content
const senderSpan = document.createElement('span');
senderSpan.textContent = `${sender}: `;
senderSpan.classList.add('sender');

const messageSpan = document.createElement('span');
messageSpan.textContent = message;

// Append sender and message spans to the message element
messageElement.appendChild(senderSpan);
messageElement.appendChild(messageSpan);

// Assigning classes based on sender
if (sender === 'User') {
messageElement.classList.add('user');
} else if (sender === 'Bot') {
messageElement.classList.add('bot');
}

messagesContainer.appendChild(messageElement);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}