-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAichathelp.html
More file actions
184 lines (173 loc) · 5.2 KB
/
Aichathelp.html
File metadata and controls
184 lines (173 loc) · 5.2 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Public API Chat Widget</title>
<style>
/* Basic reset and body style */
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
flex-direction: column;
}
/* DALL·E generated image header */
.header-image {
width: 400px;
max-width: 90%;
margin-bottom: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
/* Chat widget container */
.chat-container {
width: 400px;
max-width: 90%;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
height: 500px;
overflow: hidden;
}
/* Chat header styling */
.chat-header {
background-color: #4CAF50;
color: #fff;
padding: 15px;
font-size: 18px;
text-align: center;
}
/* Chat messages area */
.chat-messages {
flex: 1;
padding: 15px;
overflow-y: auto;
background-color: #e5ddd5;
}
/* Message bubbles */
.message {
margin-bottom: 10px;
padding: 8px 12px;
border-radius: 5px;
max-width: 80%;
clear: both;
word-wrap: break-word;
}
.message.user {
background-color: #dcf8c6;
float: right;
}
.message.bot {
background-color: #fff;
float: left;
}
/* Chat input area */
.chat-input {
display: flex;
border-top: 1px solid #ddd;
}
.chat-input input {
flex: 1;
border: none;
padding: 10px;
font-size: 16px;
outline: none;
}
.chat-input button {
border: none;
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.chat-input button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<!-- DALL·E generated image (simulated with a public placeholder image) -->
<img class="header-image" src="https://via.placeholder.com/400x200.png?text=DALL%E2%80%A2E+Generated+Image" alt="DALL·E generated chat header image" />
<!-- Chat widget container -->
<div class="chat-container">
<div class="chat-header">Chat Widget</div>
<div class="chat-messages" id="chat-messages">
<!-- Chat messages will appear here -->
</div>
<div class="chat-input">
<input type="text" id="chat-input" placeholder="Type a message..." />
<button id="send-button">Send</button>
</div>
</div>
<script>
// Immediately Invoked Function Expression (IIFE) to encapsulate the chat widget logic
(function(){
const chatMessages = document.getElementById('chat-messages');
const chatInput = document.getElementById('chat-input');
const sendButton = document.getElementById('send-button');
// Connect to a public WebSocket echo server that sends back any message received.
const ws = new WebSocket('wss://echo.websocket.events');
ws.onopen = function() {
console.log('Connected to WebSocket server');
addBotMessage('Hello! You are connected to the chat. Type your message below.');
};
ws.onmessage = function(event) {
console.log('Received:', event.data);
// Only add bot message if the message is not the service notice
if(event.data !== "echo.websocket.events sponsored message") {
addBotMessage(event.data);
}
};
ws.onerror = function(error) {
console.error('WebSocket error:', error);
addBotMessage('Error connecting to chat server.');
};
ws.onclose = function() {
console.log('WebSocket connection closed');
addBotMessage('Disconnected from chat server.');
};
// Helper function to add user messages to the chat window
function addUserMessage(message) {
const messageElem = document.createElement('div');
messageElem.className = 'message user';
messageElem.textContent = message;
chatMessages.appendChild(messageElem);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// Helper function to add bot messages to the chat window
function addBotMessage(message) {
const messageElem = document.createElement('div');
messageElem.className = 'message bot';
messageElem.textContent = message;
chatMessages.appendChild(messageElem);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// Event listener for the Send button
sendButton.addEventListener('click', function(){
const message = chatInput.value.trim();
if (message) {
addUserMessage(message);
// Send the message via the WebSocket connection
ws.send(message);
chatInput.value = '';
chatInput.focus();
}
});
// Allow sending message with the Enter key
chatInput.addEventListener('keyup', function(event){
if (event.key === 'Enter') {
sendButton.click();
}
});
})();
</script>
</body>
</html>