Skip to main content

Open chat session stream

GET 

/participants/:user_id/chat_sessions/:id/stream

Open a new chat session stream to listen for new chat events on a single chat session from the server.

This is a supplementary endpoint to the /participants/{user_id}/stream endpoint to support the secondary stream for chat messages.

This will be useful to create an application which requires a separate stream for a main participant stream and a specific chat session.

For example,

  • a main stream for dealing with the participant's activity cards and an incoming chat message but remains unread until the participant open the chat session.
  • a second stream for a specific chat session to listen for new chat messages in the chat session and mark the message as read
  • the second stream should be closed when the participant leaves the chat session or switches to another session

The server sends the Server Sent Event in plain text to the client in this format when there is an event.

data: {"eventType": "MESSAGE_SENT", payload: [.....] }

EventTypes

KEEP_ALIVE This will be issued every 15 seconds to the client so the connection is kept open. you can simply ignore this.

MESSAGE_SENT This will be issued when there is a message sent from the server. This can be used for building a chat application The payload for this event can be found from api/v1/docs#/schemas/ChatMessage

CHAT_SESSION_MEMBER_REQUESTED This will be issued when a coach tried to join a locked chat session.

CHAT_SESSION_MEMBER_JOINED This will be issued when a new member joins the chat session.

CHAT_SESSION_MEMBER_LEFT This will be issued when a member leaves the chat session.

payload for these events will have the following structure

{ "sessionId": "string", "participantId": "string", "memberId": "string", "memberType": "string", "memberName": "string", "photoUrl": "string or null" }

CHAT_SESSION_MEMBER_APPROVED This will be issued when an existing session member approves the coach to join the chat session.

CHAT_SESSION_MEMBER_REJECTED This will be issued when an existing session member rejects the coach to join the chat session.

The payload for these events will have the following structure

{ "sessionId": "string", "participantId": "string", "memberId": "string", "memberType": "string", "memberName": "string", "approvedBy": "string", // or "rejectedBy": "string" }

** It is recommended to use EventSourcePolly from https://github.com/Yaffle/EventSource This will extend the EventSource to have Headers for the auth token.

sse = new EventSourcePolyfill(streamURL, {
headers: {
"Authorization": "Bearer ${authToken}",
"X-API-Key": "${apiKey}"
}
});

Request

Responses

OK