WEBSOCKET MESSAGES
2) Then, create a conversation. There are two types of conversation: user-to-user (only 2 users) and group conversations (from 0 to N users). Just like on facebook, users **don't need to be friends** to start conversation, you can start conversation with any user in the system.
* Create user-to-user conversation via POST /chats/conversation/, pass JSON with one field: userprofile_id (the guy you want to talk to)
* Create group conversation via POST /chats/group_conversation/, pass JSON with name and user_profile_ids (list of guys you want to talk to - you MUST include your own profile id here as well!)
3) To list conversations and group conversations we are in:
* GET /api/v1/chats/conversation
* GET /api/v1/chats/group_conversation/
4) Get a chat server session token via POST /chats/session/open-session/, pass device_identifier (unique device id such as mac address)
5) Open a web socket to the chat server, and start sending/receiving messages: see the section below.
ROUTABLE
Request
type: 'ROUTABLE'
chat_room_identifier: string
message: string
}
HISTORY
* from_message_timestamp_identifier -> unix epoch timestamp (in nanoseconds) before which you want to pull messages.
For example to pull messages before September 1, 2021 9:50:38 (unix timestamp 1630489838) you need to pass 1630489838000000000
* limit -> how many messages you want to get. Maximum is 100.
Request
type: 'GET_HISTORY'
chat_room_identifier: string
from_message_timestamp_identifier: integer
limit: integer
}
SET LAST MESSAGE READ
Request
type: 'SET_LAST_MESSAGE_READ'
chat_room_identifier: string
message_timestamp_identifier: integer
}
GET LAST MESSAGES READ
Request
type: 'GET_LAST_MESSAGES_READ'
chat_room_identifier: string
}
GET LAST CHAT ROOM MESSAGE
Request
type: 'GET_LAST_CHAT_ROOM_MESSAGE'
chat_room_identifiers: list[string]
}
GET UNREAD MESSAGES COUNT
Request
type: 'GET_UNREAD_MESSAGES_COUNT'
chat_room_identifiers: list[string]
}
ERROR
* 10001 - Internal server error.
* 10001 - User does not belong to this chat room. The cause of this error is when you pass an incorrect chat_room_identifier.
* 10002 - 'message' field must be a string type.
* 10003 - Length of chat_room_identifiers list cannot be grater than 10. This error is specific to GET_UNREAD_MESSAGES_COUNT request.
* 10004 - Invalid message format. You'll see this error when your message is malformed, i.e. not a valid JSON.
* 10005 - Missing required field. You sent a message without a required field. This error will include an extra object with the name of the required field.
* 10006 - Central router not present. Consider this an internal server error.
* 10007 - Message flood detected. If user spams the chat with more than 300 messages per minute, server will send back this error and terminate
socket connection. You should show an appropriate error message to the user in your client app and re-open the socket.
Example response
type: ROUTABLE
message_timestamp_identifier: 1630499662256827108
chat_room_identifier: b95c5d7e-0fad-415a-8ea5-035f1a79c335:SFF-QA
app_user_identifier: def094f5-2e13-45e7-8712-edb2e8b55fe5:SFF-QA
message: Hello world!
custom_data: {\"display_name\": \"Joe Biden\", \"first_name\": \"Joe\", \"last_name\": \"Biden\"}
}
SYSTEM ROUTABLE
* chat_room_identifier - chat room in which the message was written
* message_timestamp_identifier - message timestamp in form of unix epoch time, in nanoseconds
* app_user_identifier - identifier of the use who wrote the message
* custom_data - custom data associated with the user who wrote the message
* message - the message content
Example response
type: SYSTEM_ROUTABLE
chat_room_identifier: b95c5d7e-0fad-415a-8ea5-035f1a79c335:SFF-QA
message_timestamp_identifier: 1639741268522956324
message: System message!
}
GET HISTORY
Example response
type: GET_HISTORY
payload: [
{
message: Hello world!
is_system_message: False
message_timestamp_identifier: 1639741268522956324
chat_room_identifier: b95c5d7e-0fad-415a-8ea5-035f1a79c335:SFF-QA
app_user_identifier: def094f5-2e13-45e7-8712-edb2e8b55fe5:SFF-QA
custom_data: {\"display_name\": \"Joe Biden\", \"first_name\": \"Joe\", \"last_name\": \"Biden\"}
},
... more messages ...
]
}
GET LAST MESSAGES READ
Example response
type: GET_LAST_MESSAGES_READ
payload: [
{
message_timestamp_identifier: 1630499662256827108
chat_room_identifier: b95c5d7e-0fad-415a-8ea5-035f1a79c335:SFF-QA
app_user_identifier: def094f5-2e13-45e7-8712-edb2e8b55fe5:SFF-QA
custom_data: {\"display_name\": \"Joe Biden\", \"first_name\": \"Joe\", \"last_name\": \"Biden\"}
},
... more messages ...
]
}
SET LAST MESSAGE READ
Example response
type: GET_LAST_MESSAGES_READ
message_timestamp_identifier: 1630499662256827108
chat_room_identifier: b95c5d7e-0fad-415a-8ea5-035f1a79c335:SFF-QA
app_user_identifier: def094f5-2e13-45e7-8712-edb2e8b55fe5:SFF-QA
custom_data: {\"display_name\": \"Joe Biden\", \"first_name\": \"Joe\", \"last_name\": \"Biden\"}
GET LAST CHAT ROOM MESSAGE
Example response
type: GET_LAST_CHAT_ROOM_MESSAGE
payload: [
{
chat_room_identifier: ceaa81a9-6ca9-4b5c-a1c7-64c81f7cbf87:SFF-QA
last_message_text: Hello world!
message_timestamp_identifier: 1634223745351316876
has_unread_messages: true
},
... more chat room data ...
]
}
GET UNREAD MESSAGES COUNT
Example response
type: GET_UNREAD_MESSAGES_COUNT
payload: [
{
chat_room_identifier: ceaa81a9-6ca9-4b5c-a1c7-64c81f7cbf87:SFF-QA
unread_messages_count: 13
},
... more chat room data ...
]
}