-
Notifications
You must be signed in to change notification settings - Fork 693
/
script.js
52 lines (40 loc) · 1.75 KB
/
script.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
// script.js
const inputField = document.getElementById('chat-input');
const chatBox = document.getElementById('chat-box');
inputField.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
const userMessage = inputField.value;
inputField.value = '';
// Display user message
const userMessageDiv = document.createElement('div');
userMessageDiv.classList.add('user-message');
userMessageDiv.textContent = userMessage;
chatBox.appendChild(userMessageDiv);
// Check if user has accepted the license
if (!localStorage.getItem('licenseAccepted')) {
const licenseMessage = document.createElement('div');
licenseMessage.classList.add('bot-message');
licenseMessage.textContent = "Please agree to our terms of service and privacy policy before using the chatbot.";
chatBox.appendChild(licenseMessage);
const acceptButton = document.createElement('button');
acceptButton.textContent = "Accept";
acceptButton.addEventListener('click', () => {
localStorage.setItem('licenseAccepted', 'true');
chatBox.removeChild(licenseMessage);
chatBox.removeChild(acceptButton);
// Bot's response
const botMessage = document.createElement('div');
botMessage.classList.add('bot-message');
botMessage.textContent = "How can I help you today?";
chatBox.appendChild(botMessage);
});
chatBox.appendChild(acceptButton);
return;
}
// Bot's response (replace with actual AI logic)
const botMessage = document.createElement('div');
botMessage.classList.add('bot-message');
botMessage.textContent = "You said: " + userMessage; // Replace with a more sophisticated response
chatBox.appendChild(botMessage);
}
});