chat module is the server-side client for Sublay’s messaging: direct and group conversations, messages (with GIFs, mentions, threads, quotes, and file attachments), membership, reactions, read state, and reporting.
Acting on behalf of a user
Your service key has no implicit session user, so every chat call takes the user it acts as, inactingUserId. Where a function also takes a userId (createDirectConversation, addMember, removeMember, changeMemberRole), that userId is the target user. See Acting on behalf of a user.
Omitting
actingUserId returns 400 chat/missing-user-id.Conversations
listConversations
Lists the acting user’s conversations, newest activity first. Uses cursor pagination — passpagination.nextCursor from the previous page as cursor to get the next one.
Only conversations of these types: any of
"direct", "group", "space". Omitted, every type is listed.pagination.nextCursor from the previous response, passed as returned; omit it (or pass null) for the first page. It is opaque: don’t build or parse it. One the server can’t read is rejected with 400 chat/invalid-cursor.Promise<CursorPaginatedResponse<ConversationPreview>>: { data: ConversationPreview[]; pagination: { nextCursor: string | null; hasMore: boolean } }. nextCursor is null when hasMore is false.
A ConversationPreview is the conversation’s own fields plus:
unreadCountandmemberCount(active members).mutedUntilandmutedForever: the acting user’s mute on the conversation (see muteConversation).otherMembers— up to 5 active members other than the acting user (id,name,username,avatar) fordirect/groupconversations, so a DM/group can render the counterparty without a separate members fetch. Capped at 5 (usememberCountfor the group total); empty forspaceconversations.lastMessage(ConversationPreviewLastMessage | null): a preview of the newest top-level message —id,conversationId,content(cut to 100 characters),gif,userId,moderationStatus,userDeletedAt,createdAt,files, anduser({ id, name, username, avatar, reputation }, ongroupandspacerows only;nullondirectrows). It has no mentions, quotes or reactions. A deleted or removed last message is its placeholder.
createDirectConversation
Returns the one-to-one conversation between the acting user and a target user, or creates it when there is none. Props type:CreateDirectConversationProps.
Promise<CreateDirectConversationResult>: { conversation: Conversation; created: boolean }. created is true when this call created the conversation (HTTP 201) and false when it already existed (HTTP 200).
createGroupConversation
Creates a group conversation; the acting user becomes its admin.The group’s avatar image, up to 50 MB. Raw bytes carry no type, so pass
mimeType with a Uint8Array (image/jpeg, image/png or image/webp; without it the file goes as application/octet-stream and is refused with 400 chat/unsupported-file-type); a Blob keeps its own type. options says how to process the image and must include mode (see Upload Image). With an image, the request is sent as multipart/form-data. Requires the files-images bundle.Promise<Conversation>
getConversation
Fetches a single conversation the acting user is a member of.Promise<Conversation>, with memberCount (active members) and currentMember (the acting user’s own member row, or null when they have none).
updateConversation
Updates a group conversation. Requires the acting user to be a group admin.A new avatar image, replacing the current one (up to 50 MB). Raw bytes carry no type, so pass
mimeType with a Uint8Array (image/jpeg, image/png or image/webp; without it the file goes as application/octet-stream and is refused with 400 chat/unsupported-file-type); a Blob keeps its own type. options says how to process the image and must include mode (see Upload Image). With an image, the request is sent as multipart/form-data.Files to remove: the conversation’s
avatarFileId, nothing else. Removing it clears the avatar. Works alone or with a new avatarFile. Any other id throws a 400 (chat/invalid-remove-file-ids, with invalidIds).Space conversations only: who may post — any active member (
"members") or only the space’s active admins and moderators ("team").Promise<Conversation>
deleteConversation
Deletes a group conversation. Requires the acting user to be a group admin.Promise<void>
getUnreadCount
Returns the acting user’s unread totals across all conversations.Promise<{ totalUnread: number; unreadConversationCount: number }>
Members
listMembers
Results per page: a whole number from
1 to 100. Defaults to 50. A larger value is rejected with 400 chat/invalid-query, never lowered to 100.Promise<PaginatedResponse<ConversationMember>>
addMember
Adds a member to a group. Requires the acting caller to be a group admin.Promise<ConversationMember>
removeMember
Removes another member from a group. Requires the acting caller to be a group admin. AuserId equal to actingUserId is refused with 400 chat/own-member-id: to leave, use leaveConversation.
Promise<void>
changeMemberRole
Promotes or demotes another member. Requires the acting caller to be a group admin. AuserId equal to actingUserId is refused with 400 chat/own-member-id.
Promise<ConversationMember>
checkMyConversationMembership
Reads the acting user’s own membership in a conversation (GET /chat/conversations/:conversationId/members/me).
Promise<CheckMyConversationMembershipResponse>, a flat object where a field that doesn’t apply is left out:
- an active member:
{ isMember: true, role, lastReadAt, mutedForever, mutedUntil } - a user who left or was removed:
{ isMember: false, leftAt } - a user with no membership yet (a space conversation they haven’t opened):
{ isMember: false }
404 chat/not-found or 403 chat/not-a-member). See Check My Membership.
leaveConversation
The acting user leaves a conversation (DELETE /chat/conversations/:conversationId/members/me).
Promise<void>. It resolves with no value once the user has left.
Messages
listMessages
Lists messages in a conversation. Pages are anchored on a message — pass a message id asbefore to page backwards, or as after to page forwards (before/after are mutually exclusive).
A message id: the
limit messages just before it. Pass the oldest message you hold to load older ones. It must be a message of this conversation at the same thread level (parentMessageId), or the call is rejected with 400 chat/invalid-cursor. Mutually exclusive with after.A message id: the
limit messages just after it. Pass the newest message you hold to load newer ones. Same rules as before. Mutually exclusive with before.The order of the page by creation time. Defaults to
"desc" for the main stream and "asc" for a thread. With before or after, the anchor decides which messages are in the page; sortDir only orders them.Associations to populate, as a single value or an array:
"files" (the message’s images and files) and "grants" (each message’s reputation-grant summary). Pass ["files", "grants"] for both.Optional filters.
filters.hasReplies (boolean): when true, returns only messages that have thread replies (threadReplyCount > 0); when false, only messages with none. Filters by thread replies, not quotings. Threads are one level deep, so hasReplies: true together with parentMessageId always returns an empty list — the response’s notice field explains why.Promise<{ data: ChatMessage[]; pagination: { hasMore: boolean }; notice?: string }>. hasMore says whether more messages exist past this page in the direction of travel: older with before, newer with after; with neither, older for "desc" and newer for "asc". See List Messages › Paging.
sendMessage
Sends a message as the acting user. A message must have content, a GIF, or at least one image or file. Whenimages or files are attached the request is sent as multipart/form-data; otherwise it’s a JSON body.
{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options: ImageOptions }
Images, 50 MB each, processed per
options (mode is required); each comes back with image and its variants. Pass mimeType with a Uint8Array; a part without a filename is named image. A request takes at most 20 files in all. Requires the files-images bundle.{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options?: { pathParts?: string[] } }
Files, 50 MB each, stored as uploaded (JPEG, PNG, WebP or PDF: pass
mimeType with a Uint8Array) (image is null, an image sent here included). A part without a filename is named file. Requires the files-images bundle.Promise<SendMessageResponse>: the created message as a SentChatMessage (a ChatMessage without reactionCounts, userReactions and grants), with localId when you passed one.
getMessage
A single value or an array. The only value is
"grants" — it attaches the message’s reputation-grant summary at message.grants. The message’s files are always returned.Promise<ChatMessage>
editMessage
Edits a message. Requires the acting user to be the message author.A GifData attachment, or
null to clear it.Promise<SentChatMessage>: the edited message, without reactionCounts, userReactions and grants.
deleteMessage
Soft-deletes a message. Requires the acting user to be the author or a group admin.Promise<void>
Reporting a message
Message reports go through the shared reports API, not a chat-specific function — the same call that reports entities and comments.targetId is the message id; the conversation is resolved server-side, so no
conversationId is needed. The reporter must be a member of the conversation
and cannot report their own message. See createReport.
Reactions
toggleReaction
Adds or removes the acting user’s emoji reaction on a message. A deleted or removed message takes no new reaction: adding one fails with404 chat/message-not-found, while taking back the acting user’s own still works.
Promise<{ reactionCounts: Record<string, number>; userReactions: string[]; delta: 1 | -1 }> (delta is 1 if the reaction was added, -1 if removed).
listReactions
Lists the users who reacted with a given emoji.Results per page: a whole number from
1 to 100. Defaults to 50. A larger value is rejected with 400 chat/invalid-query, never lowered to 100.Promise<{ data: MessageReaction[]; pagination: { page; limit; total; hasMore } }>, where MessageReaction is { emoji: string; user: UserSummary; createdAt: string } and the user is { id, name, username, avatar, reputation } (plus spaceReputation when requested).
Read state
markAsRead
Marks the conversation read up to a given message.Promise<void>
muteConversation
Sets or clears a user’s mute on a conversation. Muting suppresses themessage push for this conversation only; the message is still delivered. See Notification Preferences & Mute.
Like every other
chat call, the Node SDK names the acting user with actingUserId. The user must be a member of the conversation, and the returned currentMember is that user’s own row. End-user-token clients (the React hooks, the browser JS SDK) act on the signed-in user and send no actingUserId.The mute duration choice, or
null to clear the mute. Send the choice, never a raw timestamp.Promise<{ currentMember: ConversationMember }> — that user’s own member row.
“Forever” is an explicit signal. A
forever mute returns mutedForever: true with mutedUntil: null. A timed mute returns mutedForever: false with a real ISO mutedUntil. Read the boolean — never string-match a far-future date.Space conversations
Each space has a single built-in conversation. These three live onclient.spaces (they’re /spaces/... routes), not on client.chat.
spaces.getSpaceConversation
Fetches-or-creates a space’s conversation and joins the acting user to it. The acting user must be an active member of the space; a pending or rejected request, or a ban, is refused.Promise<Conversation>, with memberCount and currentMember (the acting user’s own member row).
spaces.moderateSpaceChatMessage
Removes a message in a space conversation.On the space moderation routes,
actingUserId is required: the request has
exactly that user’s moderation permissions and is refused if they cannot
moderate the space.The moderation action. Chat messages are never held for approval, so
"remove" is the only value.The moderator the request acts as: they must be a moderator or admin of the space, and the action is recorded as theirs.
Promise<{ moderationStatus: "removed" | null }>: null for a message its author deleted (and nobody removed), which is left as it was.
Handling chat message reports
A report against a space-conversation message is handled withspaces.handleSpaceReport, the one function for every report type in a space. A chat message report takes the actions "remove-message", "ban-user" and "dismiss", and requires a summary like every other report type.
