-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.html
354 lines (309 loc) · 9.24 KB
/
index2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zoho InsightX</title>
<style>
/* Global Styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f9f9f9;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
text-align: center;
background-color: #4caf50;
color: white;
padding: 20px 0;
}
main {
margin: 20px;
flex-grow: 1;
}
section {
margin: 20px 0;
}
h2 {
color: #333;
}
#chat-widget {
width: 300px;
height: 400px;
border: 1px solid #ccc;
border-radius: 8px;
position: fixed;
bottom: 70px;
right: 20px;
display: flex;
flex-direction: column;
background-color: #ffffff;
transition: transform 0.3s ease-in-out;
overflow: hidden;
}
#chat-header {
background-color: #4caf50;
color: white;
padding: 10px;
display: flex;
justify-content: space-between;
align-items: center;
}
.header-icons {
display: flex;
gap: 10px;
justify-content: flex-start;
}
.header-icons button {
border: none;
background-color: transparent;
color: white;
font-size: 16px;
cursor: pointer;
}
.header-icons button:hover {
color: #ddd;
}
#chat-messages {
flex: 1;
overflow-y: auto;
padding: 10px;
}
#chat-input {
display: flex;
padding: 10px;
border-top: 1px solid #ccc;
}
#chat-input input {
flex: 1;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
#chat-input button {
margin-left: 10px;
padding: 8px 12px;
border: none;
background-color: #4caf50;
color: white;
border-radius: 4px;
cursor: pointer;
}
#chat-input button:hover {
background-color: #45a049;
}
/* Chat launcher icon */
#chat-launcher {
position: fixed;
bottom: 80px;
right: 20px;
width: 60px;
height: 60px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 50%;
font-size: 24px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
cursor: pointer;
}
#chat-launcher.hidden {
display: none;
}
#chat-launcher:hover {
background-color: #45a049;
}
/* Mic Icon for Voice Functionality */
#voice-btn {
background-color: transparent;
color: #4caf50;
font-size: 24px;
border: none;
cursor: pointer;
position: absolute;
right: 10px;
bottom: 60px;
}
/* Mic Popup */
#mic-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: none;
justify-content: center;
align-items: center;
}
#mic-popup .popup-content {
background-color: white;
padding: 20px;
border-radius: 10px;
text-align: center;
}
#mic-popup button {
background-color: #4caf50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
/* Footer adjustment */
footer {
height: 25px;
width: 100%;
background-color: #4caf50;
color: white;
text-align: center;
padding: 20px 0;
margin-top: 0px;
position: relative;
}
</style>
</head>
<body>
<header>
<h1>Zoho InsightX</h1>
<p>Proactive Sentiment Analysis and Productivity Integration</p>
</header>
<main>
<section id="chat-widget-container">
<div id="chat-widget">
<div id="chat-header">
<span>InsightX Bot</span>
<div class="header-icons">
<button id="minimize-btn">--</button>
<button id="maximize-btn">◻</button>
<button id="close-btn">✖</button>
</div>
</div>
<div id="chat-messages"></div>
<div id="chat-input">
<input type="text" id="user-input" placeholder="Ask me anything...">
<button id="send-btn">Send</button>
</div>
<!-- Mic Button for Voice-to-Text -->
<button id="voice-btn">🎤</button>
</div>
<!-- Chat Launcher Icon -->
<button id="chat-launcher" class="hidden">💬</button>
</section>
</main>
<footer>
<p>Zoho InsightX - Empowering Sentiment-Driven Productivity</p>
</footer>
<!-- Mic Popup for Voice Input -->
<div id="mic-popup">
<div class="popup-content">
<h3>Speak Now...</h3>
<p id="mic-status">Listening...</p>
<button id="mic-close-btn">Close</button>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const sendBtn = document.getElementById("send-btn");
const userInput = document.getElementById("user-input");
const chatMessages = document.getElementById("chat-messages");
const voiceBtn = document.getElementById("voice-btn");
const micPopup = document.getElementById("mic-popup");
const micStatus = document.getElementById("mic-status");
const micCloseBtn = document.getElementById("mic-close-btn");
// Mic popup for voice functionality
voiceBtn.addEventListener("click", () => {
micPopup.style.display = "flex";
micStatus.textContent = "Listening...";
startVoiceRecognition(); // Start voice recognition when mic is clicked
});
// Close Mic Popup when user clicks close button
micCloseBtn.addEventListener("click", () => {
micPopup.style.display = "none";
recognition.stop(); // Stop the recognition if user decides to close
});
// Start Voice Recognition
let recognition;
function startVoiceRecognition() {
if (!('webkitSpeechRecognition' in window)) {
alert("Your browser does not support Speech Recognition.");
return;
}
recognition = new webkitSpeechRecognition();
recognition.continuous = true; // Keep listening until stopped
recognition.interimResults = true; // Show partial results as well
recognition.lang = 'en-US'; // Set language to English (can be changed as needed)
recognition.onstart = () => {
micStatus.textContent = "Listening...";
};
recognition.onerror = (event) => {
micStatus.textContent = "Error occurred. Try again.";
};
recognition.onresult = (event) => {
let transcript = '';
for (let i = event.resultIndex; i < event.results.length; i++) {
transcript += event.results[i][0].transcript;
}
userInput.value = transcript; // Show recognized text in input field
micStatus.textContent = "Speech recognized: " + transcript;
// Optionally, send to chatbot after recognition is complete
if (event.results[event.results.length - 1].isFinal) {
sendChatInput(transcript); // Send text to chatbot when final results are available
}
};
recognition.onend = () => {
if (micPopup.style.display === "flex") {
micStatus.textContent = "Listening...";
recognition.start(); // Restart recognition if it ends unexpectedly
}
};
recognition.start();
}
// Handle Send button click
sendBtn.addEventListener("click", () => {
const message = userInput.value;
if (message.trim() !== "") {
const messageElement = document.createElement("div");
messageElement.textContent = message;
chatMessages.appendChild(messageElement);
userInput.value = "";
sendChatInput(message); // Send typed message to chatbot
}
});
// Send the user input to chatbot
function sendChatInput(input) {
// Display user message in chat
chatMessages.innerHTML += `<div>User: ${input}</div>`;
// Call API to get chatbot response
getChatbotResponse(input);
}
// API Call to Zoho or other chatbot API
async function fetchChatData() {
try {
const apiUrl = "https://cliq.zoho.com/api/v2/chats";
const accessToken = "3e7b31c4bda927a3498ca1b13d9b9b7ba8bb5b243c"; // Replace with dynamically fetched token
const response = await fetch(apiUrl, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
});
if (response.ok) {
const data = await response.json();
displayChatData(data.chats);
} else {
throw new Error(`Error ${response.status}: Unable to fetch data`);
}
} catch (error) {
console.error("Error fetching chat data:", error);
}
}
});
</script>
</body>
</html>