-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.html
More file actions
123 lines (110 loc) · 2.78 KB
/
Bot.html
File metadata and controls
123 lines (110 loc) · 2.78 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Learning Bot</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background: #f5f5f5;
display: flex;
flex-direction: column;
height: 100vh;
}
h1 {
text-align: center;
padding: 1em;
background-color: #fff;
border-bottom: 1px solid #ddd;
margin: 0;
}
#chat {
flex: 1;
padding: 1em;
overflow-y: auto;
display: flex;
flex-direction: column;
}
.message {
margin-bottom: 0.8em;
max-width: 70%;
padding: 0.7em 1em;
border-radius: 20px;
line-height: 1.4;
word-wrap: break-word;
}
.user {
align-self: flex-end;
background-color: #d1f0ff;
}
.bot {
align-self: flex-start;
background-color: #ffe3b3;
}
.input-area {
display: flex;
padding: 1em;
background: #fff;
border-top: 1px solid #ddd;
}
input[type="text"] {
flex: 1;
padding: 0.7em;
border-radius: 20px;
border: 1px solid #ccc;
font-size: 1em;
outline: none;
}
button {
margin-left: 0.5em;
padding: 0.7em 1.2em;
border-radius: 20px;
border: 1px solid #000000b8;
background-color: #fff;
cursor: pointer;
font-size: 1em;
}
</style>
</head>
<body>
<h1>🧠 Learning Bot</h1>
<div id="chat"></div>
<div class="input-area">
<input type="text" id="userInput" placeholder="Type a message..." />
<button onclick="handleUserInput()">Send</button>
</div>
<script>
const chatBox = document.getElementById('chat');
const memory = JSON.parse(localStorage.getItem('botMemory')) || {};
function addMessage(sender, text) {
const msg = document.createElement('div');
msg.className = `message ${sender}`;
msg.textContent = text;
chatBox.appendChild(msg);
chatBox.scrollTop = chatBox.scrollHeight;
}
function handleUserInput() {
const inputField = document.getElementById('userInput');
const userText = inputField.value.trim();
if (!userText) return;
addMessage('user', userText);
if (memory[userText]) {
addMessage('bot', memory[userText]);
} else {
const reply = prompt(`Teach me! What should I reply when someone says: "${userText}"?`);
if (reply) {
memory[userText] = reply;
localStorage.setItem('botMemory', JSON.stringify(memory));
addMessage('bot', reply);
} else {
addMessage('bot', "I don't know that yet. Maybe teach me?");
}
}
inputField.value = '';
}
</script>
</body>
</html>