I’m trying to make an ai chatbot in my application using n8n as my backend ai agent. For that, I’m using webhooks. I have three UI elements for this: the text input field, a text display field and a button to trigger the webhook. However, I’m not getting the text input through the webhook, and my message variable always shows empty like so:
As you can see, I have successfully sent timestamps an other data, but the text I enter in the text inputfield is never sent. The code I using for this purpose is the following:
import {
Behaviour,
serializable,
Text,
InputField,
Button
} from “@needle-tools/engine”;
export class ARChatAgent extends Behaviour {
@serializable(Text)
chatOutput!: Text;
@serializable(InputField)
chatInput!: InputField;
@serializable(Button)
sendButton!: Button;
start() {
// Listen to button clicks
this.sendButton.gameObject.addEventListener(“click”, () => {
const message = this.chatInput.text;
console.log(“Sending to AI:”, message); // DEBUG STEP 1
if (message && message.trim()) {
this.sendToAI(message);
} else {
console.warn("Input message is empty or not set!");
}
});
}
async sendToAI(userMessage: string) {
try {
const response = await fetch(“https://my-n8n-server/webhook/ar-chat”, {
method: “POST”,
headers: {
“Content-Type”: “application/json”
},
body: JSON.stringify({ message: userMessage })
});
console.log("Response status:", response.status); // ✅ DEBUG STEP 2
const replyText = await response.text();
console.log("Raw reply from n8n:", replyText); // ✅ DEBUG STEP 2
this.chatOutput.text = replyText || "No reply received";
} catch (error) {
console.error("Error fetching AI reply:", error);
this.chatOutput.text = "Error connecting to AI.";
}
}
}
Note that this log is never activated when starting the application:
console.log(“Sending to AI:”, message); // DEBUG STEP 1
Can anyone let me know what am i missing or point me to the docs for this.
Thanks!