Install socket.io-client on toddle
Hey there everyone ! I have created a chatbot UI , have been trying to connect it to Flowise API with streaming but no success with that so far . Here is their documentation on this : https://docs.flowiseai.com/using-flowise/streaming The first step is to Install socket.io-client to your front-end application , how can we do that in Toddle ? Apart from that , here 's what I 've done : const io = require("socket.io-client");
const fetch = require("node-fetch");
async function flowiseStreaming(args, ctx) {
const flowiseUrl = "http://localhost:3000"; // Reemplaza con tu URL de Flowise
const chatflowId = "<chatflow-id>"; // Reemplaza con el ID de tu chatflow
const socket = io(flowiseUrl);
socket.on("connect", () => {
const socketIOClientId = socket.id;
async function sendQuery(data) {
const response = await fetch(
`${flowiseUrl}/api/v1/prediction/${chatflowId}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
question: args.question,
socketIOClientId,
}),
}
);
const result = await response.json();
return result;
}
sendQuery().then((response) => {
console.log(response);
});
});
socket.on("start", () => {
ctx.triggerActionEvent("start");
});
socket.on("token", (token) => {
ctx.triggerActionEvent("token", token);
});
socket.on("sourceDocuments", (sourceDocuments) => {
ctx.triggerActionEvent("sourceDocuments", sourceDocuments);
});
socket.on("end", () => {
ctx.triggerActionEvent("end");
socket.disconnect();
});
}
module.exports = flowiseStreaming;I am not a coder , trying my best to make this work but at this point I do not understand what 's wrong here and don 't know how to debug it . Any help would be very helpful 🙏🏻 ✅1There are some additional installation options here https://socket.io/docs/v4/client-api/ If you 're using a custom action , then you could do something like async function flowiseStreaming(args, ctx) {
const { io } = await import("https://cdn.socket.io/4.7.5/socket.io.esm.min.js");
...rest of your code goes here...
}❤️1Getting this error on the console : Error in Custom Action ReferenceError : module is not defined at Object .handler (custom -code .js ?v =cd95520 &entry = C o m p o n e n t s : 7 3 :1 ) at T (runtime . t s : 3 7 0 :30 ) at runtime . t s : 1 4 3 7 :11 at Array .forEach ( <anonymous > ) at Object .onEvent [as triggerEvent ] (runtime . t s : 1 4 3 6 :30 ) at T (runtime . t s : 2 0 3 :13 ) at runtime . t s : 1 5 5 5 :9 at Array .forEach ( <anonymous > ) at HTMLButtonElement .y (runtime . t s : 1 5 3 2 :21 ) The code
.jpeg/public)