@@ -95,6 +96,36 @@
+
+
+
+ Chatbot
+ close
+
+
+ -
+ smart_toy
+
Welcome to CSEdge 👋 How I can help You Today
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ send
+
+
+
From 0ee3377da71d2eec7a435f3b53e26a85beb6d187 Mon Sep 17 00:00:00 2001
From: sidhigrover <123989540+sidhigrover@users.noreply.github.com>
Date: Sat, 1 Jun 2024 01:07:00 +0530
Subject: [PATCH 2/3] Added New Chatbox and remove the old chatbox
---
chatbox.css | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++
chatboxx.js | 143 ++++++++++++++++++++++++++++++++++++++
index.html | 61 ++++++++--------
style.css | 44 ++++++++++++
4 files changed, 413 insertions(+), 32 deletions(-)
create mode 100644 chatbox.css
create mode 100644 chatboxx.js
diff --git a/chatbox.css b/chatbox.css
new file mode 100644
index 00000000..c52918b5
--- /dev/null
+++ b/chatbox.css
@@ -0,0 +1,197 @@
+/* Import Google font - Poppins */
+@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
+
+* {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ font-family: "Poppins", sans-serif;
+}
+body {
+
+}
+.chatbot-toggler {
+
+ position: fixed;
+ bottom: 30px;
+ right: 35px;
+ outline: none;
+ border: none;
+ height: 50px;
+ width: 50px;
+ display: flex;
+ cursor: pointer;
+ align-items: center;
+ justify-content: center;
+ border-radius: 50%;
+ background: #4178c0;
+ transition: all 0.2s ease;
+}
+body.show-chatbot .chatbot-toggler {
+ transform: rotate(90deg);
+}
+.chatbot-toggler span {
+ color: #fff;
+ position: absolute;
+}
+.chatbot-toggler span:last-child,
+body.show-chatbot .chatbot-toggler span:first-child {
+ opacity: 0;
+}
+body.show-chatbot .chatbot-toggler span:last-child {
+ opacity: 1;
+}
+.chatbot {
+ z-index: 1;
+ position: fixed;
+ right: 35px;
+ bottom: 90px;
+ width: 420px;
+ background: #fff;
+ border-radius: 15px;
+ overflow: hidden;
+ opacity: 0;
+ pointer-events: none;
+ transform: scale(0.5);
+ transform-origin: bottom right;
+ box-shadow: 0 0 128px 0 rgba(0,0,0,0.1),
+ 0 32px 64px -48px rgba(0,0,0,0.5);
+ transition: all 0.1s ease;
+}
+body.show-chatbot .chatbot {
+ opacity: 1;
+ pointer-events: auto;
+ transform: scale(1);
+}
+.chatbot header {
+ padding: 16px 0;
+ position: relative;
+ text-align: center;
+ color: #fff;
+ background: #4178c0;
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
+}
+.chatbot header span {
+ position: absolute;
+ right: 15px;
+ top: 50%;
+ display: none;
+ cursor: pointer;
+ transform: translateY(-50%);
+}
+header h2 {
+ font-size: 1.4rem;
+}
+.chatbot .chatbox {
+ overflow-y: auto;
+ height: 510px;
+ padding: 30px 20px 100px;
+}
+.chatbot :where(.chatbox, textarea)::-webkit-scrollbar {
+ width: 6px;
+}
+.chatbot :where(.chatbox, textarea)::-webkit-scrollbar-track {
+ background: #fff;
+ border-radius: 25px;
+}
+.chatbot :where(.chatbox, textarea)::-webkit-scrollbar-thumb {
+ background: #ccc;
+ border-radius: 25px;
+}
+.chatbox .chat {
+ display: flex;
+ list-style: none;
+}
+.chatbox .outgoing {
+ margin: 20px 0;
+ justify-content: flex-end;
+}
+.chatbox .incoming span {
+ width: 32px;
+ height: 32px;
+ color: #fff;
+ cursor: default;
+ text-align: center;
+ line-height: 32px;
+ align-self: flex-end;
+ background: #4178c0;
+ border-radius: 4px;
+ margin: 0 10px 7px 0;
+}
+.chatbox .chat p {
+ white-space: pre-wrap;
+ padding: 12px 16px;
+ border-radius: 10px 10px 0 10px;
+ max-width: 75%;
+ color: #fff;
+ font-size: 0.95rem;
+ background: #4178c0;
+}
+.chatbox .incoming p {
+ border-radius: 10px 10px 10px 0;
+}
+.chatbox .chat p.error {
+ color: #721c24;
+ background: #f8d7da;
+}
+.chatbox .incoming p {
+ color: #000;
+ background: #f2f2f2;
+}
+.chatbot .chat-input {
+ display: flex;
+ gap: 5px;
+ position: absolute;
+ bottom: 0;
+ width: 100%;
+ background: #fff;
+ padding: 3px 20px;
+ border-top: 1px solid #ddd;
+}
+.chat-input textarea {
+ height: 55px;
+ width: 100%;
+ border: none;
+ outline: none;
+ resize: none;
+ max-height: 180px;
+ padding: 15px 15px 15px 0;
+ font-size: 0.95rem;
+}
+.chat-input span {
+ align-self: flex-end;
+ color: #4178c0;
+ cursor: pointer;
+ height: 55px;
+ display: flex;
+ align-items: center;
+ visibility: hidden;
+ font-size: 1.35rem;
+}
+.chat-input textarea:valid ~ span {
+ visibility: visible;
+}
+
+@media (max-width: 490px) {
+ .chatbot-toggler {
+ right: 20px;
+ bottom: 20px;
+ }
+ .chatbot {
+ right: 0;
+ bottom: 0;
+ height: 100%;
+ border-radius: 0;
+ width: 100%;
+ }
+ .chatbot .chatbox {
+ height: 90%;
+ padding: 25px 15px 100px;
+ }
+ .chatbot .chat-input {
+ padding: 5px 15px;
+ }
+ .chatbot header span {
+ display: block;
+ }
+}
\ No newline at end of file
diff --git a/chatboxx.js b/chatboxx.js
new file mode 100644
index 00000000..b54b67b9
--- /dev/null
+++ b/chatboxx.js
@@ -0,0 +1,143 @@
+const chatbotToggler = document.querySelector(".chatbot-toggler");
+const closeBtn = document.querySelector(".close-btn");
+const chatbox = document.querySelector(".chatbox");
+const chatInput = document.querySelector(".chat-input textarea");
+const sendChatBtn = document.querySelector(".chat-input span");
+
+let userMessage = null; // Variable to store user's message
+let appointmentStep = 0; // Variable to track the appointment scheduling steps
+let selectedDoctor = null; // Variable to store the selected doctor
+let appointmentDetails = {}; // Object to store appointment details
+const API_KEY = "PASTE-YOUR-API-KEY"; // Paste your API key here
+const inputInitHeight = chatInput.scrollHeight;
+
+const predefinedQA = {
+ "Hi": "Hello",
+ "Hey":"Hello",
+ "How are you?": "I'm just a bot, but I'm doing great! How can I assist you today?",
+ "What is your name?": "I am a chatbot created to assist you.",
+ "Tell me a joke.": "Why don't scientists trust atoms? Because they make up everything!",
+ "What is RapiDoc?": "RapiDoc is an online platform which enables you to get information about your nearest hospitals and healthcare facilities. It aims to address health-related issues. It is a one-stop destination for all your medical needs.",
+ "How can RapiDoc help me?": "RapiDoc helps you find the nearest hospitals and healthcare facilities, ensuring you have access to necessary medical information and services quickly and easily.",
+ "What services does RapiDoc provide?": "RapiDoc provides information on nearby hospitals, healthcare facilities, and various medical services to address your health-related needs.",
+ "Make an appointment": "Sure, here are some doctors available for appointments:\n1. Dr. Vikas Chopra\n2. Dr. Ajay Aggarwal\n3. Dr. Soni Gupta\nPlease type the number of the doctor you want to make an appointment with."
+};
+
+const doctorsList = {
+ "1": "Dr. Vikas Chopra",
+ "2": "Dr. Ajay Aggarwal",
+ "3": "Dr. Soni Gupta"
+};
+
+const createChatLi = (message, className) => {
+ const chatLi = document.createElement("li");
+ chatLi.classList.add("chat", `${className}`);
+ let chatContent = className === "outgoing" ? `` : `smart_toy`;
+ chatLi.innerHTML = chatContent;
+ chatLi.querySelector("p").textContent = message;
+ return chatLi;
+}
+
+const generateResponse = (chatElement) => {
+ const API_URL = "https://api.openai.com/v1/chat/completions";
+ const messageElement = chatElement.querySelector("p");
+
+ const requestOptions = {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ "Authorization": `Bearer ${API_KEY}`
+ },
+ body: JSON.stringify({
+ model: "gpt-3.5-turbo",
+ messages: [{ role: "user", content: userMessage }],
+ })
+ }
+
+ fetch(API_URL, requestOptions).then(res => res.json()).then(data => {
+ messageElement.textContent = data.choices[0].message.content.trim();
+ }).catch(() => {
+ messageElement.classList.add("error");
+ messageElement.textContent = "Oops! Something went wrong. Please try again.";
+ }).finally(() => chatbox.scrollTo(0, chatbox.scrollHeight));
+}
+
+const handleAppointment = (userMessage) => {
+ if (appointmentStep === 0) {
+ selectedDoctor = doctorsList[userMessage];
+ if (!selectedDoctor) {
+ chatbox.appendChild(createChatLi("Invalid doctor number. Please try again.", "incoming"));
+ return;
+ }
+ chatbox.appendChild(createChatLi(`You selected ${selectedDoctor}. Please enter the date for your appointment (YYYY-MM-DD).`, "incoming"));
+ appointmentStep++;
+ } else if (appointmentStep === 1) {
+ const date = userMessage;
+ if (!date.match(/^\d{4}-\d{2}-\d{2}$/)) {
+ chatbox.appendChild(createChatLi("Invalid date format. Please enter the date in YYYY-MM-DD format.", "incoming"));
+ return;
+ }
+ appointmentDetails.date = date;
+ chatbox.appendChild(createChatLi("Please enter the time for your appointment (HH:MM).", "incoming"));
+ appointmentStep++;
+ } else if (appointmentStep === 2) {
+ const time = userMessage;
+ if (!time.match(/^\d{2}:\d{2}$/)) {
+ chatbox.appendChild(createChatLi("Invalid time format. Please enter the time in HH:MM format.", "incoming"));
+ return;
+ }
+ appointmentDetails.time = time;
+ chatbox.appendChild(createChatLi(`Appointment scheduled with ${selectedDoctor} on ${appointmentDetails.date} at ${appointmentDetails.time}.`, "incoming"));
+ appointmentStep = 0;
+ selectedDoctor = null;
+ appointmentDetails = {};
+ }
+}
+
+const handleChat = () => {
+ userMessage = chatInput.value.trim();
+ if (!userMessage) return;
+
+ chatInput.value = "";
+ chatInput.style.height = `${inputInitHeight}px`;
+
+ chatbox.appendChild(createChatLi(userMessage, "outgoing"));
+ chatbox.scrollTo(0, chatbox.scrollHeight);
+
+ if (appointmentStep > 0) {
+ handleAppointment(userMessage);
+ } else if (predefinedQA[userMessage]) {
+ setTimeout(() => {
+ const incomingChatLi = createChatLi(predefinedQA[userMessage], "incoming");
+ chatbox.appendChild(incomingChatLi);
+ chatbox.scrollTo(0, chatbox.scrollHeight);
+ }, 600);
+ } else if (Object.keys(doctorsList).includes(userMessage)) {
+ setTimeout(() => {
+ handleAppointment(userMessage);
+ }, 600);
+ } else {
+ setTimeout(() => {
+ const incomingChatLi = createChatLi("Thinking...", "incoming");
+ chatbox.appendChild(incomingChatLi);
+ chatbox.scrollTo(0, chatbox.scrollHeight);
+ generateResponse(incomingChatLi);
+ }, 600);
+ }
+}
+
+chatInput.addEventListener("input", () => {
+ chatInput.style.height = `${inputInitHeight}px`;
+ chatInput.style.height = `${chatInput.scrollHeight}px`;
+});
+
+chatInput.addEventListener("keydown", (e) => {
+ if (e.key === "Enter" && !e.shiftKey && window.innerWidth > 800) {
+ e.preventDefault();
+ handleChat();
+ }
+});
+
+sendChatBtn.addEventListener("click", handleChat);
+closeBtn.addEventListener("click", () => document.body.classList.remove("show-chatbot"));
+chatbotToggler.addEventListener("click", () => document.body.classList.toggle("show-chatbot"));
diff --git a/index.html b/index.html
index c6190282..165bfaaa 100644
--- a/index.html
+++ b/index.html
@@ -46,10 +46,38 @@
+
+
+
+
+
+
+
+
+
+ Chatbot
+ close
+
+
+ -
+ smart_toy
+
Hi there 👋
How can I help you today?
+
+
+
+
+ send
+
+
+
+
@@ -96,37 +124,6 @@
-
-
-
- Chatbot
- close
-
-
- -
- smart_toy
-
Welcome to CSEdge 👋 How I can help You Today
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- send
-
-
-
-
@@ -948,7 +945,7 @@
-
+
diff --git a/style.css b/style.css
index d3c80dae..63b59073 100644
--- a/style.css
+++ b/style.css
@@ -124,6 +124,7 @@ h6 {
padding: 20px;
margin-bottom: 20px;
border-radius: 10px;
+ z-index: -1;
}
@@ -141,11 +142,13 @@ h6 {
transition: 0.3s;
font-size: 16px;
font-weight: 600;
+ z-index: -1;
display: inline-block;
}
.appointment-btn:hover {
background: #55a5ea;
+ z-index: -1;
color: #fff;
}
@@ -449,6 +452,7 @@ section {
}
.featured-services .icon-box {
+ z-index: -1;
width: 230px;
height: 270px;
margin-left: 15px;
@@ -466,6 +470,7 @@ section {
}
.featured-services .icon-box::before {
+ z-index: -1;
content: '';
position: absolute;
background: #000;
@@ -478,16 +483,19 @@ section {
}
.featured-services .icon-box:hover::before {
+ z-index: -1;
background: #3fbcc051;
top: 0px;
border-radius: 50px;
}
.featured-services .icon1 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon1 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #3fbcc0a4;
@@ -495,10 +503,12 @@ section {
}
.featured-services .icon2 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon2 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #55a5ea;
@@ -506,10 +516,12 @@ section {
}
.featured-services .icon3 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon3 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #55a5ea;
@@ -517,10 +529,12 @@ section {
}
.featured-services .icon4 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon4 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #55a5ea;
@@ -568,12 +582,14 @@ section {
/*################----About----################*/
.about .icon-boxes h4 {
+ z-index: -1;
font-size: 18px;
color: #55a5ea;
margin-bottom: 15px;
}
.about .icon-boxes h3 {
+ z-index: -1;
font-size: 28px;
font-weight: 700;
color: #55a5ea;
@@ -581,6 +597,7 @@ section {
}
.about .icon-box {
+ z-index: -1;
background: #111111;
border-radius: 10px;
margin-top: 35px;
@@ -589,6 +606,7 @@ section {
}
.about .icon-box .icon {
+ z-index: -1;
float: left;
display: flex;
align-items: center;
@@ -601,20 +619,24 @@ section {
}
.about .icon-box .icon i {
+ z-index: -1;
color: #3fbcc0a4;
font-size: 32px;
}
.about .icon-box:hover .icon {
+ z-index: -1;
background: #55a5ea;
border-color: #55a5ea;
}
.about .icon-box:hover .icon i {
+ z-index: -1;
color: #fff;
}
.about .icon-box .title {
+ z-index: -1;
margin-left: 85px;
font-weight: 700;
@@ -623,6 +645,7 @@ section {
}
.about .icon-box .title a {
+ z-index: -1;
color: #fff;
transition: 0.3s;
font-size: 18px;
@@ -630,16 +653,19 @@ section {
}
.about .icon-box .title a:hover {
+ z-index: -1;
color: #55a5ea;
}
.about .icon-box .description {
+ z-index: -1;
margin-left: 85px;
line-height: 24px;
font-size: 14px;
}
.about .video-box {
+ z-index: -1;
background: url("../img/about.png") center center no-repeat;
background-size: cover;
height: 300px;
@@ -648,6 +674,7 @@ section {
.about .play-btn {
width: 94px;
+ z-index: -1;
height: 94px;
background: radial-gradient(#55a5ea 50%, rgba(4, 196, 234, 0.4) 52%);
border-radius: 50%;
@@ -659,6 +686,7 @@ section {
}
.about .play-btn::after {
+ z-index: -1;
content: '';
position: absolute;
left: 50%;
@@ -674,6 +702,7 @@ section {
}
.about .play-btn::before {
+ z-index: -1;
content: '';
position: absolute;
width: 120px;
@@ -687,12 +716,14 @@ section {
}
.about .play-btn:hover::after {
+ z-index: -1;
border-left: 15px solid #55a5ea;
transform: scale(20);
}
.about .play-btn:hover::before {
content: '';
+ z-index: -1;
position: absolute;
left: 50%;
top: 50%;
@@ -738,10 +769,13 @@ section {
/*################----Counts----################*/
.counts {
/* padding-top: 30px; */
+
justify-content: center;
}
+
.counts .count-box {
+ z-index: -1;
box-shadow: -10px -5px 40px 0 rgba(0, 0, 0, 0.1);
padding: 50px 80px;
margin: 5%;
@@ -804,6 +838,7 @@ section {
}
.counts .count-box p {
+ z-index: -1;
padding: 30px 0 0 0;
/* margin: 0; */
font-family: "Roboto", sans-serif;
@@ -812,6 +847,7 @@ section {
}
.counts .count-box a {
+ z-index: -1;
font-weight: 600;
display: block;
/* margin-top: 10px; */
@@ -829,6 +865,7 @@ section {
/*################----Services----################*/
.services .icon-box {
+ z-index: -1;
text-align: center;
margin-left: 80px;
margin-right: 80px;
@@ -843,6 +880,7 @@ section {
}
.services .icon-box .icon {
+
margin: 0 auto;
width: 64px;
height: 64px;
@@ -857,11 +895,14 @@ section {
}
.services .icon-box .icon i {
+
color: #060606;
font-size: 28px;
}
.services .icon-box .icon::before {
+
+
position: absolute;
content: '';
left: -8px;
@@ -875,16 +916,19 @@ section {
}
.services .icon-box h4 {
+
font-weight: 700;
margin-bottom: 15px;
font-size: 24px;
}
.services .icon-box h4 a {
+
color: #55a5ea;
}
.services .icon-box p {
+
line-height: 24px;
font-size: 14px;
margin-bottom: 0;
From 63d65d1dcfd6e4b5a3661fb20a70e345e0c3625b Mon Sep 17 00:00:00 2001
From: sidhigrover <123989540+sidhigrover@users.noreply.github.com>
Date: Sat, 1 Jun 2024 15:25:19 +0530
Subject: [PATCH 3/3] I removed that API Key
---
chatboxx.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/chatboxx.js b/chatboxx.js
index b54b67b9..c02fc282 100644
--- a/chatboxx.js
+++ b/chatboxx.js
@@ -8,7 +8,7 @@ let userMessage = null; // Variable to store user's message
let appointmentStep = 0; // Variable to track the appointment scheduling steps
let selectedDoctor = null; // Variable to store the selected doctor
let appointmentDetails = {}; // Object to store appointment details
-const API_KEY = "PASTE-YOUR-API-KEY"; // Paste your API key here
+
const inputInitHeight = chatInput.scrollHeight;
const predefinedQA = {
+
+
+
+
From 0ee3377da71d2eec7a435f3b53e26a85beb6d187 Mon Sep 17 00:00:00 2001
From: sidhigrover <123989540+sidhigrover@users.noreply.github.com>
Date: Sat, 1 Jun 2024 01:07:00 +0530
Subject: [PATCH 2/3] Added New Chatbox and remove the old chatbox
---
chatbox.css | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++
chatboxx.js | 143 ++++++++++++++++++++++++++++++++++++++
index.html | 61 ++++++++--------
style.css | 44 ++++++++++++
4 files changed, 413 insertions(+), 32 deletions(-)
create mode 100644 chatbox.css
create mode 100644 chatboxx.js
diff --git a/chatbox.css b/chatbox.css
new file mode 100644
index 00000000..c52918b5
--- /dev/null
+++ b/chatbox.css
@@ -0,0 +1,197 @@
+/* Import Google font - Poppins */
+@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
+
+* {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ font-family: "Poppins", sans-serif;
+}
+body {
+
+}
+.chatbot-toggler {
+
+ position: fixed;
+ bottom: 30px;
+ right: 35px;
+ outline: none;
+ border: none;
+ height: 50px;
+ width: 50px;
+ display: flex;
+ cursor: pointer;
+ align-items: center;
+ justify-content: center;
+ border-radius: 50%;
+ background: #4178c0;
+ transition: all 0.2s ease;
+}
+body.show-chatbot .chatbot-toggler {
+ transform: rotate(90deg);
+}
+.chatbot-toggler span {
+ color: #fff;
+ position: absolute;
+}
+.chatbot-toggler span:last-child,
+body.show-chatbot .chatbot-toggler span:first-child {
+ opacity: 0;
+}
+body.show-chatbot .chatbot-toggler span:last-child {
+ opacity: 1;
+}
+.chatbot {
+ z-index: 1;
+ position: fixed;
+ right: 35px;
+ bottom: 90px;
+ width: 420px;
+ background: #fff;
+ border-radius: 15px;
+ overflow: hidden;
+ opacity: 0;
+ pointer-events: none;
+ transform: scale(0.5);
+ transform-origin: bottom right;
+ box-shadow: 0 0 128px 0 rgba(0,0,0,0.1),
+ 0 32px 64px -48px rgba(0,0,0,0.5);
+ transition: all 0.1s ease;
+}
+body.show-chatbot .chatbot {
+ opacity: 1;
+ pointer-events: auto;
+ transform: scale(1);
+}
+.chatbot header {
+ padding: 16px 0;
+ position: relative;
+ text-align: center;
+ color: #fff;
+ background: #4178c0;
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
+}
+.chatbot header span {
+ position: absolute;
+ right: 15px;
+ top: 50%;
+ display: none;
+ cursor: pointer;
+ transform: translateY(-50%);
+}
+header h2 {
+ font-size: 1.4rem;
+}
+.chatbot .chatbox {
+ overflow-y: auto;
+ height: 510px;
+ padding: 30px 20px 100px;
+}
+.chatbot :where(.chatbox, textarea)::-webkit-scrollbar {
+ width: 6px;
+}
+.chatbot :where(.chatbox, textarea)::-webkit-scrollbar-track {
+ background: #fff;
+ border-radius: 25px;
+}
+.chatbot :where(.chatbox, textarea)::-webkit-scrollbar-thumb {
+ background: #ccc;
+ border-radius: 25px;
+}
+.chatbox .chat {
+ display: flex;
+ list-style: none;
+}
+.chatbox .outgoing {
+ margin: 20px 0;
+ justify-content: flex-end;
+}
+.chatbox .incoming span {
+ width: 32px;
+ height: 32px;
+ color: #fff;
+ cursor: default;
+ text-align: center;
+ line-height: 32px;
+ align-self: flex-end;
+ background: #4178c0;
+ border-radius: 4px;
+ margin: 0 10px 7px 0;
+}
+.chatbox .chat p {
+ white-space: pre-wrap;
+ padding: 12px 16px;
+ border-radius: 10px 10px 0 10px;
+ max-width: 75%;
+ color: #fff;
+ font-size: 0.95rem;
+ background: #4178c0;
+}
+.chatbox .incoming p {
+ border-radius: 10px 10px 10px 0;
+}
+.chatbox .chat p.error {
+ color: #721c24;
+ background: #f8d7da;
+}
+.chatbox .incoming p {
+ color: #000;
+ background: #f2f2f2;
+}
+.chatbot .chat-input {
+ display: flex;
+ gap: 5px;
+ position: absolute;
+ bottom: 0;
+ width: 100%;
+ background: #fff;
+ padding: 3px 20px;
+ border-top: 1px solid #ddd;
+}
+.chat-input textarea {
+ height: 55px;
+ width: 100%;
+ border: none;
+ outline: none;
+ resize: none;
+ max-height: 180px;
+ padding: 15px 15px 15px 0;
+ font-size: 0.95rem;
+}
+.chat-input span {
+ align-self: flex-end;
+ color: #4178c0;
+ cursor: pointer;
+ height: 55px;
+ display: flex;
+ align-items: center;
+ visibility: hidden;
+ font-size: 1.35rem;
+}
+.chat-input textarea:valid ~ span {
+ visibility: visible;
+}
+
+@media (max-width: 490px) {
+ .chatbot-toggler {
+ right: 20px;
+ bottom: 20px;
+ }
+ .chatbot {
+ right: 0;
+ bottom: 0;
+ height: 100%;
+ border-radius: 0;
+ width: 100%;
+ }
+ .chatbot .chatbox {
+ height: 90%;
+ padding: 25px 15px 100px;
+ }
+ .chatbot .chat-input {
+ padding: 5px 15px;
+ }
+ .chatbot header span {
+ display: block;
+ }
+}
\ No newline at end of file
diff --git a/chatboxx.js b/chatboxx.js
new file mode 100644
index 00000000..b54b67b9
--- /dev/null
+++ b/chatboxx.js
@@ -0,0 +1,143 @@
+const chatbotToggler = document.querySelector(".chatbot-toggler");
+const closeBtn = document.querySelector(".close-btn");
+const chatbox = document.querySelector(".chatbox");
+const chatInput = document.querySelector(".chat-input textarea");
+const sendChatBtn = document.querySelector(".chat-input span");
+
+let userMessage = null; // Variable to store user's message
+let appointmentStep = 0; // Variable to track the appointment scheduling steps
+let selectedDoctor = null; // Variable to store the selected doctor
+let appointmentDetails = {}; // Object to store appointment details
+const API_KEY = "PASTE-YOUR-API-KEY"; // Paste your API key here
+const inputInitHeight = chatInput.scrollHeight;
+
+const predefinedQA = {
+ "Hi": "Hello",
+ "Hey":"Hello",
+ "How are you?": "I'm just a bot, but I'm doing great! How can I assist you today?",
+ "What is your name?": "I am a chatbot created to assist you.",
+ "Tell me a joke.": "Why don't scientists trust atoms? Because they make up everything!",
+ "What is RapiDoc?": "RapiDoc is an online platform which enables you to get information about your nearest hospitals and healthcare facilities. It aims to address health-related issues. It is a one-stop destination for all your medical needs.",
+ "How can RapiDoc help me?": "RapiDoc helps you find the nearest hospitals and healthcare facilities, ensuring you have access to necessary medical information and services quickly and easily.",
+ "What services does RapiDoc provide?": "RapiDoc provides information on nearby hospitals, healthcare facilities, and various medical services to address your health-related needs.",
+ "Make an appointment": "Sure, here are some doctors available for appointments:\n1. Dr. Vikas Chopra\n2. Dr. Ajay Aggarwal\n3. Dr. Soni Gupta\nPlease type the number of the doctor you want to make an appointment with."
+};
+
+const doctorsList = {
+ "1": "Dr. Vikas Chopra",
+ "2": "Dr. Ajay Aggarwal",
+ "3": "Dr. Soni Gupta"
+};
+
+const createChatLi = (message, className) => {
+ const chatLi = document.createElement("li");
+ chatLi.classList.add("chat", `${className}`);
+ let chatContent = className === "outgoing" ? `` : `smart_toy`;
+ chatLi.innerHTML = chatContent;
+ chatLi.querySelector("p").textContent = message;
+ return chatLi;
+}
+
+const generateResponse = (chatElement) => {
+ const API_URL = "https://api.openai.com/v1/chat/completions";
+ const messageElement = chatElement.querySelector("p");
+
+ const requestOptions = {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ "Authorization": `Bearer ${API_KEY}`
+ },
+ body: JSON.stringify({
+ model: "gpt-3.5-turbo",
+ messages: [{ role: "user", content: userMessage }],
+ })
+ }
+
+ fetch(API_URL, requestOptions).then(res => res.json()).then(data => {
+ messageElement.textContent = data.choices[0].message.content.trim();
+ }).catch(() => {
+ messageElement.classList.add("error");
+ messageElement.textContent = "Oops! Something went wrong. Please try again.";
+ }).finally(() => chatbox.scrollTo(0, chatbox.scrollHeight));
+}
+
+const handleAppointment = (userMessage) => {
+ if (appointmentStep === 0) {
+ selectedDoctor = doctorsList[userMessage];
+ if (!selectedDoctor) {
+ chatbox.appendChild(createChatLi("Invalid doctor number. Please try again.", "incoming"));
+ return;
+ }
+ chatbox.appendChild(createChatLi(`You selected ${selectedDoctor}. Please enter the date for your appointment (YYYY-MM-DD).`, "incoming"));
+ appointmentStep++;
+ } else if (appointmentStep === 1) {
+ const date = userMessage;
+ if (!date.match(/^\d{4}-\d{2}-\d{2}$/)) {
+ chatbox.appendChild(createChatLi("Invalid date format. Please enter the date in YYYY-MM-DD format.", "incoming"));
+ return;
+ }
+ appointmentDetails.date = date;
+ chatbox.appendChild(createChatLi("Please enter the time for your appointment (HH:MM).", "incoming"));
+ appointmentStep++;
+ } else if (appointmentStep === 2) {
+ const time = userMessage;
+ if (!time.match(/^\d{2}:\d{2}$/)) {
+ chatbox.appendChild(createChatLi("Invalid time format. Please enter the time in HH:MM format.", "incoming"));
+ return;
+ }
+ appointmentDetails.time = time;
+ chatbox.appendChild(createChatLi(`Appointment scheduled with ${selectedDoctor} on ${appointmentDetails.date} at ${appointmentDetails.time}.`, "incoming"));
+ appointmentStep = 0;
+ selectedDoctor = null;
+ appointmentDetails = {};
+ }
+}
+
+const handleChat = () => {
+ userMessage = chatInput.value.trim();
+ if (!userMessage) return;
+
+ chatInput.value = "";
+ chatInput.style.height = `${inputInitHeight}px`;
+
+ chatbox.appendChild(createChatLi(userMessage, "outgoing"));
+ chatbox.scrollTo(0, chatbox.scrollHeight);
+
+ if (appointmentStep > 0) {
+ handleAppointment(userMessage);
+ } else if (predefinedQA[userMessage]) {
+ setTimeout(() => {
+ const incomingChatLi = createChatLi(predefinedQA[userMessage], "incoming");
+ chatbox.appendChild(incomingChatLi);
+ chatbox.scrollTo(0, chatbox.scrollHeight);
+ }, 600);
+ } else if (Object.keys(doctorsList).includes(userMessage)) {
+ setTimeout(() => {
+ handleAppointment(userMessage);
+ }, 600);
+ } else {
+ setTimeout(() => {
+ const incomingChatLi = createChatLi("Thinking...", "incoming");
+ chatbox.appendChild(incomingChatLi);
+ chatbox.scrollTo(0, chatbox.scrollHeight);
+ generateResponse(incomingChatLi);
+ }, 600);
+ }
+}
+
+chatInput.addEventListener("input", () => {
+ chatInput.style.height = `${inputInitHeight}px`;
+ chatInput.style.height = `${chatInput.scrollHeight}px`;
+});
+
+chatInput.addEventListener("keydown", (e) => {
+ if (e.key === "Enter" && !e.shiftKey && window.innerWidth > 800) {
+ e.preventDefault();
+ handleChat();
+ }
+});
+
+sendChatBtn.addEventListener("click", handleChat);
+closeBtn.addEventListener("click", () => document.body.classList.remove("show-chatbot"));
+chatbotToggler.addEventListener("click", () => document.body.classList.toggle("show-chatbot"));
diff --git a/index.html b/index.html
index c6190282..165bfaaa 100644
--- a/index.html
+++ b/index.html
@@ -46,10 +46,38 @@
+
+
+
+
+
+
+
+ Chatbot
+ close +-
+
-
+ smart_toy
+
Welcome to CSEdge 👋 How I can help You Today + + +
+ + + + + + + + + +
+
+
+ send
+
+
+
+
+
+
+
Chatbot
+ close +-
+
-
+ smart_toy
+
Hi there 👋
+
How can I help you today?
+
+
+ send
+
+
-
-
-
- Chatbot
- close
-
-
- -
- smart_toy
-
Welcome to CSEdge 👋 How I can help You Today
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- send
-
-
-
-
@@ -948,7 +945,7 @@
-
+
diff --git a/style.css b/style.css
index d3c80dae..63b59073 100644
--- a/style.css
+++ b/style.css
@@ -124,6 +124,7 @@ h6 {
padding: 20px;
margin-bottom: 20px;
border-radius: 10px;
+ z-index: -1;
}
@@ -141,11 +142,13 @@ h6 {
transition: 0.3s;
font-size: 16px;
font-weight: 600;
+ z-index: -1;
display: inline-block;
}
.appointment-btn:hover {
background: #55a5ea;
+ z-index: -1;
color: #fff;
}
@@ -449,6 +452,7 @@ section {
}
.featured-services .icon-box {
+ z-index: -1;
width: 230px;
height: 270px;
margin-left: 15px;
@@ -466,6 +470,7 @@ section {
}
.featured-services .icon-box::before {
+ z-index: -1;
content: '';
position: absolute;
background: #000;
@@ -478,16 +483,19 @@ section {
}
.featured-services .icon-box:hover::before {
+ z-index: -1;
background: #3fbcc051;
top: 0px;
border-radius: 50px;
}
.featured-services .icon1 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon1 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #3fbcc0a4;
@@ -495,10 +503,12 @@ section {
}
.featured-services .icon2 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon2 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #55a5ea;
@@ -506,10 +516,12 @@ section {
}
.featured-services .icon3 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon3 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #55a5ea;
@@ -517,10 +529,12 @@ section {
}
.featured-services .icon4 {
+ z-index: -1;
margin-bottom: 15px;
}
.featured-services .icon4 i {
+ z-index: -1;
font-size: 48px;
line-height: 1;
color: #55a5ea;
@@ -568,12 +582,14 @@ section {
/*################----About----################*/
.about .icon-boxes h4 {
+ z-index: -1;
font-size: 18px;
color: #55a5ea;
margin-bottom: 15px;
}
.about .icon-boxes h3 {
+ z-index: -1;
font-size: 28px;
font-weight: 700;
color: #55a5ea;
@@ -581,6 +597,7 @@ section {
}
.about .icon-box {
+ z-index: -1;
background: #111111;
border-radius: 10px;
margin-top: 35px;
@@ -589,6 +606,7 @@ section {
}
.about .icon-box .icon {
+ z-index: -1;
float: left;
display: flex;
align-items: center;
@@ -601,20 +619,24 @@ section {
}
.about .icon-box .icon i {
+ z-index: -1;
color: #3fbcc0a4;
font-size: 32px;
}
.about .icon-box:hover .icon {
+ z-index: -1;
background: #55a5ea;
border-color: #55a5ea;
}
.about .icon-box:hover .icon i {
+ z-index: -1;
color: #fff;
}
.about .icon-box .title {
+ z-index: -1;
margin-left: 85px;
font-weight: 700;
@@ -623,6 +645,7 @@ section {
}
.about .icon-box .title a {
+ z-index: -1;
color: #fff;
transition: 0.3s;
font-size: 18px;
@@ -630,16 +653,19 @@ section {
}
.about .icon-box .title a:hover {
+ z-index: -1;
color: #55a5ea;
}
.about .icon-box .description {
+ z-index: -1;
margin-left: 85px;
line-height: 24px;
font-size: 14px;
}
.about .video-box {
+ z-index: -1;
background: url("../img/about.png") center center no-repeat;
background-size: cover;
height: 300px;
@@ -648,6 +674,7 @@ section {
.about .play-btn {
width: 94px;
+ z-index: -1;
height: 94px;
background: radial-gradient(#55a5ea 50%, rgba(4, 196, 234, 0.4) 52%);
border-radius: 50%;
@@ -659,6 +686,7 @@ section {
}
.about .play-btn::after {
+ z-index: -1;
content: '';
position: absolute;
left: 50%;
@@ -674,6 +702,7 @@ section {
}
.about .play-btn::before {
+ z-index: -1;
content: '';
position: absolute;
width: 120px;
@@ -687,12 +716,14 @@ section {
}
.about .play-btn:hover::after {
+ z-index: -1;
border-left: 15px solid #55a5ea;
transform: scale(20);
}
.about .play-btn:hover::before {
content: '';
+ z-index: -1;
position: absolute;
left: 50%;
top: 50%;
@@ -738,10 +769,13 @@ section {
/*################----Counts----################*/
.counts {
/* padding-top: 30px; */
+
justify-content: center;
}
+
.counts .count-box {
+ z-index: -1;
box-shadow: -10px -5px 40px 0 rgba(0, 0, 0, 0.1);
padding: 50px 80px;
margin: 5%;
@@ -804,6 +838,7 @@ section {
}
.counts .count-box p {
+ z-index: -1;
padding: 30px 0 0 0;
/* margin: 0; */
font-family: "Roboto", sans-serif;
@@ -812,6 +847,7 @@ section {
}
.counts .count-box a {
+ z-index: -1;
font-weight: 600;
display: block;
/* margin-top: 10px; */
@@ -829,6 +865,7 @@ section {
/*################----Services----################*/
.services .icon-box {
+ z-index: -1;
text-align: center;
margin-left: 80px;
margin-right: 80px;
@@ -843,6 +880,7 @@ section {
}
.services .icon-box .icon {
+
margin: 0 auto;
width: 64px;
height: 64px;
@@ -857,11 +895,14 @@ section {
}
.services .icon-box .icon i {
+
color: #060606;
font-size: 28px;
}
.services .icon-box .icon::before {
+
+
position: absolute;
content: '';
left: -8px;
@@ -875,16 +916,19 @@ section {
}
.services .icon-box h4 {
+
font-weight: 700;
margin-bottom: 15px;
font-size: 24px;
}
.services .icon-box h4 a {
+
color: #55a5ea;
}
.services .icon-box p {
+
line-height: 24px;
font-size: 14px;
margin-bottom: 0;
From 63d65d1dcfd6e4b5a3661fb20a70e345e0c3625b Mon Sep 17 00:00:00 2001
From: sidhigrover <123989540+sidhigrover@users.noreply.github.com>
Date: Sat, 1 Jun 2024 15:25:19 +0530
Subject: [PATCH 3/3] I removed that API Key
---
chatboxx.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/chatboxx.js b/chatboxx.js
index b54b67b9..c02fc282 100644
--- a/chatboxx.js
+++ b/chatboxx.js
@@ -8,7 +8,7 @@ let userMessage = null; // Variable to store user's message
let appointmentStep = 0; // Variable to track the appointment scheduling steps
let selectedDoctor = null; // Variable to store the selected doctor
let appointmentDetails = {}; // Object to store appointment details
-const API_KEY = "PASTE-YOUR-API-KEY"; // Paste your API key here
+
const inputInitHeight = chatInput.scrollHeight;
const predefinedQA = {
-
-
-
-
-
@@ -948,7 +945,7 @@ Chatbot
- close --
-
-
- smart_toy
-
Welcome to CSEdge 👋 How I can help You Today - - -
- - - - - - - - - -
-
-
- send
-
-