Streaming

Using WebSockets provides the ability to stream responses back to a client in order to allow partial results for certain requests. This improves the perceived responsiveness of applications and offers a better user experience.
The WebSocket url is https://api.lingoblocks.com.

Message Streaming

Stream a message response back to a client as it's being generated.
  • WebSocket URL: https://api.lingoblocks.com
  • Requirements:
    • accessToken: The existing access token for the session (see Authentication).
    • socket.io-client: WebSocket client library (see npm package).

Setup and Connection

  1. 1.
    Import socket.io-client to create a WebSocket connection.
import { io } from "socket.io-client";
  1. 2.
    Initialize socket connection.
const options = {
transportOptions: {
polling: {
extraHeaders: {
"access-token": "<access-token>"
}
}
}
};
const socket = io("https://api.lingoblocks.com", options);

Receiving Messages

  • Listen for messages on the message event.
  • Filter messages by checking if the event data matches chatbot.responseGenerated.
  • Process the streamed message data.
socket.on("message", (eventData) => {
if (eventData.event === "chatbot.responseGenerated") {
console.log("Streaming message data:", eventData.data);
}
};
Last modified 2mo ago