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',
})
EMITuserConnect

Authenticate the Socket.IO connection with a JWT token.

Payload

NameTypeRequiredDescription
tokenstringYesJWT Bearer token
token_panelstringYesAlways 'therapist'

Example

{
  "token": "eyJhbGci...",
  "token_panel": "therapist"
}
EMITgetConversations

Request the list of chat conversations for the authenticated user.

Payload

NameTypeRequiredDescription
sender_idstringYesAuthenticated user UUID
sender_rolestringYesAlways 'therapist'

Example

{
  "sender_id": "user-uuid",
  "sender_role": "therapist"
}
LISTENconversationsList

Receive the list of conversations in response to getConversations.

Payload

NameTypeRequiredDescription
statusbooleanYesSuccess flag
dataConversation[]YesArray of conversations

Example

{
  "status": true,
  "data": [
    {
      "uuid": "conv-uuid-1",
      "participant_name": "John Doe",
      "last_message": "Thank you",
      "unread_count": 2
    }
  ]
}
EMITgetMessages

Request messages for a specific conversation.

Payload

NameTypeRequiredDescription
conversation_uuidstringYesConversation UUID
sender_idstringYesAuthenticated user UUID
sender_rolestringYesAlways 'therapist'
per_pageintegerNoMessages per page
pageintegerNoPage number

Example

{
  "conversation_uuid": "conv-uuid-1",
  "sender_id": "user-uuid",
  "sender_role": "therapist",
  "per_page": 20,
  "page": 1
}
LISTENmessagesList

Receive messages for a conversation.

Payload

NameTypeRequiredDescription
statusbooleanYesSuccess flag
data.messagesChatMessage[]YesArray of messages
data.totalintegerYesTotal message count

Example

{
  "status": true,
  "data": {
    "messages": [
      {
        "uuid": "msg-1",
        "message": "Hello",
        "sender_role": "therapist",
        "created_at": "2026-03-01T10:00:00Z"
      }
    ],
    "total": 15
  }
}
EMITsendMessage

Send a chat message in a conversation.

Payload

NameTypeRequiredDescription
conversation_uuidstringYesConversation UUID
messagestringYesMessage content
message_typestringYesAlways 'text'
content_textstringYesMessage content (duplicate for compatibility)
receiver_onlinebooleanNoWhether receiver is online
receiver_in_chatbooleanNoWhether 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?"
}
LISTENreceivedMessage

Receive a new incoming message in real-time.

Payload

NameTypeRequiredDescription
statusbooleanYesSuccess flag
dataChatMessageYesThe 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"
  }
}
EMITjoinChat

Join a chat room to receive real-time messages.

Payload

NameTypeRequiredDescription
conversation_uuidstringYesConversation UUID

Example

{
  "conversation_uuid": "conv-uuid-1"
}
EMITleaveChat

Leave a chat room to stop receiving real-time messages.

Payload

NameTypeRequiredDescription
conversation_uuidstringYesConversation UUID

Example

{
  "conversation_uuid": "conv-uuid-1"
}
BOTHtyping

Send or receive typing indicator events.

Payload

NameTypeRequiredDescription
conversation_uuidstringYesConversation UUID
is_typingbooleanYesWhether the user is typing

Example

{
  "conversation_uuid": "conv-uuid-1",
  "is_typing": true
}
EMITdeleteMessage

Delete a message from a conversation.

Payload

NameTypeRequiredDescription
message_idstringYesMessage UUID to delete
conversation_uuidstringYesConversation 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();
  }
});