// Test script for ChatbotGateway Socket.IO connection // Run with: node test-chatbot-socket.js const io = require("socket.io-client"); // Connect to the chatbot gateway // The path option matches the path configured in ChatbotGateway const socket = io("http://localhost:4000", { path: "/ws-chatbot", transports: ["websocket"], // Optional: Add token for authenticated connection // query: { // token: "your-jwt-token-here" // } }); socket.on("connect", () => { console.log("āœ… Connected to ChatbotGateway!"); console.log("Socket ID:", socket.id); // Test: Create a session console.log("\nšŸ“¤ Creating session..."); socket.emit("create_session"); }); socket.on("authenticated", (data) => { console.log("āœ… Authenticated:", data); }); socket.on("unauthorized", (data) => { console.log("āŒ Unauthorized:", data); }); socket.on("session_created", (data) => { console.log("āœ… Session created:", JSON.stringify(data, null, 2)); // Test: Join the session if (data.data && data.data.id) { console.log("\nšŸ“¤ Joining session:", data.data.id); socket.emit("join_chat", data.data.id); } }); socket.on("chat_joined", (data) => { console.log("āœ… Joined chat:", JSON.stringify(data, null, 2)); // Test: Send a message if (data.data && data.data.id) { console.log("\nšŸ“¤ Sending test message..."); socket.emit("send_message", { sessionId: data.data.id, content: "Hello, chatbot!", }); } }); socket.on("message_received", (data) => { console.log("šŸ“Ø Message received:", JSON.stringify(data, null, 2)); }); socket.on("bot_response_start", (data) => { console.log("šŸ¤– Bot response started:", JSON.stringify(data, null, 2)); }); socket.on("bot_response_chunk", (data) => { process.stdout.write(data.data?.chunk || ""); }); socket.on("bot_response_end", (data) => { console.log("\nāœ… Bot response completed:", JSON.stringify(data, null, 2)); }); socket.on("bot_response", (data) => { console.log("šŸ¤– Bot response:", JSON.stringify(data, null, 2)); }); socket.on("error", (data) => { console.log("āŒ Error:", JSON.stringify(data, null, 2)); }); socket.on("session_error", (data) => { console.log("āŒ Session error:", JSON.stringify(data, null, 2)); }); socket.on("message_error", (data) => { console.log("āŒ Message error:", JSON.stringify(data, null, 2)); }); socket.on("disconnect", (reason) => { console.log("āŒ Disconnected:", reason); }); socket.on("connect_error", (error) => { console.log("āŒ Connection error:", error.message); }); // Keep the script running process.stdin.resume();