function sendMessage()

in reference-architectures/cloud_deploy_flow/WebsiteDemo/public/script.js [70:94]


function sendMessage() {
  const messageInput = document.getElementById('message-input');
  let message = messageInput.value;
  // Clean up the message
  message = message.trim(); // Remove leading and trailing whitespace
  message = message.replace(/\n/g, ''); // Remove newline characters

  // Send the message to the backend
  fetch('/send-message', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: message,
  })
    .then((response) => {
      if (response.ok) {
        messageInput.value = ''; // Clear the input after sending
        updateMessages(); // Optionally refresh messages after sending
      } else {
        console.error('Failed to send message');
      }
    })
    .catch((error) => console.error('Error:', error));
}