ReferenceAsk
A

events.publish

Publishes a payload to one or many named channels; connected subscribers receive it instantly.
events.publish(channels, data) Promise<{ delivered: number }>

Sends a payload to one or many channels from anywhere on the backend: a method, a cron, or a webhook handler. One call fans out to up to 500 channels, so publishing to every member of a room is a single request. It returns the count of live subscriber connections across those channels, and a count of zero means nobody is listening right now. Keep payloads small: the cap is 32k serialized characters, so the pattern is to publish an id and let the client fetch the full record.

Parameters
channels
string | string[]
RequiredOne channel name, or up to 500 in one call to fan out to a whole audience. Exact names only (letters, digits, and : _ - .), no wildcards.
data
unknown
RequiredThe payload subscribers receive. Capped at 32k serialized characters, so publish an id and let the client fetch, not a document.
Publish to one user's channel
import { events } from '@mindstudio-ai/agent';

export async function assignTicket(input: { ticketId: string; assignee: string }) {
  const ticket = await Tickets.update(input.ticketId, { assignee: input.assignee });
  await events.publish(`user:${input.assignee}`, { type: 'ticket', id: ticket.id });
  return ticket;
}