ok
This commit is contained in:
@@ -5,12 +5,12 @@
|
|||||||
const [messages, setMessages] = useState([
|
const [messages, setMessages] = useState([
|
||||||
{
|
{
|
||||||
sender: 'bot',
|
sender: 'bot',
|
||||||
text: 'Halo 👋 Saya Klinik AI! Ada yang bisa saya bantu?',
|
text: 'Hai Dermalovers! 👋 Saya siap membantu anda tampil lebih percaya diri. Ada pertanyaan seputar perawatan kulit atau kecantikan hari ini?',
|
||||||
time: getTime(),
|
time: getTime(),
|
||||||
quickReplies: [
|
quickReplies: [
|
||||||
'Bagaimana menghilangkan komedo',
|
'List harga layanan Dermalounge',
|
||||||
'Apakah bisa menghilangkan bopeng?',
|
'Beri saya info jadwal dokter',
|
||||||
'Perutku mual dan kembung',
|
'Apa saja layanan disini',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@@ -53,9 +53,10 @@
|
|||||||
setMessages(newMessages);
|
setMessages(newMessages);
|
||||||
setInput('');
|
setInput('');
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
// Send to backend
|
// Send to backend
|
||||||
const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/ask/dev', {
|
const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/ask', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ pertanyaan: message, sessionId: JSON.parse(localStorage.getItem('session')).sessionId, lastSeen: new Date().toISOString() }),
|
body: JSON.stringify({ pertanyaan: message, sessionId: JSON.parse(localStorage.getItem('session')).sessionId, lastSeen: new Date().toISOString() }),
|
||||||
@@ -75,19 +76,11 @@
|
|||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setMessages(prev => [
|
sendMessage('gimana')
|
||||||
...prev,
|
|
||||||
{
|
|
||||||
sender: 'bot',
|
|
||||||
text: 'Maaf, terjadi kesalahan pada server. Silakan coba lagi nanti.',
|
|
||||||
time: getTime(),
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
console.error('Fetch error:', error);
|
console.error('Fetch error:', error);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
setIsLoading(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -112,7 +105,20 @@
|
|||||||
className={`${styles.messageRow} ${styles[msg.sender]}`}
|
className={`${styles.messageRow} ${styles[msg.sender]}`}
|
||||||
>
|
>
|
||||||
<div className={`${styles.message} ${styles[msg.sender]}`}>
|
<div className={`${styles.message} ${styles[msg.sender]}`}>
|
||||||
{msg.text}
|
{msg.sender !== 'bot'
|
||||||
|
? msg.text
|
||||||
|
: (() => {
|
||||||
|
try {let cleanText = msg.text.replace(/`/g, ''); // Remove backticks
|
||||||
|
cleanText = cleanText.substring(4); // Remove first 4 characters
|
||||||
|
let parsedObj = JSON.parse(cleanText);
|
||||||
|
|
||||||
|
return parsedObj.jawaban;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("JSON parsing error:", e); // Log error parsing if it occurs
|
||||||
|
return msg.text; // Return an empty string if there is an error
|
||||||
|
}
|
||||||
|
|
||||||
|
})()}
|
||||||
{msg.quickReplies && (
|
{msg.quickReplies && (
|
||||||
<div className={styles.quickReplies}>
|
<div className={styles.quickReplies}>
|
||||||
{msg.quickReplies.map((reply, i) => (
|
{msg.quickReplies.map((reply, i) => (
|
||||||
@@ -145,6 +151,64 @@
|
|||||||
Kirim
|
Kirim
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div style={{width: '96.6%'}}>
|
||||||
|
<div style={{
|
||||||
|
backgroundColor: '#f0f0f0',
|
||||||
|
width: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
overflowX: 'auto',
|
||||||
|
padding: '8px',
|
||||||
|
scrollbarWidth: 'none'
|
||||||
|
}}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flexShrink: 0,
|
||||||
|
background: '#fff',
|
||||||
|
border: '1px solid #ccc',
|
||||||
|
padding: '8px 12px',
|
||||||
|
borderRadius: '20px',
|
||||||
|
fontSize: '13px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
margin: '3px'
|
||||||
|
}}
|
||||||
|
onClick={() => sendMessage('Dapatkah bopeng dihilangkan?')}
|
||||||
|
>
|
||||||
|
Dapatkah bopeng dihilangkan?
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flexShrink: 0,
|
||||||
|
background: '#fff',
|
||||||
|
border: '1px solid #ccc',
|
||||||
|
padding: '8px 12px',
|
||||||
|
borderRadius: '20px',
|
||||||
|
fontSize: '13px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
margin: '3px'
|
||||||
|
}}
|
||||||
|
onClick={() => sendMessage('Bisa booking treatment untuk besok?')}
|
||||||
|
>
|
||||||
|
Bisa booking treatment untuk besok?
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flexShrink: 0,
|
||||||
|
background: '#fff',
|
||||||
|
border: '1px solid #ccc',
|
||||||
|
padding: '8px 12px',
|
||||||
|
borderRadius: '20px',
|
||||||
|
fontSize: '13px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
margin: '3px'
|
||||||
|
}}
|
||||||
|
onClick={() => sendMessage('Bisa booking treatment untuk besok?')}
|
||||||
|
>
|
||||||
|
Ada treatment untuk jerawat?
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const Dashboard = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchStats() {
|
async function fetchStats() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/dashboard/dev');
|
const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/dashboard');
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setDiscussedTopics(data[0]?.result?.topics)
|
setDiscussedTopics(data[0]?.result?.topics)
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ const navigate = useNavigate();
|
|||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('https://bot.kediritechnopark.com/webhook/profile/dev', {
|
const response = await fetch('https://bot.kediritechnopark.com/webhook/profile', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
Reference in New Issue
Block a user