Websocket icon

Websocket

Interact with ws stream

Actions2

Overview

This node enables interaction with WebSocket streams within an n8n workflow. Specifically, it allows sending messages over an existing WebSocket connection or closing a WebSocket connection. It is useful in scenarios where real-time communication is needed, such as pushing updates to a live dashboard, sending commands to a WebSocket server, or gracefully terminating WebSocket connections.

For example, after receiving a WebSocket connection from a trigger node, this node can send JSON-formatted messages through that connection to notify clients or other services. Alternatively, it can close the connection when no longer needed.

Properties

Name Meaning
Websocket Resource Field (Parameter Name) The name of the field in the incoming data that holds the WebSocket resource object. This must match the output field name from the WebSocket trigger node.
Message The JSON message content to send over the WebSocket connection.

Output

The node outputs an array of JSON objects, each representing the result of the operation for each input item. Each output JSON contains:

  • success: A boolean indicating if the operation was successful (true).
  • A property named after the WebSocket resource field (e.g., "ws"), containing the WebSocket resource object used for sending or closing.

No binary data is output by this node.

Dependencies

  • Requires an active WebSocket resource object passed into the node via the specified WebSocket resource field.
  • Depends on a prior node (such as a WebSocket trigger) that provides the WebSocket connection object.
  • No external API keys or credentials are required by this node itself, but the WebSocket connection may require authentication handled elsewhere.

Troubleshooting

  • Error: "Execution error: No websocket resource received"
    This occurs if the specified WebSocket resource field is missing in the input data. Ensure that the field name matches exactly the one provided by the WebSocket trigger node and that the trigger node successfully established a WebSocket connection.

  • Message not sent or connection not closed
    Verify that the WebSocket resource object is valid and connected. If the connection has been closed or lost before this node runs, sending or closing operations will fail silently or throw errors.

  • Handling failures
    If the node is set to continue on failure, errors will be returned as part of the output JSON with an error property describing the issue.

Links and References

Discussion