-
Notifications
You must be signed in to change notification settings - Fork 22
/
chatbot.html
578 lines (539 loc) · 19.5 KB
/
chatbot.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
<!-- <script src="vendor/jquery/jquery.min.js"></script> -->
<!-- <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script> -->
<!--
<script src="assets/js/isotope.min.js"></script>
<script src="assets/js/owl-carousel.js"></script>
<script src="assets/js/lightbox.js"></script>
<script src="assets/js/tabs.js"></script>
<script src="assets/js/video.js"></script>
<script src="assets/js/slick-slider.js"></script>
<script src="assets/js/custom.js"></script> -->
<style>
body {
background: rgb(17, 102, 126);
background: -moz-radial-gradient(
circle,
rgba(17, 102, 126, 1) 0%,
rgba(0, 8, 81, 1) 100%
);
font-family: sans-serif;
}
#chatbot-container {
z-index: 999;
color: #2c2325;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
backdrop-filter: grayscale(0.8);
}
#chatbot-interface {
height: 70vh;
width: 60vw;
background-color: #2c2325;
border-radius: 1rem;
margin-top:0%;
}
#chatbot-header {
font-weight: 600;
border-top-left-radius: 1rem;
border-top-right-radius: 1rem;
background: radial-gradient(
ellipse farthest-corner at right bottom,
#fedb37 0%,
#fdb931 8%,
#9f7928 30%,
#8a6e2f 40%,
transparent 80%
),
radial-gradient(
ellipse farthest-corner at left top,
#d1b464 25%,
#5d4a1f 62.5%,
#5d4a1f 100%
);
padding: 0.2rem;
padding-left: 1.5rem;
padding-right: 1.5rem;
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
}
#chatbot-chat {
/* height: calc(100% - 56.9px - 6rem); */
height: 80%;
border-bottom-left-radius: 1rem;
border-bottom-right-radius: 1rem;
padding: 1rem;
overflow-y: scroll;
display: flex;
flex-direction: column-reverse;
}
.chatbot-messages {
padding: 1rem;
padding-top: 0.2rem;
padding-bottom: 0.2rem;
border-radius: 1rem;
margin-top: 0.3rem;
margin-bottom: 0.3rem;
width: fit-content;
}
.chatbot-received-messages {
background: radial-gradient(
ellipse farthest-corner at right bottom,
#fdb931 8%,
#9f7928 30%,
#8a6e2f 40%,
transparent 80%
),
radial-gradient(
ellipse farthest-corner at left top,
#d1b464 25%,
#5d4a1f 62.5%,
#5d4a1f 100%
);
filter: grayscale(0.3);
border-top-left-radius: 0rem;
}
.chatbot-button {
padding: 1rem;
padding-top: 0.2rem;
padding-bottom: 0.2rem;
border-radius: 1rem;
margin-top: 0.3rem;
margin-bottom: 0.3rem;
width: fit-content;
}
.chatbot-received-button {
background-color: #29dcec;
/* background: radial-gradient(
ellipse farthest-corner at right bottom,
#eed742 8%,
#e1e665 30%,
#edae1b 40%,
transparent 80%
),
radial-gradient(
ellipse farthest-corner at left top,
#29dcec 25%,
#69b4dd 62.5%,
#659abd 100%
); */
filter: grayscale(0.3);
border-top-left-radius: 0rem;
}
.chatbot-sent-messages {
color: white;
background-color: #574449;
border-top-right-radius: 0rem;
margin-left: auto;
margin-right: 0;
}
#chatbot-footer {
padding: 2rem;
padding-top: 1rem;
padding-bottom: 1rem;
display: flex;
margin-bottom:50px;
flex-wrap: nowrap;
justify-content: space-around;
align-items: center;
}
#chatbot-input-container {
width: calc(100%);
}
#chatbot-input {
width: calc(100% - 2rem);
padding: 0.5rem;
color: white;
background-color: #574449;
border: 0.1rem solid #574449;
border-radius: 1rem;
}
#chatbot-input:focus {
outline-offset: 0px !important;
outline: none !important;
border: 0.1rem solid #8a6e2f;
/*box-shadow: 0 0 5px #FDB931 !important;*/
}
#chatbot-new-message-send-button {
cursor: pointer;
}
#send-icon {
color: white;
}
#chatbot-open-container {
position: fixed;
bottom: 1rem;
right: 1rem;
background: radial-gradient(
ellipse farthest-corner at right bottom,
#fedb37 0%,
#fdb931 8%,
#9f7928 30%,
#8a6e2f 40%,
transparent 80%
),
radial-gradient(
ellipse farthest-corner at left top,
#d1b464 25%,
#5d4a1f 62.5%,
#5d4a1f 100%
);
padding: 1rem;
border-radius: 50%;
width: 3.5rem;
height: 3.5rem;
text-align: center;
cursor: pointer;
z-index: 1000;
}
#chatbot-open-container i {
padding-top: 0.25rem;
font-size: 3rem;
color: #2c2325;
}
</style>
</head>
<body>
<div id="chatbot-container">
<div id="chatbot-interface">
<div id="chatbot-header">
<p>Smart Tutor And Guidance</p>
<button
class="chatbot-messages chatbot-sent-messages"
id="cancelcourse"
onclick="cancelcourse()"
style="font-weight: bold"
>
Cancel Course
</button>
</div>
<div id="chatbot-chat">
<div class="chatbot-messages chatbot-received-messages">
<p>Please type "start" to start conversation.</p>
</div>
<div class="chatbot-messages chatbot-received-messages">
<p>Hey Learner! I am IRIS, Smart-Tutor.</p>
</div>
</div>
<div id="chatbot-footer">
<div id="chatbot-input-container">
<input
type="text"
id="chatbot-input"
name="chatbot-input"
placeholder="Type a command here..."
/>
</div>
<div id="chatbot-new-message-send-button" onclick="newInput()">
<i class="material-icons" id="send-icon">send</i>
</div>
</div>
</div>
</div>
<button
onclick="gotoindex()"
style="
background-image: url('cancellogo.png');
background-repeat: no-repeat;
background-size: cover;
"
id="chatbot-open-container"
></button>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function gotoindex() {
window.location.replace("index.html");
}
const chat = document.getElementById("chatbot-chat");
$("#chatbot-open-container").click(function () {
$("#open-chat-button").toggle(200);
$("#close-chat-button").toggle(200);
$("#chatbot-container").fadeToggle(200);
});
document
.getElementById("chatbot-new-message-send-button")
.addEventListener("click", newInput);
document
.getElementById("chatbot-input")
.addEventListener("keypress", function (e) {
if (e.key === "Enter") {
newInput();
}
});
var mno = 0;
function newInput() {
newText = document.getElementById("chatbot-input").value;
newText=newText.toLowerCase();
if (newText == "") {
} else if (newText == "start" && subjectchosen == "") {
document.getElementById("chatbot-input").value = "";
addMessage("sent", newText);
generateResponse(newText, 0);
} else if (newText == "start" && subjectchosen != "") {
document.getElementById("chatbot-input").value = "";
addMessage("sent", newText);
mno = 1;
generateResponse(newText, subjectchosen);
} else {
document.getElementById("chatbot-input").value = "";
addMessage("sent", newText);
generateResponse(newText, -1);
}
}
function cancelcourse() {
mno = 0;
c = 0;
subjectchosen = "";
localStorage.setItem("studentsubject", "");
addMessage("sent", "I have left the Course now");
addMessage("received", "Thank You.,Have a Great day and keep Learning");
document.getElementById("cancelcourse").disabled = true;
document.getElementById("cancelcourse").innerHTML = "course cancelled";
}
function addMessage(type, text) {
let messageDiv = document.createElement("div");
let responseText = document.createElement("p");
responseText.appendChild(document.createTextNode(text));
// messageDiv.onclick = function () { alert("hi");}
if (type == "sent") {
messageDiv.classList.add("chatbot-messages", "chatbot-sent-messages");
} else if (type == "received") {
messageDiv.classList.add("chatbot-messages", "chatbot-received-messages");
}
messageDiv.appendChild(responseText);
chat.prepend(messageDiv);
}
function addbutton(type, text, c) {
let messageDiv = document.createElement("button");
let responseText = document.createElement("p");
responseText.appendChild(document.createTextNode(text));
messageDiv.setAttribute("onclick", "checkbutton(" + c + ");");
if (type == "sent") {
messageDiv.classList.add("chatbot-messages", "chatbot-sent-messages");
} else if (type == "received") {
messageDiv.classList.add("chatbot-button", "chatbot-received-button");
// messageDiv.style.backgroundColor="blue";
}
messageDiv.appendChild(responseText);
chat.prepend(messageDiv);
}
var i = 0;
// function websubjectchat() {}
// var subject=["web","app","dsa","python"];
var subject = [
{
name: "web",
topic: [
{
message: "Yeah! You have Chosen Web Development Course.",
button: [],
},
{
message:
"So what do you want from me? I can provide This amazing facilities about this course",
button: ["Courses Videos", "Study Materials", "Practice Problems"],
},
{
message:
"So Welcome to Web Development,I have provided some lectures now.",
button: ["https://www.youtube.com/watch?v=l1EssrLxt7E&list=PLfqMhTWNBTe3H6c9OGXb5_6wcc1", "https://www.youtube.com/watch?v=l1EssrLxt7E&list=PLfqMhTWNBTe3H6c9OGXb5_6wcc1Mca52n", "https://www.youtube.com/watch?v=9Y8iq5fDL38&list=PLhzIaPMgkbxDxVcH-M-JFM73PY1R_i2mK"],
},
{
message:
"So Welcome to Web Development,I have provided some study materials/Documentation.",
button: ["https://www.w3schools.com/whatis/", "https://developers.google.com/web", "https://sasit.rutgers.edu/how-to-guides/web-development-documentation/web-development"],
},
{
message:
"So Welcome to Web Development,I have provided some practice question links.",
button: ["https://www.teamwork.com/blog/web-development-projects/", "https://www.upgrad.com/blog/web-development-project-ideas-for-beginners/", "https://www.interviewbit.com/blog/web-development-projects/"],
},
{
message: "Do You To Exit From this Course?",
button: ["Yes", "No"],
},
],
},
{
name: "app",
topic: [
{
message: "Yeah! You have Chosen Android Development Course.",
button: [],
},
{
message:
"So what do you want from me? I can provide This amazing facilities about this course",
button: ["Courses Videos", "Study Materials", "Practice Problems"],
},
{
message:
"So Welcome to android Development,I have provided some lectures.",
button: ["https://www.youtube.com/watch?v=InigFUSiPl8&list=PLu0W_9lII9aiL0kysYlfSOUgY5rNlOhUd", "https://www.youtube.com/watch?v=HyU4vkZ2NB8&list=PLjVLYmrlmjGdDps6HAwOOVoAtBPAgIOXL", "https://www.youtube.com/watch?v=NLvaOL6Cm48&list=PL6Q9UqV2Sf1gHCHOKYLDofElSvxtRRXOR"],
},
{
message:
"So Welcome to android Development,I have provided some study materials/Documentation.",
button: ["https://developer.android.com/docs", "https://developers.google.com/maps/documentation/android-sdk/overview", "https://developer.android.com/studio/intro"],
},
{
message:
"So Welcome to android Development,I have provided some practice question links.",
button: ["https://www.knowledgehut.com/blog/web-development/android-project-ideas", "https://www.geeksforgeeks.org/android-projects-from-basic-to-advanced-level/", "https://www.upgrad.com/blog/android-project-ideas-topics-for-beginners/"],
},
{
message: "Do You To Exit From this Course?",
button: ["Yes", "No"],
},
],
},
{
name: "python",
topic: [
{
message: "Yeah! You have Chosen python Language Course.",
button: [],
},
{
message:
"So what do you want from me? I can provide This amazing facilities about this course",
button: ["Courses Videos", "Study Materials", "Practice Problems"],
},
{
message:
"So Welcome to python Language ,I have provided some lectures.",
button: ["https://www.youtube.com/watch?v=QXeEoD0pB3E&list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3", "https://www.youtube.com/watch?v=YYXdXT2l-Gg&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU", "https://www.youtube.com/watch?v=7wnove7K-ZQ&list=PLu0W_9lII9agwh1XjRt242xIpHhPT2llg"],
},
{
message:
"So Welcome to Python Language,I have provided some study materials/Documentation.",
button: ["https://www.w3schools.com/python/", "https://www.tutorialspoint.com/python/index.htm", "https://www.javatpoint.com/python-tutorial"],
},
{
message:
"So Welcome to Python Language,I have provided some practice question links.",
button: ["lhttps://www.geeksforgeeks.org/python-exercises-practice-questions-and-solutions/", "https://www.w3resource.com/python-exercises/", "https://pynative.com/python-exercises-with-solutions/"],
},
{
message: "Do You To Exit From this Course?",
button: ["Yes", "No"],
},
],
},
{
name: "dsa",
topic: [
{
message: "Yeah! You have Chosen Data Structure and Algorithm Course.",
button: [],
},
{
message:
"So what do you want from me? I can provide This amazing facilities about this course",
button: ["Courses Videos", "Study Materials", "Practice Problems"],
},
{
message:
"So Welcome to Data Structure and Algorithm ,I have provided some lectures.",
button: ["https://www.youtube.com/watch?v=WQoB2z67hvY&list=PLDzeHZWIZsTryvtXdMr6rPh4IDexB5NIA", "https://www.youtube.com/watch?v=5_5oE5lgrhw&list=PLu0W_9lII9ahIappRPN0MCAgtOu3lQjQi", "https://www.youtube.com/watch?v=7wnove7K-ZQ&list=PLu0W_9lII9agwh1XjRt242xIpHhPT2llg"],
},
{
message:
"So Welcome to Data Structure and Algorithm ,I have provided some study materials/Documentation.",
button: ["https://www.geeksforgeeks.org/learn-data-structures-and-algorithms-dsa-tutorial/", "https://www.tutorialspoint.com/data_structures_algorithms/index.htm", "https://www.javatpoint.com/data-structure-tutorial"],
},
{
message:
"So Welcome to Data Structure and Algorithm ,I have provided some practice question links.",
button: ["https://practice.geeksforgeeks.org/explore?page=1&sortBy=submissions&source=google&medium=cpc&device=c&keyword=gfg%20dsa%20practice&matchtype=b&campaignid=19552155281&adgroup=145127760237&gad=1&gclid=Cj0KCQjwqs6lBhCxARIsAG8YcDjnBwieV3dKEk78eYa4XBB9RTly2dccffh4G9R3EBmp_Iw8kJuucEkaAm5yEALw_wcB", "https://workat.tech/problem-solving/practice/topics", "https://www.tutorialspoint.com/data_structures_algorithms/data_structures_algorithms_questions_answers.htm"],
},
{
message: "Do You To Exit From this Course?",
button: ["Yes", "No"],
},
],
},
];
// console.log(subject);
var subjectchosen = localStorage.getItem("studentsubject");
// subjectchosen = "web";
// if(subjectchosen=="web"){
// addMessage("received",web[i].message);
// }
var check;
function generateResponse(prompt, status) {
// Here you can add your answer-generating code
// alert(status);
if (status == 0) {
addMessage(
"received",
"You have Not Taken Any Course Yet.Please Select a course from home page."
);
} else if (status == -1) {
addMessage(
"received",
"Wrong information!Please type 'start' to start conversation."
);
// addMessage("received", "Great to hear that!");
} else {
var mes = "",
mes1 = "";
// var check;
for (var j = 0; j < subject.length; j++) {
if (subject[j].name == status) {
mes = subject[j].topic[0].message;
mes1 = subject[j].topic[1].message;
check = j;
break;
}
}
addMessage("received", mes);
addMessage("received", mes1);
for (var c = 0; c < subject[check].topic[1].button.length; c++) {
addbutton("received", subject[check].topic[1].button[c], c);
}
}
}
function checkbutton(k) {
if (k == -1) {
document.getElementById("chatbot-input").value = "start";
newInput();
document.getElementById("chatbot-input").value = "";
return;
}
k = k + 1;
// alert(mno+" "+k);
addMessage("received", subject[check].topic[mno + k].message);
for (var c = 0; c < subject[check].topic[mno + k].button.length; c++) {
addMessage("received", subject[check].topic[mno + k].button[c]);
}
addbutton("received", "Go Back To Previous Menu", -1);
}
</script>
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/isotope.min.js"></script>
<script src="assets/js/owl-carousel.js"></script>
<script src="assets/js/lightbox.js"></script>
<script src="assets/js/tabs.js"></script>
<script src="assets/js/video.js"></script>
<script src="assets/js/slick-slider.js"></script>
<script src="assets/js/custom.js"></script>
<!-- <script>
// var web=[,,,"So Welcome to Web Development,We have provided some ."];
</script> -->