Zebflow Docs
ws.message.send
Zebflow Docs

ws.message.send

Sends --body over a WebSocket

ws.message.send [--room TEXT] [--connection TEXT] --body JSON [--event TEXT] [--recipient TEXT] → message

Sends --body over a WebSocket. --room reaches the sockets joined to a room of this project as an event message named --event (default event); without --room the room is the one of the trigger.room that started the run. An exact room that is not open is FW_NODE_WS_ROOM_NOT_OPEN; a pattern (zone-*) reaches every open room it matches and answers how many. --recipient all (default), session (the triggering socket only), others (every socket but that one), user:<sub> (every session of that identity) or tag:<tag> (every session holding that tag, from ws.session.tag — a team's chat). --connection instead sends on the socket a trigger.socket node holds open (its node id, or pipeline/path:node_id); it takes no --event or --recipient. Give one of --room and --connection, not both. Adds message: { sent, room, event } (a pattern: { sent, rooms, event }; a socket: { sent, connection }) and keeps the rest of the payload. Does not change room state — that is ws.state.*.

Flags

  • --room: The room to send to — an exact name, or a pattern reaching every open room it matches; default: the room of the trigger.room that started the run.
  • --connection: The trigger.socket node whose open socket to send on: its id, or pipeline/path:node_id.
  • --body (required): What to send — a literal or {{ expr }}.
  • --event: The event name clients receive (rooms only). Default: event.
  • --recipient: Rooms only: all (default), session (the triggering socket), others (every socket but that one), user:<sub> (every session of that identity) or tag:<tag> (every session holding that tag).

Examples

Broadcast a chat line to the room

| ws.message.send --event chat.message --body "{{ { from: input.room.session_id, text: input.room.payload.text } }}"

After trigger.room, the room is the one the event came from.

It answers:

json
{  "message": {    "sent": true,    "room": "lobby",    "event": "chat.message"  }}

Push from a schedule to a fixed room

| ws.message.send --room dashboard --event stats.tick --body "{{ { online: input.online } }}"

Announce to every open zone

| ws.message.send --room "zone-*" --event server.notice --body "{{ { text: 'restart in 5 minutes' } }}"

It answers:

json
{  "message": {    "sent": true,    "rooms": 3,    "event": "server.notice"  }}

Notify one user on every device

| ws.message.send --room notifications --recipient "user:{{ input.order.owner }}" --event order.shipped --body "{{ input.order }}"

notifications is a fixed room (trigger.room --room notifications); every signed-in session of that identity receives it.

Tell one team

| ws.message.send --recipient tag:team:red --event team.chat --body "{{ { from: input.room.session_id, text: input.room.payload.text } }}"

Only the sessions ws.session.tag --tag team:red tagged receive it.

Subscribe after connecting

| ws.message.send --connection n0 --body "{{ { op: 'subscribe', symbols: ['AUDUSD'] } }}"

n0 is the trigger.socket node that holds the socket open.

It answers:

json
{  "message": {    "sent": true,    "connection": "n0"  }}