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. Most functions take that user asuserId; the few where userId already names a target take the actor as actingUserId instead (createDirectConversation, addMember, removeMember, changeMemberRole).
Naming a user other than the caller’s own is gated to service keys. With
a service key, omitting the acting user returns
400 chat/missing-user-id.Conversations
listConversations
Lists the acting user’s conversations, newest activity first. Uses cursor (keyset) pagination — pass the last item’slastMessageAt as cursor and its createdAt as cursorCreatedAt to get the next page.
Promise<{ conversations: ConversationPreview[]; hasMore: boolean }>
Each ConversationPreview includes 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.
createDirectConversation
Creates (or returns the existing) one-to-one conversation between the acting user and a target user.Promise<Conversation>
createGroupConversation
Creates a group conversation; the acting user becomes its admin.Promise<Conversation>
getConversation
Fetches a single conversation the acting user is a member of.Promise<Conversation>
updateConversation
Updates a group conversation. Requires the acting user to be a group admin.File id for the avatar, or
null to clear it. It must be a file the acting user uploaded, or an app-owned file uploaded without a userId, that isn’t attached to anything else (400 chat/invalid-avatar-file otherwise).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
Promise<PaginatedResponse<ConversationMember>>
addMember
Adds a member to a group. Requires the acting caller to be a group admin.Promise<ConversationMember>
removeMember
Removes a member from a group. Requires the acting caller to be a group admin.Promise<void>
changeMemberRole
Promotes or demotes a member. Requires the acting caller to be a group admin.Promise<ConversationMember>
leaveConversation
Promise<void>
Messages
listMessages
Lists messages in a conversation. Uses cursor pagination — passbefore (an ISO timestamp) to page backwards, or after to page forwards (before/after are mutually exclusive).
Comma-separated associations to populate:
"files" (message attachments) and "grants" (each message’s reputation-grant summary). Combine them as "files,grants".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 parentId always returns an empty list — the response’s notice field explains why.Promise<{ messages: ChatMessage[]; hasMore: boolean; oldestCreatedAt: string | null; newestCreatedAt: string | null }>
sendMessage
Sends a message as the acting user. A message must have content, a GIF, or at least one file. Whenfiles are attached the request is sent as multipart/form-data; otherwise it’s a JSON body.
Attachments:
{ file: Uint8Array | Blob; filename?: string; mimeType?: string }[], up to 10, each up to 50 MB (a larger file is refused). They count toward the project’s file storage: on the free plan, or when the project’s usage limit behavior is set to strict, a message whose files would go over the storage limit is refused with 429 project/quota-reached.Promise<ChatMessage>
getMessage
Comma-separated associations to populate. Only
"grants" is supported here — it attaches the message’s reputation-grant summary at message.grants.Promise<ChatMessage>
editMessage
Edits a message. Requires the acting user to be the message author.A GifData attachment, or
null to clear it.Promise<ChatMessage>
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.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.Promise<{ data: MessageReaction[]; pagination: { page; limit; total; hasMore } }>
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 userId (the service key acts on that user’s behalf). 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 omit userId.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 a member of the space who is not banned, there or in a parent space; a request still awaiting approval or one that was declined is enough.Promise<Conversation>
spaces.moderateSpaceChatMessage
Removes a message in a space conversation.On the two space-chat moderation routes,
actingUserId is optional. Omit it
and your service key acts as the project, passing the space-moderator check.
Name a user and the request has exactly that user’s moderation permissions:
it is refused if they cannot moderate the space.The moderator the key acts for. The request then has exactly that moderator’s permissions. Omit it to act as the project.
Promise<{ message: string; moderationStatus: string }>
spaces.handleSpaceChatReport
Resolves a report against a space-conversation message: remove the message, ban the user, and/or dismiss.dismiss cannot be combined with the other actions.Optional. The server bans the author of the reported message; if sent, this must be that author.
The moderator the key acts for. The request then has exactly that moderator’s permissions. Omit it to act as the project.
Promise<{ message: string; code: string }>
