WebSocket Events
Real-time messaging via Socket.IO. 11 events for chat, typing indicators, and message management.
Connection Setup
Connect to the Socket.IO server and authenticate with your JWT token:
import { io } from 'socket.io-client';
const socket = io('https://visitnote-api-production.up.railway.app', {
transports: ['websocket'],
autoConnect: true,
});
// Authenticate after connecting
socket.emit('userConnect', {
token: 'YOUR_JWT_TOKEN',
token_panel: 'therapist',
});Python Example
import socketio
sio = socketio.Client()
sio.connect('https://visitnote-api-production.up.railway.app', transports=['websocket'])
sio.emit('userConnect', {
'token': 'YOUR_JWT_TOKEN',
'token_panel': 'therapist',
})userConnectAuthenticate the Socket.IO connection with a JWT token.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
token | string | Yes | JWT Bearer token |
token_panel | string | Yes | Always 'therapist' |
Example
{
"token": "eyJhbGci...",
"token_panel": "therapist"
}getConversationsRequest the list of chat conversations for the authenticated user.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
sender_id | string | Yes | Authenticated user UUID |
sender_role | string | Yes | Always 'therapist' |
Example
{
"sender_id": "user-uuid",
"sender_role": "therapist"
}conversationsListReceive the list of conversations in response to getConversations.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
status | boolean | Yes | Success flag |
data | Conversation[] | Yes | Array of conversations |
Example
{
"status": true,
"data": [
{
"uuid": "conv-uuid-1",
"participant_name": "John Doe",
"last_message": "Thank you",
"unread_count": 2
}
]
}getMessagesRequest messages for a specific conversation.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
conversation_uuid | string | Yes | Conversation UUID |
sender_id | string | Yes | Authenticated user UUID |
sender_role | string | Yes | Always 'therapist' |
per_page | integer | No | Messages per page |
page | integer | No | Page number |
Example
{
"conversation_uuid": "conv-uuid-1",
"sender_id": "user-uuid",
"sender_role": "therapist",
"per_page": 20,
"page": 1
}messagesListReceive messages for a conversation.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
status | boolean | Yes | Success flag |
data.messages | ChatMessage[] | Yes | Array of messages |
data.total | integer | Yes | Total message count |
Example
{
"status": true,
"data": {
"messages": [
{
"uuid": "msg-1",
"message": "Hello",
"sender_role": "therapist",
"created_at": "2026-03-01T10:00:00Z"
}
],
"total": 15
}
}sendMessageSend a chat message in a conversation.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
conversation_uuid | string | Yes | Conversation UUID |
message | string | Yes | Message content |
message_type | string | Yes | Always 'text' |
content_text | string | Yes | Message content (duplicate for compatibility) |
receiver_online | boolean | No | Whether receiver is online |
receiver_in_chat | boolean | No | Whether receiver is in the chat room |
Example
{
"conversation_uuid": "conv-uuid-1",
"message": "How are you feeling today?",
"message_type": "text",
"content_text": "How are you feeling today?"
}receivedMessageReceive a new incoming message in real-time.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
status | boolean | Yes | Success flag |
data | ChatMessage | Yes | The received message |
Example
{
"status": true,
"data": {
"uuid": "msg-2",
"message": "I'm feeling much better",
"sender_role": "patient",
"created_at": "2026-03-01T10:05:00Z"
}
}joinChatJoin a chat room to receive real-time messages.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
conversation_uuid | string | Yes | Conversation UUID |
Example
{
"conversation_uuid": "conv-uuid-1"
}leaveChatLeave a chat room to stop receiving real-time messages.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
conversation_uuid | string | Yes | Conversation UUID |
Example
{
"conversation_uuid": "conv-uuid-1"
}typingSend or receive typing indicator events.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
conversation_uuid | string | Yes | Conversation UUID |
is_typing | boolean | Yes | Whether the user is typing |
Example
{
"conversation_uuid": "conv-uuid-1",
"is_typing": true
}deleteMessageDelete a message from a conversation.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
message_id | string | Yes | Message UUID to delete |
conversation_uuid | string | Yes | Conversation UUID |
Example
{
"message_id": "msg-1",
"conversation_uuid": "conv-uuid-1"
}Common Patterns
Listing Conversations
// Request conversations
socket.emit('getConversations', {
sender_id: 'your-user-uuid',
sender_role: 'therapist',
});
// Listen for response
socket.on('conversationsList', (data) => {
console.log('Conversations:', data.data);
});Sending and Receiving Messages
// Join a chat room
socket.emit('joinChat', { conversation_uuid: 'conv-uuid' });
// Send a message
socket.emit('sendMessage', {
conversation_uuid: 'conv-uuid',
message: 'Hello, how are you feeling?',
message_type: 'text',
content_text: 'Hello, how are you feeling?',
});
// Listen for incoming messages
socket.on('receivedMessage', (data) => {
console.log('New message:', data.data);
});
// Leave when done
socket.emit('leaveChat', { conversation_uuid: 'conv-uuid' });Typing Indicators
// Send typing status
socket.emit('typing', {
conversation_uuid: 'conv-uuid',
is_typing: true,
});
// Listen for other user's typing
socket.on('typing', (data) => {
if (data.is_typing) {
showTypingIndicator();
} else {
hideTypingIndicator();
}
});Sign in to access API docs
Full API reference is available to VisitNote subscribers.
Don't have an account? Start free trial