diff --git a/public/dermalounge.jpg b/public/dermalounge.jpg new file mode 100644 index 0000000..c04e45e Binary files /dev/null and b/public/dermalounge.jpg differ diff --git a/src/ChatBot.js b/src/ChatBot.js index 8b14d0a..35b7322 100644 --- a/src/ChatBot.js +++ b/src/ChatBot.js @@ -1,177 +1,157 @@ -import React, { useState, useEffect } from 'react'; -import styles from './ChatBot.module.css'; + import React, { useState, useEffect } from 'react'; + import styles from './ChatBot.module.css'; -const ChatBot = ({ existingConversation, readOnly, hh }) => { - const [messages, setMessages] = useState([ - { - sender: 'bot', - text: 'Halo 👋 Saya Klinik AI! Ada yang bisa saya bantu?', - time: getTime(), - quickReplies: [ - 'Bagaimana menghilangkan komedo', - 'Apakah bisa menghilangkan bopeng?', - 'Perutku mual dan kembung', - ], - }, - ]); + const ChatBot = ({ existingConversation, readOnly, hh }) => { + const [messages, setMessages] = useState([ + { + sender: 'bot', + text: 'Halo 👋 Saya Klinik AI! Ada yang bisa saya bantu?', + time: getTime(), + quickReplies: [ + 'Bagaimana menghilangkan komedo', + 'Apakah bisa menghilangkan bopeng?', + 'Perutku mual dan kembung', + ], + }, + ]); - const [input, setInput] = useState(''); - const [isLoading, setIsLoading] = useState(false); - useEffect(() => { + const [input, setInput] = useState(''); + const [isLoading, setIsLoading] = useState(false); + useEffect(() => { - if (existingConversation && existingConversation.length > 0) { - setMessages(existingConversation); - } - }, [existingConversation]) - useEffect(() => { - if (!localStorage.getItem('session')) { - function generateUUID() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - const r = Math.random() * 16 | 0; - const v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); + if (existingConversation && existingConversation.length > 0) { + setMessages(existingConversation); } + }, [existingConversation]) + useEffect(() => { + if (!localStorage.getItem('session')) { + function generateUUID() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + const r = Math.random() * 16 | 0; + const v = c === 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); + } - const sessionId = generateUUID(); - const dateNow = new Date().toISOString(); + const sessionId = generateUUID(); + const dateNow = new Date().toISOString(); - localStorage.setItem('session', JSON.stringify({ sessionId: sessionId, lastSeen: dateNow })) - } - }, []); + localStorage.setItem('session', JSON.stringify({ sessionId: sessionId, lastSeen: dateNow })) + } + }, []); - const sendMessage = async (textOverride = null) => { - const message = textOverride || input.trim(); - if (message === '') return; + const sendMessage = async (textOverride = null) => { + const message = textOverride || input.trim(); + if (message === '') return; - // Show user's message immediately - const newMessages = [ - ...messages, - { sender: 'user', text: message, time: getTime() }, - ]; + // Show user's message immediately + const newMessages = [ + ...messages, + { sender: 'user', text: message, time: getTime() }, + ]; - setMessages(newMessages); - setInput(''); - setTimeout(() => setIsLoading(true), 1000); + setMessages(newMessages); + setInput(''); - try { - // Send to backend - const response = await fetch('https://botdev.kediritechnopark.com/webhook/master-agent/ask', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ pertanyaan: message, sessionId: JSON.parse(localStorage.getItem('session')).sessionId, lastSeen: new Date().toISOString() }), - }); + try { + // Send to backend + const response = await fetch('https://botdev.kediritechnopark.com/webhook/master-agent/ask', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ pertanyaan: message, sessionId: JSON.parse(localStorage.getItem('session')).sessionId, lastSeen: new Date().toISOString() }), + }); - const data = await response.json(); - console.log(data) - // Assuming your backend sends back something like: { answer: "text" } - // Adjust this according to your actual response shape - const botAnswer = data[0].output || data[0].output[0].text || 'Maaf, saya tidak mengerti.'; + const data = await response.json(); + console.log(data) + // Assuming your backend sends back something like: { answer: "text" } + // Adjust this according to your actual response shape + const botAnswer = data[0].output[0].text || data[0].output || 'Maaf, saya tidak mengerti.'; - // Add bot's reply - setMessages(prev => [ - ...prev, - { sender: 'bot', text: botAnswer, time: getTime() }, - ]); + // Add bot's reply + setMessages(prev => [ + ...prev, + { sender: 'bot', text: botAnswer, time: getTime() }, + ]); - setIsLoading(false); - } catch (error) { - setMessages(prev => [ - ...prev, - { - sender: 'bot', - text: 'Maaf, terjadi kesalahan pada server. Silakan coba lagi nanti.', - time: getTime(), - }, - ]); - console.error('Fetch error:', error); - } finally { - setIsLoading(false); - } - setIsLoading(false); + setIsLoading(false); + } catch (error) { + setMessages(prev => [ + ...prev, + { + sender: 'bot', + text: 'Maaf, terjadi kesalahan pada server. Silakan coba lagi nanti.', + time: getTime(), + }, + ]); + console.error('Fetch error:', error); + } finally { + setIsLoading(false); + } + setIsLoading(false); + }; + + return ( +
+
+ Bot Avatar + DERMALOUNGE +
+ +
+ + {isLoading && ( +
+
+ Mengetik... +
+
+ )} + {messages.slice().reverse().map((msg, index) => ( +
+
+ {msg.text} + {msg.quickReplies && ( +
+ {msg.quickReplies.map((reply, i) => ( +
sendMessage(reply)} + > + {reply} +
+ ))} +
+ )} +
{msg.time}
+
+
+ ))} +
+ +
+ setInput(e.target.value)} + onKeyDown={(e) => e.key === 'Enter' && sendMessage()} + disabled={isLoading} + /> + +
+
+ ); }; - return ( -
-
- Bot Avatar - Kloowear AI Assistant -
+ function getTime() { + const now = new Date(); + return now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); + } -
- - {isLoading && ( -
- Bot -
- Mengetik... -
-
- )} - {messages.slice().reverse().map((msg, index) => ( -
- {msg.sender === 'bot' && ( - Bot - )} -
- {msg.text} - {msg.quickReplies && ( -
- {msg.quickReplies.map((reply, i) => ( -
sendMessage(reply)} - > - {reply} -
- ))} -
- )} -
{msg.time}
-
- {msg.sender === 'user' && ( - User - )} -
- ))} -
- -
- setInput(e.target.value)} - onKeyDown={(e) => e.key === 'Enter' && sendMessage()} - disabled={isLoading} - /> - -
-
- ); -}; - -function getTime() { - const now = new Date(); - return now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); -} - -export default ChatBot; + export default ChatBot; diff --git a/src/Dashboard.js b/src/Dashboard.js index 3b46a34..2173920 100644 --- a/src/Dashboard.js +++ b/src/Dashboard.js @@ -128,9 +128,9 @@ const Dashboard = () => { return (
- Bot Avatar + Bot Avatar
-

Kloowear AI Admin Dashboard

+

Dermalounge AI Admin Dashboard

Statistik penggunaan chatbot secara real-time

@@ -159,6 +159,10 @@ const Dashboard = () => {
+
+ UNTUK MENAMBAHKAN LAYANAN, KUNJUNGI LINK INI + dengan username: dermalounge, password: 1234 +
© 2025 Kloowear AI - Admin Panel