async function sendMessage() {
const userMessage = input.value;
if (!userMessage.trim()) return;
addMessage(userMessage, "user");
input.value = "";
try {
const response = await fetch("https://chatgpt.com/g/g-675c6525c1888191bbdf8636cd29ef21-cotizaciones", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ message: userMessage }),
});
if (!response.ok) {
throw new Error(`Error del servidor: ${response.status}`);
}
const data = await response.json();
const botMessage = data.response || "Lo siento, no pude procesar eso.";
addMessage(botMessage, "bot");
} catch (error) {
console.error("Error en la solicitud:", error);
addMessage("Ocurrió un error al conectar con el servidor. Por favor, intenta nuevamente.", "bot");
}
}