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 |
| Auth | auth: { 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
| Event | Direction | Payload |
|---|---|---|
connected | server → client | { roomId: string, success: true } |
message | server → client | Message object (same top-level structure as Message History) |
error | server → 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);
});
Recommended order
- Visitor Registration →
accessToken - Connect to the socket and listen for
connected/message - Load history via Message History
- Send user input via Send Message
- Receive bot/agent replies from the
messageevent