Skip to content
fetch(WEBHOOK_URL, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ message: text })
})
.then(function(res) { return res.text(); })
.then(function(rawText) {
hideTyping();
var answer = '';
var source = 'groq';
try {
var data = JSON.parse(rawText);
if (data.answer) {
answer = data.answer;
source = data.source || 'groq';
} else if (data[0] && data[0].answer) {
answer = data[0].answer;
source = data[0].source || 'groq';
} else {
answer = rawText;
}
} catch(e) {
answer = rawText;
}
addMessage('bot', answer, source);
})
.catch(function(err) {
hideTyping();
addMessage('bot', 'Something went wrong. Please visit https://cwdezigns.com or try again.', 'fallback');
})
.finally(function() {
sendBtn.disabled = false;
isWaiting = false;
});