Skip to main content
The WebSocket command (Command Type: 1) establishes a long-running WebSocket connection with event-driven command hooks. Supports native, SignalR, and Socket.IO protocols.

Command Type

Command Type ID: 1

Parameters

Stop On

These connection stop conditions are handled automatically by the platform. They are not blueprint parameters — you cannot configure them in params, 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: each onMessage 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 your onMessage 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:
an onMessage chain that parses and shapes it publishes:
Notes:
  • Only the data field is meaningful to downstream consumers; shape it with Parse / transform commands to your provider-event format.
  • If data is undefined (nothing was produced for a frame), nothing is published for that frame.
  • On a heartbeat tick the current accumulated data is re-published unchanged, so consumers see a steady cadence even with no new frame.

Error Handling and Reconnection

Use onError 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 through headers (placeholders such as ${secrets.feedToken} resolve at runtime):
Some feeds instead expect the token in the URL query string or in a subscribe message sent from onConnect (via WebSocket Send) — check the provider’s docs for which the feed uses.

Native WebSocket with onMessage Hook

SignalR Connection

SignalR delivers each hub message as an envelope of the form { "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. Every heartbeatIntervalMs the current merged event is re-published, so downstream consumers receive a steady cadence even when no new frame has arrived.