Command Type
Command Type ID: 1Parameters
Stop On
These connection stop conditions are handled automatically by the platform. They are not blueprint parameters — you cannot configure them inparams, and there is no stopOn object in saved blueprints.
Use
onClose or onError hooks to react when a connection ends. An explicit WebSocket Close command in a hook also closes the connection.
WebSocketOnInterval
WebSocketSignalRSettings
WebSocketSocketIOSettings
Hook Firing Semantics
Each hook fires at a specific point in the connection lifecycle:
On startup the command connects, runs
onConnect a single time, and only then begins processing incoming frames. Frames that arrive while onConnect is still running are buffered and processed in order once it completes, so subscription setup always happens before the first message is handled.
Heartbeat Re-publishing
heartbeatIntervalMs controls how often the command re-publishes the current accumulated result, independent of whether new frames have arrived (defaults to 3000 ms). On each tick, if a result has been produced, the latest accumulated result is published again. This is what lets the last (streaming) step emit on a steady cadence even during quiet periods with no new messages. onInterval is separate: it runs your own commands (for example a keep-alive send) on its own intervalMs, while the heartbeat only re-publishes the current result.
Frame Model: Snapshots and Deltas
Many live feeds send an initial snapshot of the full state followed by a stream of incremental deltas that carry only what changed. WebSocket accumulates state across frames for the life of the connection: eachonMessage run can read and update values carried in the step’s state and local variables, so your hook commands can merge the snapshot and subsequent deltas into one complete event before publishing. Because state persists across frames, the streaming step can always publish the current, fully merged event, including on a heartbeat tick when no new delta has arrived.
Published Output Shape
After youronMessage commands run, the step publishes a result whose data field holds whatever your transform produced — typically the parsed (and, for streaming steps, fully merged) event. For example, given an incoming frame:
onMessage chain that parses and shapes it publishes:
- Only the
datafield is meaningful to downstream consumers; shape it with Parse / transform commands to your provider-event format. - If
dataisundefined(nothing was produced for a frame), nothing is published for that frame. - On a heartbeat tick the current accumulated
datais re-published unchanged, so consumers see a steady cadence even with no new frame.
Error Handling and Reconnection
UseonError to react to a socket error — for example to publish a status/marker or run cleanup commands. When an error occurs, the command runs onError and then the connection is torn down; the hook is not a place to reconnect.
Reconnection is handled automatically at the job level: a dropped connection ends the job and the item is rescheduled/retried, which re-establishes the connection. You do not (and should not) implement reconnect/retry loops inside onError.
Usage Examples
Authenticated Handshake (Bearer token / API key)
Most live feeds require credentials at the handshake. Pass them throughheaders (placeholders such as ${secrets.feedToken} resolve at runtime):
onConnect (via WebSocket Send) — check the provider’s docs for which the feed uses.
Native WebSocket with onMessage Hook
SignalR Connection
{ "type", "target", "arguments" }, where arguments is the array of values the hub method was invoked with. Parse the payload from $.arguments[0] (or the relevant index), not a top-level data field.
Socket.IO Connection
With Heartbeat Interval
Worked Example: Sports, Events, Event Data
A typical live feed is collected in three steps that walk from a broad list down to per-event streams. The first two are discovery steps that open the socket, capture a one-time snapshot, and close. The final streaming step keeps the socket open and publishes on each heartbeat.Step 1: Sports (discovery)
Opens the socket, subscribes to the sports list, parses the snapshot, then closes with the WebSocket Close command (Type 9). The list of sports is published once, and each sport becomes an item for the next step.Step 2: Events (discovery)
Runs once per sport. It subscribes to that sport’s events, grabs the events snapshot, then closes. The events are published once and fan out into items for the final step.Step 3: Event Data (streaming, last step)
Runs once per event and keeps the socket open. The first frame is a full snapshot; later frames are deltas merged into the accumulated event state. EveryheartbeatIntervalMs the current merged event is re-published, so downstream consumers receive a steady cadence even when no new frame has arrived.
Related Commands
- WebSocket Send - Send within onConnect/onMessage hooks
- Decode - Decode compressed payloads (parse command, usable in WS hooks)
- WebSocket Close - Terminate the connection