1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Replace with your actual webhook URL
const webhookUrl = "https://your-n8n-instance.com/webhook/path";
async function testWebhook() {
try {
const response = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
sessionId: "test_session_123",
chatInput: "Hello, this is a test message",
message: "Hello, this is a test message",
sender: "user",
timestamp: new Date().toISOString()
})
});
// Read response as text first
const responseText = await response.text();
console.log("Response status:", response.status);
try {
// Try to parse as JSON
const jsonData = JSON.parse(responseText);
console.log("JSON response:", jsonData);
} catch (e) {
// If not JSON, show as text
console.log("Text response:", responseText);
}
} catch (error) {
console.error("Error testing webhook:", error);
}
}
testWebhook();No Output
Run the code to generate an output.