chatbot
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// 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();
|
||||
|
||||
Reference in New Issue
Block a user