top of page
bottom of page
// Function to send chat messages to n8n webhook
function sendMessageToN8N(message, userId, chatId) {
console.log("Preparing to send message to n8n:", message, userId, chatId); // Debug log
fetch("http://localhost:5678/webhook-test/wix-chat", { // REPLACE with your actual public n8n URL
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message: message,
userId: userId,
chatId: chatId
})
})
.then(response => response.json())
.then(data => console.log("Message sent successfully to n8n:", data))
.catch(error => console.error("Error sending message to n8n:", error));
}
// Ensure Wix Chat is ready before running
$w.onReady(() => {
console.log("Wix Chat Integration Initialized"); // Debug log
$w("#chatbox1").onMessage((message) => {
if (message && message.text) {
console.log("Received message from Wix Chat:", message.text); // Debug log
sendMessageToN8N(message.text, message.senderId, message.chatroomId);
} else {
console.error("Invalid message format:", message);
}
});
});
Comments