.clear-button {
position: fixed;
bottom: 20px;
right: 20px;
}
</style>
sendButton.addEventListener("click", function () {
const message = inputField.value;
sendMessage(message);
inputField.value = "";
});
clearButton.addEventListener("click", function () {
chatlog.innerHTML = '<p class="text-center">Welcome to our AI Chatbot. How can I assist you today?</p>';
});
function sendMessage(message) {
const userMessage = document.createElement("p");
userMessage.innerText = `You: ${message}`;
chatlog.appendChild(userMessage);
const loader = document.createElement("div");
loader.classList.add("spinner-border", "spinner-border-sm", "text-primary", "align-self-end");
loader.setAttribute("role", "status");
const botMessage = document.createElement("p");
botMessage.classList.add("text-end");
botMessage.appendChild(loader);
chatlog.appendChild(botMessage);
fetch("https://www.literallyanything.io/api/integrations/chatgpt", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"systemPrompt": "How can I assist you today?",
"prompts": [{ "role": "user", "content": message }]
})
})
.then(res => res.json())
.then(data => {
botMessage.innerText = `Bot: ${data.response}`;
})
.catch(err => {
botMessage.innerText = `Bot: Sorry, I'm unable to process your request at the moment. Please try again later.`;
console.log(err);
});
}
</script>