Skip to main content

Streaming messages

Streaming messages deliver content incrementally, similar to how AI chatbots stream their responses token by token. Use streaming messages to display content in real time as it is generated.

How it works

A streaming message is sent in chunks. The sender sends multiple updates for the same message, and the receiver appends each chunk to display the message progressively.

Receive streaming messages

Register a listener to handle streaming message updates:

TypeScript
import { NCEngine, MessageHandler } from '@nexconn/chat';

NCEngine.addMessageHandler('stream-handler', new MessageHandler({
onStreamMessageRequestInit({ messageId }) {
// Called when a new streaming message begins
console.log('Streaming started for message:', messageId);
},
onStreamMessageRequestDelta({ messageId, chunkInfo }) {
// Called for each incremental chunk
console.log('Chunk received:', chunkInfo.content);
console.log('Full content so far:', chunkInfo.messageContent);
},
onStreamMessageRequestComplete({ messageId, code }) {
// Called when the stream is complete
console.log('Streaming complete for message:', messageId, 'Code:', code);
},
}));

StreamMessageRequestChunkInfo fields

FieldTypeDescription
contentstringThe incremental content chunk for this update
messageContentstringThe accumulated full content up to this point

The parent StreamMessageDeltaEvent also includes messageId for the streaming message.

info
  • Streaming messages are typically used for AI chatbot responses and real-time content generation.
  • The client accumulates chunks and displays them progressively in the UI.
  • When onStreamMessageRequestComplete fires, no more chunks will be sent for this message.