Subscriptions

Live data subscriptions via realtime.subscribe

Import a query function from @start-chat/sdk/queries and pass it to realtime.subscribe. Your callback fires immediately with current data, then again whenever the data changes.

import { setup, realtime } from '@start-chat/sdk'
import { channelMessages } from '@start-chat/sdk/queries'
await setup({ apiKey: 'sk_live_your_api_key' })
const sub = realtime.subscribe(
channelMessages,
{ serverId: 'srv_...', channelId: 'ch_...' },
(messages) => {
console.info('Messages:', messages.length)
},
)
// read current data without waiting for callback
console.info(sub.data)
// stop listening
sub.unsubscribe()

realtime.subscribe returns a Subscription object:

PropertyDescription
.dataCurrent data snapshot (updates on each callback)
.unsubscribe()Stop listening for updates

serverById

Get server details by ID.

ParameterTypeRequiredDescription
serverIdstringYes
import { serverById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(serverById, { serverId: 'srv_...' }, (data) => {
console.info('serverById updated:', data)
})

serverMembers

List members of a server.

ParameterTypeRequiredDescription
serverIdstringYes
limitnumberNo
searchstringNo
cursorValuenumberNo
cursorDir'forward' | 'backward'Noforward, backward
import { serverMembers } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(serverMembers, { serverId: 'srv_...' }, (data) => {
console.info('serverMembers updated:', data)
})

userServers

List servers the authenticated user belongs to.

ParameterTypeRequiredDescription
userIdstringNo
import { userServers } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(userServers, {}, (data) => {
console.info('userServers updated:', data)
})

searchJoinableServers

Search for public servers the user can join.

ParameterTypeRequiredDescription
userIdstringNo
searchstringNo
limitnumberNo
import { searchJoinableServers } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(searchJoinableServers, {}, (data) => {
console.info('searchJoinableServers updated:', data)
})

channelsByServer

List all channels in a server.

ParameterTypeRequiredDescription
serverIdstringYes
import { channelsByServer } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(channelsByServer, { serverId: 'srv_...' }, (data) => {
console.info('channelsByServer updated:', data)
})

channelById

Get channel details by ID.

ParameterTypeRequiredDescription
channelIdstringYes
import { channelById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(channelById, { channelId: 'ch_...' }, (data) => {
console.info('channelById updated:', data)
})

channelMessages

Fetch messages in a channel. Supports cursor-based pagination, filtering, and limit control.

ParameterTypeRequiredDescription
serverIdstringYes
channelIdstringYes
fromOrderstringNo
around'before' | 'after'Nobefore, after
limitnumberNo
solobooleanNo
channelFilter'thread' | 'chat' | 'app' | 'pinned'Nothread, chat, app, pinned
appendingFromOrderstringNo
import { channelMessages } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(
channelMessages,
{ serverId: 'srv_...', channelId: 'ch_...' },
(data) => {
console.info('channelMessages updated:', data)
},
)

messageById

Get a single message by ID.

ParameterTypeRequiredDescription
messageIdstringYes
import { messageById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(messageById, { messageId: 'msg_...' }, (data) => {
console.info('messageById updated:', data)
})

threadWithMessages

Get a thread and all its messages.

ParameterTypeRequiredDescription
threadIdstringYes
serverIdstringYes
import { threadWithMessages } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(
threadWithMessages,
{ threadId: 'thr_...', serverId: 'srv_...' },
(data) => {
console.info('threadWithMessages updated:', data)
},
)

threadById

Get thread metadata by ID.

ParameterTypeRequiredDescription
threadIdstringYes
import { threadById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(threadById, { threadId: 'thr_...' }, (data) => {
console.info('threadById updated:', data)
})

userById

Get user profile by ID.

ParameterTypeRequiredDescription
userIdstringYes
import { userById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(userById, { userId: 'usr_...' }, (data) => {
console.info('userById updated:', data)
})