GramAPP / app.js
Merlintxu's picture
Update app.js
eb27c83
raw
history blame
863 Bytes
import axios from 'axios';
let chatBox = document.getElementById('chatBox');
let inputField = document.getElementById('inputField');
function sendMessage() {
let message = inputField.value;
let messageElement = document.createElement('p');
messageElement.textContent = 'You: ' + message;
chatBox.appendChild(messageElement);
axios.post('/api/game', { message: message })
.then(response => {
let botMessageElement = document.createElement('p');
botMessageElement.textContent = 'Bot: ' + response.data.message;
chatBox.appendChild(botMessageElement);
})
.catch(error => console.error(error));
}
inputField.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
sendMessage();
inputField.value = '';
}
});