Skip to main content
The 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, in actingUserId. Where a function also takes a userId (createDirectConversation, addMember, removeMember, changeMemberRole), that userId is the target user. See Acting on behalf of a user.
Membership is enforced against the acting user (resolve-then-check). Sublay resolves the named user first, then runs the normal conversation checks against that user. So you can only act as a user who is genuinely a member of the conversation, and admin-only actions (delete/update conversation, add/remove members, change roles) require that user to be a group admin. A service key cannot post into a conversation as a user who isn’t in it.
Omitting actingUserId returns 400 chat/missing-user-id.

Conversations

listConversations

Lists the acting user’s conversations, newest activity first. Uses cursor pagination — pass pagination.nextCursor from the previous page as cursor to get the next one.
string
required
The user whose conversations are listed.
ConversationType | ConversationType[]
Only conversations of these types: any of "direct", "group", "space". Omitted, every type is listed.
string | null
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.
number
Page size, 1–50. Defaults to 20.
Returns — 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:
  • unreadCount and memberCount (active members).
  • mutedUntil and mutedForever: 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) for direct/group conversations, so a DM/group can render the counterparty without a separate members fetch. Capped at 5 (use memberCount for the group total); empty for space conversations.
  • lastMessage (ConversationPreviewLastMessage | null): a preview of the newest top-level message — id, conversationId, content (cut to 100 characters), gif, userId, moderationStatus, userDeletedAt, createdAt, files, and user ({ id, name, username, avatar, reputation }, on group and space rows only; null on direct rows). 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.
string
required
The other participant (the target).
string
required
The user initiating the DM.
Returns — 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.
string
required
The acting user (becomes the group admin).
string
Group name.
string
Group description.
string[]
Initial members to add.
object
Custom key-value data.
{ file: Uint8Array | Blob; filename?: string; mimeType?: string; options: ImageOptions }
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.
Returns — Promise<Conversation>

getConversation

Fetches a single conversation the acting user is a member of.
string
required
string
required
The acting user (must be a member).
Returns — 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.
string
required
string
required
The acting user (must be a group admin).
string
string
{ file: Uint8Array | Blob; filename?: string; mimeType?: string; options: ImageOptions }
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.
string[]
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).
"members" | "team"
Space conversations only: who may post — any active member ("members") or only the space’s active admins and moderators ("team").
Returns — Promise<Conversation>

deleteConversation

Deletes a group conversation. Requires the acting user to be a group admin.
string
required
string
required
The acting user (must be a group admin).
Returns — Promise<void>

getUnreadCount

Returns the acting user’s unread totals across all conversations.
string
required
Returns — Promise<{ totalUnread: number; unreadConversationCount: number }>

Members

listMembers

string
required
string
required
The acting user (must be a member).
number
Defaults to 1.
number
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.
"admin" | "member"
Filter by role.
Returns — Promise<PaginatedResponse<ConversationMember>>

addMember

Adds a member to a group. Requires the acting caller to be a group admin.
string
required
string
required
The member to add (the target).
string
required
The caller (must be a group admin).
Returns — Promise<ConversationMember>

removeMember

Removes another member from a group. Requires the acting caller to be a group admin. A userId equal to actingUserId is refused with 400 chat/own-member-id: to leave, use leaveConversation.
string
required
string
required
The member to remove (the target).
string
required
The caller (must be a group admin).
Returns — Promise<void>

changeMemberRole

Promotes or demotes another member. Requires the acting caller to be a group admin. A userId equal to actingUserId is refused with 400 chat/own-member-id.
string
required
string
required
The member whose role changes (the target).
"admin" | "member"
required
string
required
The caller (must be a group admin).
Returns — Promise<ConversationMember>

checkMyConversationMembership

Reads the acting user’s own membership in a conversation (GET /chat/conversations/:conversationId/members/me).
string
required
string
required
The user whose membership is checked: the request acts as them.
Returns — 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 }
A user who can’t read the conversation gets the same error as reading it (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).
string
required
string
required
The user leaving.
Returns — 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 as before to page backwards, or as after to page forwards (before/after are mutually exclusive).
string
required
string
required
The acting user (must be a member).
string
List this message’s thread replies (thread view), oldest first by default.
string
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.
string
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.
number
1–100, defaults to 50.
"asc" | "desc"
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.
ChatMessageListIncludeParam
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.
MessageFilters
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.
Returns — 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. When images or files are attached the request is sent as multipart/form-data; otherwise it’s a JSON body.
string
required
string
required
The message author (must be a member).
string
Up to 4000 characters.
GifData | null
An attached GIF object.
Mention[]
User/space mentions.
string
Reply within a thread.
string
Quote another message.
object
Custom key-value data.
string
Client-generated id echoed back on the created message (not stored).
{ 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.
Returns — Promise<SendMessageResponse>: the created message as a SentChatMessage (a ChatMessage without reactionCounts, userReactions and grants), with localId when you passed one.

getMessage

string
required
string
required
string
required
The acting user (must be a member).
ChatMessageIncludeParam
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.
Returns — Promise<ChatMessage>

editMessage

Edits a message. Requires the acting user to be the message author.
string
required
string
required
string
required
The acting user (must be the message author).
string
GifData | null
A GifData attachment, or null to clear it.
Mention[]
object | null
Returns — 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.
string
required
string
required
string
required
The acting user (author or group admin).
Returns — 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 with 404 chat/message-not-found, while taking back the acting user’s own still works.
string
required
string
required
string
required
string
required
The reacting user (must be a member).
Returns — 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.
string
required
string
required
string
required
The emoji to list reactors for.
string
required
The acting user (must be a member).
number
Defaults to 1.
number
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.
Returns — 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.
string
required
string
required
The message up to which the conversation is marked read.
string
required
The acting user (must be a member).
Returns — Promise<void>

muteConversation

Sets or clears a user’s mute on a conversation. Muting suppresses the message 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.
string
required
"8h" | "24h" | "1w" | "forever" | null
required
The mute duration choice, or null to clear the mute. Send the choice, never a raw timestamp.
string
required
The user whose mute is set (must be a member).
Returns — 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 on client.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.
string
required
string
required
The acting user (must be an active member of the space).
Returns — 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.
string
required
string
required
"remove"
required
The moderation action. Chat messages are never held for approval, so "remove" is the only value.
string
The reason for the removal. Trimmed; up to 1,000 characters.
string
required
The moderator the request acts as: they must be a moderator or admin of the space, and the action is recorded as theirs.
Returns — 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 with spaces.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.