Skip to main content

Realtime Messages (Socket.IO)

Bot and agent replies are delivered over Socket.IO. On the widget side, the socket is not used to send messages; sending is always done via Send Message. The socket is only for incoming messages.

Connection

Namespace/message
Authauth: { token: accessToken }
Room{chatAppId}-{chatUserId} — the server joins automatically
import { io } from 'socket.io-client';

const socket = io(`${BASE_URL}/message`, {
auth: { token: accessToken },
withCredentials: true,
});

The accessToken is obtained from the Visitor Registration response. See Authentication for details.

Events

EventDirectionPayload
connectedserver → client{ roomId: string, success: true }
messageserver → clientMessage object (same top-level structure as Message History)
errorserver → client{ status: number, message: string } — then disconnect

connected

socket.on('connected', ({ roomId, success }) => {
console.log('bağlandı', roomId, success);
});

message

socket.on('message', (chatMessage) => {
// chatMessage.type ve chatMessage.data → Mesaj Tipleri
console.log(chatMessage);
});

Example payload:

{
"id": "97b56d6f-41d9-4037-ba2f-4d716ee284e0",
"createdAt": "2026-08-03T14:53:05.874Z",
"type": "TEXT",
"nameOfSender": "Support Bot",
"isFromSupport": true,
"data": {
"text": "Nasıl yardımcı olabilirim?"
}
}

The data schema varies by type value: Message Types.

error

socket.on('error', (err) => {
// örn. { status: 401, message: 'Invalid or missing authentication token' }
console.error(err);
});
  1. Visitor RegistrationaccessToken
  2. Connect to the socket and listen for connected / message
  3. Load history via Message History
  4. Send user input via Send Message
  5. Receive bot/agent replies from the message event