forked from abhi170599/VH_HPE_Chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
701 lines (529 loc) · 26.5 KB
/
main.js
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
let ip = "localhost:5000";
function wait(ms) {
var start = Date.now(),
now = start;
while (now - start < ms) {
now = Date.now();
}
}
let load = `
<img src="https://thumbs.gfycat.com/ObviousQuarrelsomeIntermediateegret-max-1mb.gif" align="center" style="margin-left: 42.5%; margin-top: 12%; height: 200px; width: 200px;">
<p class="h3-h" align="center">LOADING...</p>
`;
let newDOM = `
<!-- ################################################################################################# -->
<div class="headerBar">
<div class="user-photo"><img src="Images/face.png"></div>
<p class="title">Ana Datanautix</p>
<button id="exit"><img src="last.ico" style="height: 40px; width:40px; margin-left: 200%; margin-top: 24%; opacity: 0.8;"></button>
</div>
<!-- ################################################################################################# -->
<div class="chatbox">
<div class="chatlogs" id="chatArea">
<div class="chat friend">
<div class="user-photo"><img src="Images/face.png"></div>
<p class="chat-message">Hello, ask me anything!</p>
</div>
<div class="chat friend" id="loadingGif" style="display: none;">
<div class="user-photo"><img src="Images/face.png"></div>
<div class="gif"><img src="Images/loading.gif"></div>
</div>
</div>
</div>
<!-- ################################################################################################# -->
<div class="chat-form">
<div id="inputDiv">
<div id="buttonDiv"></div>
<textarea id="msg_inp" class="input" placeholder="Message" rows="1" data-min-rows='1'></textarea>
</div>
<div id="chat-form-buttons">
<input type ="image"id="mike" src="Images/microphone.png">
</div>
<div id="chat-form-buttons">
<input type ="image" id="rec" src="Images/send_icon.png">
</div>
</div>
</div>
</div>
<!-- ################################################################################################# -->
`;
function Autocomplete(){
var questions = ["What are the advantages of HPE OneView",
"What is a software-defined approach to lifecycle management",
"Can I customize functionality and integrate HPE OneView with my existing tools and environment",
"Does HPE provide integration kits for customers who do not wish to develop their own",
"Is HPE OneView a refresh to existing HPE infrastructure management tools or a brand-new design",
"What capabilities does HPE OneView offer",
"How is HPE OneView licensed",
"What server platforms are supported by HPE OneView 5.0",
"Can I create a template from an existing profile",
"Does HPE OneView support granular access control",
"What is two-factor authentication and is it supported by HPE OneView",
"What is an SPP",
"Does HPE OneView use SPPs to update the firmware and driver of servers",
"Does HPE OneView support external repository to store SPPs",
"Can you schedule the activation of firmware and OS driver updates",
"Does HPE OneView allow online profile configuration changes",
"What tools HPE OneView use for Firmware and Driver updates",
"How does HPE OneView handle Firmware and Driver updates",
"Does HPE OneView support configuration of iLO settings",
"What are the latest enhancements with HPE OneView Remote support",
"What kind of cluster profile support is offered by HPE OneView",
"Can I view DIMM inventory with HPE OneView",
"Does HPE OneView support IPv6",
"Does HPE OneView provide firmware compliance checking:",
"Does HPE OneView support HPE 3PAR StoreServ",
"Does HPE OneView support HPE Nimble Storage",
"If Flat SAN is used, can you see FC bandwidth usage data",
"What is the HPE OneView support for Brocade FC ICM",
"What can I use for Brocade SAN automated zoning with BNA support going away",
"Does HPE OneView support automated volume provisioning",
"Does HPE OneView support HPE StoreVirtual 3200 series",
"Does HPE OneView support StoreVirtual managed nodes",
"Does HPE OneView support automated SAN Storage volume provisioning for DL/Apollo Servers",
"Does HPE OneView support Brocade SAN storage",
"Can I do a migration from the Virtual Connect Manager to an HPE OneView environment without the need to power off servers",
"How many FlexNIC/FlexHBA per port does the FlexFabric support in HPE OneView",
"What is the integration with the IMC tool",
"Does HPE OneView support the B22HP FEX interconnect modules",
"Does HPE OneView support the LACP on s-channels",
"What is an Active/Active configuration",
"How does HPE OneView work with HPE switches,What can be done today in terms of management and configuration",
"Can HPE OneView manage the external top-of-rack Cisco (ToR) switch",
"Can HPE OneView manage the external top-of-rack Arista (ToR) switch",
"What is HPE Composable Ecosystem Program",
"What Microsoft plug-ins are in the HPE OneView Advanced 5.0 release",
"What VMware plug-ins are in the HPE OneView Advanced 5.0 release",
"How are the partner integrations licensed for VMware and Microsoft",
"How is HPE OneView delivered",
"Does HPE OneView replace the need for HPE Systems Insight Manager, HPE Insight Control, and HPE Virtual Connect Enterprise Manager",
"How long will Hewlett Packard Enterprise support the current HPE SIM, product",
"Are license upgrades available from Insight Management software to HPE OneView Advanced",
"What support and services are available for HPE OneView",
"How do I get training on HPE OneView",
"Can a user access inventory and health status information consolidated by HPE OneView Global Dashboard using an API",
"How does HPE OneView Global Dashboard help customers manage at scale",
"What systems does HPE Global Dashboard support",
"How is HPE OneView Global Dashboard delivered",
"Can I schedule an HPE OneView Global Dashboard report",
"How can I track the assignment of HPE OneView licensed across my data centers",
"Does HPE OneView Global Dashboard support IPv6",
"Does HPE OneView Global Dashboard support interconnect modules",
"Does HPE OneView Global Dashboard display remote support status",
"Does Remote Technician require Remote Support",
"Is there a charge for Remote Technician",
"Is a support case required for Remote Technician",
"Do I need to add firewall rules",
"Can I time-box access , Does it time out",
"Will the access be tracked and audited—what somebody did to what resource at what time",
"Will keystrokes be captured",
"What is the benefit of this versus using HPE MyRoom for screen sharing",
"Does Remote Technician make it easier to provide support dumps and logs",
"Is this technology unique to HPE OneView—how mature is it,How many people are using it",
"Will Remote Technician be available for Image Streamer",
"Is there a terminate remote technician if something is amiss"];
$( "#msg_inp" ).autocomplete({
source: questions,
position: {
my: "left top",
at: "left bottom",
collision: "flip"
},
minlength: 3,
collision: "fit"
});
}
// Function for Logging in
function Login (name, pass) {
var arr = {'username':name, 'password': pass};
loading();
$.ajax(
{
url: "http://" + ip + "/signin",
type: "POST",
data: JSON.stringify(arr),
contentType: 'application/json;charset=UTF-8',
success: function(res) {
console.log(res);
if(res.data){
localStorage.token = res.data.token;
console.log('Got a token from the server! Token: ' + localStorage.token);
localStorage.userid = res.data.id;
localStorage.name = res.data.username;
console.log(localStorage.userid + " " + localStorage.name);
chat(localStorage.userid);
}
wait(2000);
if(res.data){
let dom = document.querySelector(".container_new");
dom.remove();
let new_dom = document.createElement("div");
let a_atr = document.createAttribute("class");
a_atr.value = "container";
new_dom.setAttributeNode(a_atr);
new_dom.innerHTML = newDOM;
document.body.appendChild(new_dom);
//document.body.appendChild(recording);
btn = document.getElementById("rec");
msg = document.getElementById("msg_inp");
exit = document.getElementById("exit");
btn.addEventListener("click", function(){
let text = msg.value;
send(text);
msg.value = "";
});
$('#msg_inp').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
let text = msg.value;
send(text);
msg.value = "";
}
});
exit.addEventListener("click",function(){
Logout();
})
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;
let finalTranscript = '';
let recognition = new window.SpeechRecognition();
recognition.interimResults = true;
recognition.maxAlternatives = 10;
recognition.continuous = false;
recognition.onresult = (event) => {
let interimTranscript = '';
for (let i = event.resultIndex, len = event.results.length; i < len; i++) {
let transcript = event.results[i][0].transcript;
if (event.results[i].isFinal) {
finalTranscript = transcript;
} else {
interimTranscript = transcript;
}
}
msg.value = "";
msg.value = finalTranscript;
}
mike.addEventListener("click",function(){
recognition.start();
})
// Autocomplete
Autocomplete();
}
else{
Logout();
wait(3000);
console.log("Login Failed")
alert("Login Failed");
}
},
error: function() {
Logout();
wait(3000);
console.log("Login Failed")
alert("Login Failed");
}
}
);
}
function loading(){
document.querySelector(".container_new").remove();
console.log("Removed");
let dd = document.createElement("div");
let dd_atr = document.createAttribute("class");
dd_atr.value = "container_new";
dd.setAttributeNode(dd_atr);
dd.innerHTML = load;
document.body.appendChild(dd);
console.log("Child Added");
// wait(5000);
console.log("Loaded ** * ");
}
// Function for Logging out
function Logout(){
localStorage.clear();
window.location.replace("");
}
// Function for Registration
function Register (name, pass) {
var arr = {'username':name, 'password': pass};
$.ajax(
{
url: "http://" + ip + "/signup",
type: "POST",
data: JSON.stringify(arr),
contentType: 'application/json;charset=UTF-8',
success: function(data) {
console.log(data);
alert("Successful Signup...")
},
error: function() {
alert("Registration Failed");
}
}
);
}
// Function for Chatting initiation
function chat(userid){
let arr = {'user': userid};
$.ajax(
{
url: "http://" + ip + "/chat",
type: "POST",
data: JSON.stringify(arr),
contentType: 'application/json;charset=UTF-8',
beforeSend: function(xhr) {
if (localStorage.token) {
xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.token);
}
},
success: function(res) {
console.log(res);
localStorage.chatid = res.chat_id;
//console.log(localStorage.chatid);
let dom = document.querySelector(".container_new");
dom.remove();
let new_dom = document.createElement("div");
let a_atr = document.createAttribute("class");
a_atr.value = "container";
new_dom.setAttributeNode(a_atr);
new_dom.innerHTML = newDOM;
document.body.appendChild(new_dom);
btn = document.getElementById("rec");
msg = document.getElementById("msg_inp");
exit = document.getElementById("exit");
btn.addEventListener("click", function(){
let text = msg.value;
send(text);
msg.value = "";
});
$('#msg_inp').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
let text = msg.value;
send(text);
msg.value = "";
}
});
exit.addEventListener("click",function(){
Logout();
})
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;
let finalTranscript = '';
let recognition = new window.SpeechRecognition();
recognition.interimResults = true;
recognition.maxAlternatives = 10;
recognition.continuous = false;
recognition.onresult = (event) => {
let interimTranscript = '';
for (let i = event.resultIndex, len = event.results.length; i < len; i++) {
let transcript = event.results[i][0].transcript;
if (event.results[i].isFinal) {
finalTranscript = transcript;
} else {
interimTranscript = transcript;
}
}
msg.value = "";
msg.value = finalTranscript;
}
mike.addEventListener("click",function(){
recognition.start();
})
// Autocomplete
Autocomplete();
},
error: function() {
//alert("Chat instance not created")
}
}
);
}
function print_loading(msg){
let bot_res = document.getElementById("chatArea");
let a = document.createElement("div");
let a_atr = document.createAttribute("class");
a_atr.value = "chat friend";
a.setAttributeNode(a_atr);
let b = document.createElement("div");
let b_atr = document.createAttribute("class");
b_atr.value = "user-photo";
b.setAttributeNode(b_atr);
let img = document.createElement("img");
let i_atr = document.createAttribute("src");
i_atr.value = "Images/face.png";
img.setAttributeNode(i_atr);
b.appendChild(img);
let c = document.createElement("div");
let c_atr = document.createAttribute("class");
c_atr.value = "chat-message";
let im = document.createElement("img");
let im_atr = document.createAttribute("src");
im_atr.value = "Images/loading.gif";
im.setAttributeNode(im_atr);
im.style.cssText = 'border-radius: 20px; margin: 10px';
c.appendChild(im)
a.appendChild(b);
a.appendChild(c);
bot_res.appendChild(a);
}
function print_bot(msg){
for(let i=0; i<(100000); i++){
console.log(10);
}
let bot_res = document.getElementById("chatArea");
let a = document.createElement("div");
let a_atr = document.createAttribute("class");
a_atr.value = "chat friend";
a.setAttributeNode(a_atr);
let b = document.createElement("div");
let b_atr = document.createAttribute("class");
b_atr.value = "user-photo";
b.setAttributeNode(b_atr);
let img = document.createElement("img");
let i_atr = document.createAttribute("src");
i_atr.value = "Images/face.png";
img.setAttributeNode(i_atr);
b.appendChild(img);
let c = document.createElement("p");
let c_atr = document.createAttribute("class");
c_atr.value = "chat-message";
c.setAttributeNode(c_atr);
c.innerHTML = msg;
a.appendChild(b);
a.appendChild(c);
bot_res.lastChild.remove();
bot_res.appendChild(a);
}
function print_self(msg){
let bot_res = document.getElementById("chatArea");
let a = document.createElement("div");
let a_atr = document.createAttribute("class");
a_atr.value = "chat self";
a.setAttributeNode(a_atr);
let c = document.createElement("p");
let c_atr = document.createAttribute("class");
c_atr.value = "chat-message";
c.setAttributeNode(c_atr);
c.innerHTML = msg;
// a.appendChild(b);
a.appendChild(c);
bot_res.appendChild(a);
print_loading("Waiting")
}
// // Function to send message
// function send(msg){
// $.ajax(
// {
// url: "http://" + ip + "/send",
// type: "POST",
// data: JSON.stringify({'message': msg}),
// contentType: 'application/json;charset=UTF-8',
// beforeSend: function(xhr) {
// if (localStorage.token) {
// xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.token);
// }
// },
// success: function(res) {
// print_self(msg);
// let route = "http://" + ip + "/get_message/" + localStorage.chatid;
// $.ajax(
// {
// url: route,
// type: "GET",
// contentType: 'application/json;charset=UTF-8',
// beforeSend: function(xhr) {
// if (localStorage.token) {
// xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.token);
// }
// },
// success: function(res) {
// console.log(res);
// console.log('Hey thisis it');
// console.log(res[0].message);
// let bot_response = res[0].message;
// print_bot(bot_response);
// },
// error: function() {
// alert("Message Not Sent: Failed Attemp");
// }
// }
// )
// },
// error: function() {
// alert("Message cannot be sent due to some error");
// }
// }
// );
// }
function send(msg){
let route = "http://" + ip + "/get_response";
print_self(msg);
(chatArea).scrollTop = (chatArea).scrollHeight
$.ajax(
{
url: route,
type: "POST",
data: JSON.stringify({'message': msg, 'user': localStorage.userid, 'chat': localStorage.chatid}),
contentType: 'application/json;charset=UTF-8',
beforeSend: function(xhr) {
if (localStorage.token) {
xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.token);
}
},
success: function(res) {
console.log(res);
console.log('Hey thisis it');
console.log(res.message);
let bot_response = res.message;
print_bot(bot_response);
},
error: function() {
alert("Message Not Sent: Failed Attemp");
}
}
)
}
$(function () {
let name = document.getElementById("name");
let pass = document.getElementById("pass");
let login = document.getElementById("login");
let signup = document.getElementById("signup");
let btn;
let msg;
signup.addEventListener("click",function(){
let n = name.value;
let p = pass.value;
Register(n,p);
console.log(n + " " + p)
})
login.addEventListener("click",function(){
let n = name.value;
let p = pass.value;
localStorage.clear();
Login(n,p);
console.log(n + " " + p)
})
chat(localStorage.userid)
})
// Function for Logging in
// function Login (name, pass) {
// var arr = {'username':name, 'password': pass};
// $.ajax(
// {
// url: "http://localhost:5000/signin",
// type: "POST",
// data: JSON.stringify(arr),
// contentType: 'application/json;charset=UTF-8',
// success: function(res) {
// console.log(res);
// localStorage.token = res.data.token;
// //console.log('Got a token from the server! Token: ' + localStorage.token);
// localStorage.userid = res.data.id;
// localStorage.name = res.data.username;
// //console.log(localStorage.userid + " " + localStorage.name);
// },
// error: function() {
// alert("Login Failed");
// }
// }
// );
// }