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<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
| 6 |
+
<title>AI Chatbot</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
body {
|
| 15 |
+
font-family: 'Arial', sans-serif;
|
| 16 |
+
background-color: #f0f0f0;
|
| 17 |
+
height: 100vh;
|
| 18 |
+
display: flex;
|
| 19 |
+
flex-direction: column;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
#chat-container {
|
| 23 |
+
flex-grow: 1;
|
| 24 |
+
display: flex;
|
| 25 |
+
flex-direction: column;
|
| 26 |
+
max-width: 600px;
|
| 27 |
+
width: 100%;
|
| 28 |
+
margin: 0 auto;
|
| 29 |
+
background-color: white;
|
| 30 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
#chat-messages {
|
| 34 |
+
flex-grow: 1;
|
| 35 |
+
overflow-y: auto;
|
| 36 |
+
padding: 15px;
|
| 37 |
+
display: flex;
|
| 38 |
+
flex-direction: column;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.message {
|
| 42 |
+
max-width: 80%;
|
| 43 |
+
margin: 5px 0;
|
| 44 |
+
padding: 10px;
|
| 45 |
+
border-radius: 10px;
|
| 46 |
+
clear: both;
|
| 47 |
+
word-wrap: break-word;
|
| 48 |
+
line-height: 1.4;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.user-message {
|
| 52 |
+
background-color: #007bff;
|
| 53 |
+
color: white;
|
| 54 |
+
align-self: flex-end;
|
| 55 |
+
margin-left: auto;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.bot-message {
|
| 59 |
+
background-color: #e9ecef;
|
| 60 |
+
color: black;
|
| 61 |
+
align-self: flex-start;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.bot-message strong {
|
| 65 |
+
color: #007bff;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
#input-container {
|
| 69 |
+
display: flex;
|
| 70 |
+
padding: 10px;
|
| 71 |
+
background-color: white;
|
| 72 |
+
border-top: 1px solid #e0e0e0;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
#user-input {
|
| 76 |
+
flex-grow: 1;
|
| 77 |
+
padding: 10px;
|
| 78 |
+
border: 1px solid #ddd;
|
| 79 |
+
border-radius: 20px;
|
| 80 |
+
margin-right: 10px;
|
| 81 |
+
outline: none;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
#send-btn {
|
| 85 |
+
background-color: #007bff;
|
| 86 |
+
color: white;
|
| 87 |
+
border: none;
|
| 88 |
+
border-radius: 50%;
|
| 89 |
+
width: 40px;
|
| 90 |
+
height: 40px;
|
| 91 |
+
display: flex;
|
| 92 |
+
align-items: center;
|
| 93 |
+
justify-content: center;
|
| 94 |
+
cursor: pointer;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/* Typing Indicator */
|
| 98 |
+
.typing-indicator {
|
| 99 |
+
display: flex;
|
| 100 |
+
align-items: center;
|
| 101 |
+
background-color: #e9ecef;
|
| 102 |
+
padding: 10px;
|
| 103 |
+
border-radius: 10px;
|
| 104 |
+
align-self: flex-start;
|
| 105 |
+
margin-bottom: 10px;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.typing-indicator span {
|
| 109 |
+
height: 8px;
|
| 110 |
+
width: 8px;
|
| 111 |
+
background-color: #888;
|
| 112 |
+
border-radius: 50%;
|
| 113 |
+
margin: 0 3px;
|
| 114 |
+
animation: typing 1.4s infinite;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.typing-indicator span:nth-child(2) {
|
| 118 |
+
animation-delay: 0.2s;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.typing-indicator span:nth-child(3) {
|
| 122 |
+
animation-delay: 0.4s;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
@keyframes typing {
|
| 126 |
+
0%, 100% { opacity: 0.4; }
|
| 127 |
+
50% { opacity: 1; }
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.suggested-questions {
|
| 131 |
+
margin-top: 10px;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.suggested-question-btn {
|
| 135 |
+
display: block;
|
| 136 |
+
margin: 5px 0;
|
| 137 |
+
padding: 5px 10px;
|
| 138 |
+
background-color: #f0f0f0;
|
| 139 |
+
border: none;
|
| 140 |
+
border-radius: 5px;
|
| 141 |
+
cursor: pointer;
|
| 142 |
+
transition: background-color 0.3s ease;
|
| 143 |
+
text-align: left;
|
| 144 |
+
width: 100%;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.suggested-question-btn:hover {
|
| 148 |
+
background-color: #e0e0e0;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
@media (max-width: 600px) {
|
| 152 |
+
body {
|
| 153 |
+
margin: 0;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
#chat-container {
|
| 157 |
+
width: 100%;
|
| 158 |
+
height: 100vh;
|
| 159 |
+
max-width: none;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
#input-container {
|
| 163 |
+
padding: 10px;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
</style>
|
| 167 |
+
</head>
|
| 168 |
+
<body>
|
| 169 |
+
<div id="chat-container">
|
| 170 |
+
<div id="chat-messages"></div>
|
| 171 |
+
<div id="input-container">
|
| 172 |
+
<input type="text" id="user-input" placeholder="Ketik pesan...">
|
| 173 |
+
<button id="send-btn">➤</button>
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
<script>
|
| 178 |
+
const chatMessages = document.getElementById('chat-messages');
|
| 179 |
+
const userInput = document.getElementById('user-input');
|
| 180 |
+
const sendBtn = document.getElementById('send-btn');
|
| 181 |
+
|
| 182 |
+
// Fungsi untuk menambahkan pesan ke chat
|
| 183 |
+
function addMessage(message, type, isHTML = false) {
|
| 184 |
+
// Hapus indikator typing jika ada
|
| 185 |
+
removeTypingIndicator();
|
| 186 |
+
|
| 187 |
+
const messageElement = document.createElement('div');
|
| 188 |
+
messageElement.classList.add('message', type);
|
| 189 |
+
|
| 190 |
+
if (isHTML) {
|
| 191 |
+
messageElement.innerHTML = message;
|
| 192 |
+
} else {
|
| 193 |
+
messageElement.textContent = message;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
chatMessages.appendChild(messageElement);
|
| 197 |
+
scrollToBottom();
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
// Fungsi untuk menambahkan indikator typing
|
| 201 |
+
function addTypingIndicator() {
|
| 202 |
+
// Hapus indikator typing sebelumnya jika ada
|
| 203 |
+
removeTypingIndicator();
|
| 204 |
+
|
| 205 |
+
const typingIndicator = document.createElement('div');
|
| 206 |
+
typingIndicator.classList.add('typing-indicator');
|
| 207 |
+
typingIndicator.innerHTML = `
|
| 208 |
+
<span></span>
|
| 209 |
+
<span></span>
|
| 210 |
+
<span></span>
|
| 211 |
+
`;
|
| 212 |
+
chatMessages.appendChild(typingIndicator);
|
| 213 |
+
scrollToBottom();
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
// Fungsi untuk menghapus indikator typing
|
| 217 |
+
function removeTypingIndicator() {
|
| 218 |
+
const existingIndicator = document.querySelector('.typing-indicator');
|
| 219 |
+
if (existingIndicator) {
|
| 220 |
+
existingIndicator.remove();
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
// Fungsi untuk scroll ke bawah
|
| 225 |
+
function scrollToBottom() {
|
| 226 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
// Fungsi untuk memformat jawaban
|
| 230 |
+
function formatAnswer(answer) {
|
| 231 |
+
// Mengganti markdown bold dengan teks tebal
|
| 232 |
+
return answer.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
// Fungsi untuk menambahkan pertanyaan tambahan
|
| 236 |
+
function addSuggestedQuestions(questions) {
|
| 237 |
+
const suggestedQuestionsContainer = document.createElement('div');
|
| 238 |
+
suggestedQuestionsContainer.classList.add('suggested-questions');
|
| 239 |
+
|
| 240 |
+
const title = document.createElement('div');
|
| 241 |
+
title.textContent = 'Pertanyaan yang mungkin Anda minati:';
|
| 242 |
+
title.style.fontWeight = 'bold';
|
| 243 |
+
title.style.marginTop = '10px';
|
| 244 |
+
suggestedQuestionsContainer.appendChild(title);
|
| 245 |
+
|
| 246 |
+
questions.forEach(q => {
|
| 247 |
+
const questionButton = document.createElement('button');
|
| 248 |
+
questionButton.textContent = q.question;
|
| 249 |
+
questionButton.classList.add('suggested-question-btn');
|
| 250 |
+
|
| 251 |
+
questionButton.addEventListener('click', () => {
|
| 252 |
+
userInput.value = q.question;
|
| 253 |
+
sendMessage();
|
| 254 |
+
});
|
| 255 |
+
|
| 256 |
+
suggestedQuestionsContainer.appendChild(questionButton);
|
| 257 |
+
});
|
| 258 |
+
|
| 259 |
+
chatMessages.appendChild(suggestedQuestionsContainer);
|
| 260 |
+
scrollToBottom();
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// Fungsi untuk mengirim pesan
|
| 264 |
+
async function sendMessage() {
|
| 265 |
+
const message = userInput.value.trim();
|
| 266 |
+
if (message === '') return;
|
| 267 |
+
|
| 268 |
+
// Tambahkan pesan pengguna
|
| 269 |
+
addMessage(message, 'user-message');
|
| 270 |
+
userInput.value = '';
|
| 271 |
+
|
| 272 |
+
// Tampilkan indikator typing
|
| 273 |
+
addTypingIndicator();
|
| 274 |
+
|
| 275 |
+
try {
|
| 276 |
+
// Panggil API
|
| 277 |
+
const response = await fetch(`https://api.yanzbotz.live/api/ai/ai-search?query=${encodeURIComponent(message)}&apiKey=yanzdev`);
|
| 278 |
+
const data = await response.json();
|
| 279 |
+
|
| 280 |
+
// Cek apakah respons valid
|
| 281 |
+
if (data.result && data.result.answer) {
|
| 282 |
+
// Tambahkan respons bot dengan format yang lebih baik
|
| 283 |
+
const formattedAnswer = formatAnswer(data.result.answer);
|
| 284 |
+
addMessage(formattedAnswer, 'bot-message', true);
|
| 285 |
+
|
| 286 |
+
// Tambahan fitur: menampilkan pertanyaan tambahan
|
| 287 |
+
if (data.result.questions && data.result.questions.length > 0) {
|
| 288 |
+
addSuggestedQuestions(data.result.questions);
|
| 289 |
+
}
|
| 290 |
+
} else {
|
| 291 |
+
addMessage('Maaf, saya tidak dapat memproses permintaan Anda.', 'bot-message');
|
| 292 |
+
}
|
| 293 |
+
} catch (error) {
|
| 294 |
+
console.error('Error:', error);
|
| 295 |
+
addMessage('Terjadi kesalahan saat mengambil respons.', 'bot-message');
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
// Event listener untuk tombol kirim
|
| 300 |
+
sendBtn.addEventListener('click', sendMessage);
|
| 301 |
+
|
| 302 |
+
// Event listener untuk enter key
|
| 303 |
+
userInput.addEventListener('keypress', (event) => {
|
| 304 |
+
if (event.key === 'Enter') {
|
| 305 |
+
sendMessage();
|
| 306 |
+
}
|
| 307 |
+
});
|
| 308 |
+
</script>
|
| 309 |
+
</body>
|
| 310 |
+
</html>
|